home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / EPMATR.ZIP / BUTTONS.E < prev    next >
Text File  |  1989-07-06  |  7KB  |  209 lines

  1. /*
  2.  
  3.   This file contains several commands and functions to facilitate the
  4. construction and use of textual buttons in a flat E file. These functions
  5. capitalize on the availability of attribute support to associate commands
  6. with regions of text.
  7.  
  8. commands
  9.  
  10.   nice_box
  11.       draws a box inside the region specified by the current block mark.
  12.  
  13.   associate_phrase_with_mark
  14.       associates a phrase with the marked region.
  15.  
  16.   associated_phrase()
  17.       returns the phrase (of a certain class) associated with the current
  18.       cursor position with the text of the document.
  19.  
  20.   show_associated_phrase
  21.       calls associated_phrase() and displays the value returned.
  22.  
  23.   execute_cursor
  24.       attempts to execute the button phrase associated with the current
  25.       cursor position.
  26. */
  27.  
  28.  
  29.  
  30. defc nice_box
  31.    if marktype()<>"BLOCK" then
  32.      sayerror "A block mark must exist!!!"
  33.      return
  34.    endif
  35.    getmark FLine, LLine, FCol, LCol, MFileid
  36.    if FLine==LLine then
  37.       sayerror "The block mark is too short."
  38.       return
  39.    endif
  40.    if FCol==LCol then
  41.       sayerror "The block mark is too narrow."
  42.    endif
  43.    getfileid OldFileid
  44.    call psave_pos(OldPosition)
  45.    activatefile MFileid
  46.    /* save command state */
  47.    compile if EVERSION < 5
  48.       OldCommandState = commandstate()
  49.       if OldCommandState then
  50.          commandtoggle
  51.       endif
  52.    compile endif
  53.    /* save insert/replace state */
  54.    OldInsertState = insertstate()
  55.    /* set replace mode */
  56.    if OldInsertState then
  57.      inserttoggle
  58.    endif
  59.    FLine; .col=FCol; keyin '┌'
  60.           .col=LCol; keyin '┐'
  61.    LLine; .col=LCol; keyin '┘'
  62.           .col=FCol; keyin '└'
  63.    if FCol+1<LCol then
  64. ;;   unmark       -- pset_mark does an unmark
  65.      call pset_mark(FLine, FLine, FCol+1, LCol-1, 'BLOCK', MFileid)
  66.      FillMark '─'
  67.      LLine; .col=FCol+1
  68.      overlayblock
  69.    endif
  70.    if FLine+1<LLine then
  71. ;;   unmark       -- pset_mark does an unmark
  72.      call pset_mark(FLine+1, LLine-1, FCol, FCol, 'BLOCK', MFileid)
  73.      FillMark '│'
  74.      FLine+1; .col=LCol
  75.      overlayblock
  76.    endif
  77.    if OldInsertState<>insertstate() then
  78.      inserttoggle
  79.    endif
  80.    compile if EVERSION < 5
  81.       if OldCommandState<>commandstate() then
  82.          commandtoggle
  83.       endif
  84.    compile endif
  85.    call pset_mark(FLine, LLine, FCol, LCol, 'BLOCK', MFileid)
  86.    activatefile OldFileid
  87.    call prestore_pos(OldPosition)
  88.  
  89.  
  90. ---------------------------------------------------------------------------
  91. defc associate_Phrase_With_Mark
  92.    universal ASSOCCLASS
  93.    themarktype = marktype()
  94.    if not themarktype then  --there is no mark
  95.       call messageNwait("Error, a mark must exist before it can be colored.")
  96.       return
  97.    else
  98.       getfileid thisfileid
  99.       getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
  100.       parse arg TheClass ThePhrase
  101.       TheTag = StashPhrase(ThePhrase)
  102.       if themarktype=="CHAR" then
  103.          call find_insertion_points_for_region(firstmline, firstmcol, lastmline, lastmcol, mkfileid,
  104.                                                foffset, loffset)
  105.          -- assert: foffset is negative, loffset is positive
  106.          insert_attribute TheClass, TheTag,   1/*push*/, foffset, firstmcol, firstmline, mkfileid
  107.          insert_attribute ASSOCCLASS, TheTag, 2/*tag*/,  foffset, firstmcol, firstmline, mkfileid
  108.          insert_attribute TheClass, TheTag,   0/*pop*/,  loffset, lastmcol,  lastmline,  mkfileid
  109.       elseif themarktype=="BLOCK" then
  110.          for i = firstmline to lastmline
  111.             call find_insertion_points_for_region(i, firstmcol, i, lastmcol, mkfileid,
  112.                                                   foffset, loffset)
  113.             -- assert: foffset is negative, loffset is positive
  114.             insert_attribute TheClass,   TheTag, 1/*push*/, foffset, firstmcol, i, mkfileid
  115.             insert_attribute ASSOCCLASS, TheTag, 2/*tag*/,  foffset, firstmcol, i, mkfileid
  116.             insert_attribute TheClass,   TheTag, 0/*pop*/,  loffset, lastmcol,  i,  mkfileid
  117.          endfor
  118.       elseif themarktype=="LINE" then
  119.           call find_insertion_points_for_region(i, 1, i+1, 0, mkfileid,
  120.                                                 foffset, loffset)
  121.           -- assert: foffset is negative, loffset is positive
  122.           insert_attribute TheClass,   TheTag, 1/*push*/, foffset, 1, i,   mkfileid
  123.           insert_attribute ASSOCCLASS, TheTag, 2/*tag*/,  foffset, 1, i,   mkfileid
  124.           insert_attribute TheClass,   TheTag, 0/*pop*/,  loffset, 0, i+1, mkfileid
  125.       else
  126.           sayerror "Internal Error: weird mark type." themarktype
  127.       endif
  128.    endif
  129.  
  130. ------------------------------------------------------------------------------
  131. defproc Associated_Phrase(ArgClass)
  132.    universal FIND_PREV_ATTR_SUBOP
  133.    universal ASSOCCLASS
  134.    call psave_pos(OldPos)
  135.  compile if EVERSION < 5
  136.    cursordata
  137.  compile endif
  138.    TheClass  = ArgClass
  139.    TheOffset = 0
  140.    TheColm   = .col
  141.    TheLine   = .line
  142.    Level = 1
  143.    while Level>0 do
  144.       attribute_action FIND_PREV_ATTR_SUBOP, TheClass, TheOffset, TheColm, TheLine
  145.       if TheClass==0 then
  146.          call showmessage('assoc/button region not found')
  147.          return ''
  148.       endif
  149.       query_attribute  TheClass, TheTagNum, IsPush, TheOffset, TheColm, TheLine
  150.       if IsPush==1 then
  151.         Level = Level - 1
  152.       else
  153.         Level = Level + 1
  154.       endif
  155.    endwhile
  156.    --TheOffset = signit(TheOffset)
  157.    if TheOffset=-1 then
  158.       -- this is because we expect a tag to the right. If the offset is
  159.       --   -1, then there is not even an attribute to the right.
  160.       call showmessage('The assocregion/button has been corrupted.(1)')
  161.       return ''
  162.    endif
  163.    TheOffset = TheOffset+1
  164.    query_attribute TheClass, TheTagNum, IsPush, TheOffset, TheColm, TheLine
  165.    if TheClass<>ASSOCCLASS then
  166.       call showmessage('The assocregion/button has been corrupted.(2)')
  167.       return ''
  168.    endif
  169.    call GetPhraseTagged(TheTagNum, ThePhrase)
  170.    return ThePhrase
  171.  
  172.  
  173. -----------------------------------------------------------------------------
  174. defc Show_Associated_phrase
  175.   universal BUTTONCLASS;
  176.   ThePhrase = Associated_phrase(BUTTONCLASS)
  177.   call showmessage(" The associated phrase/command was...     ",
  178.                    "  '"ThePhrase"'")
  179.  
  180.  
  181. -----------------------------------------------------------------------------
  182. defc MH_executeclick
  183.    -- this procedure executes the command associated with the location clicked
  184.    .line - .cursory + .mousey       -- Set .line
  185.    .col  = .col  - .cursorx + .mousex
  186.    "Execute_cursor"
  187.  
  188. -----------------------------------------------------------------------------
  189. defc Execute_cursor
  190.   universal BUTTONCLASS;
  191.   ThePhrase = Associated_phrase(BUTTONCLASS)
  192.   if ThePhrase=='' then
  193.     call showmessage(" No associated text was found.")
  194.     return
  195.   endif
  196.   ThePhrase
  197.  
  198. -----------------------------------------------------------------------------
  199. definit
  200.   universal ATTR_initialized
  201.   universal HIDEIT_initialized
  202.   if ATTR_initialized=='' then
  203.      "link Attr"
  204.   endif
  205.   if HIDEIT_initialized=='' then
  206.      "link hideit"
  207.   endif
  208.  
  209.