home *** CD-ROM | disk | FTP | other *** search
- /*
-
- This file contains several commands and functions to facilitate the
- construction and use of textual buttons in a flat E file. These functions
- capitalize on the availability of attribute support to associate commands
- with regions of text.
-
- commands
-
- nice_box
- draws a box inside the region specified by the current block mark.
-
- associate_phrase_with_mark
- associates a phrase with the marked region.
-
- associated_phrase()
- returns the phrase (of a certain class) associated with the current
- cursor position with the text of the document.
-
- show_associated_phrase
- calls associated_phrase() and displays the value returned.
-
- execute_cursor
- attempts to execute the button phrase associated with the current
- cursor position.
- */
-
-
-
- defc nice_box
- if marktype()<>"BLOCK" then
- sayerror "A block mark must exist!!!"
- return
- endif
- getmark FLine, LLine, FCol, LCol, MFileid
- if FLine==LLine then
- sayerror "The block mark is too short."
- return
- endif
- if FCol==LCol then
- sayerror "The block mark is too narrow."
- endif
- getfileid OldFileid
- call psave_pos(OldPosition)
- activatefile MFileid
- /* save command state */
- compile if EVERSION < 5
- OldCommandState = commandstate()
- if OldCommandState then
- commandtoggle
- endif
- compile endif
- /* save insert/replace state */
- OldInsertState = insertstate()
- /* set replace mode */
- if OldInsertState then
- inserttoggle
- endif
- FLine; .col=FCol; keyin '┌'
- .col=LCol; keyin '┐'
- LLine; .col=LCol; keyin '┘'
- .col=FCol; keyin '└'
- if FCol+1<LCol then
- ;; unmark -- pset_mark does an unmark
- call pset_mark(FLine, FLine, FCol+1, LCol-1, 'BLOCK', MFileid)
- FillMark '─'
- LLine; .col=FCol+1
- overlayblock
- endif
- if FLine+1<LLine then
- ;; unmark -- pset_mark does an unmark
- call pset_mark(FLine+1, LLine-1, FCol, FCol, 'BLOCK', MFileid)
- FillMark '│'
- FLine+1; .col=LCol
- overlayblock
- endif
- if OldInsertState<>insertstate() then
- inserttoggle
- endif
- compile if EVERSION < 5
- if OldCommandState<>commandstate() then
- commandtoggle
- endif
- compile endif
- call pset_mark(FLine, LLine, FCol, LCol, 'BLOCK', MFileid)
- activatefile OldFileid
- call prestore_pos(OldPosition)
-
-
- ---------------------------------------------------------------------------
- defc associate_Phrase_With_Mark
- universal ASSOCCLASS
- themarktype = marktype()
- if not themarktype then --there is no mark
- call messageNwait("Error, a mark must exist before it can be colored.")
- return
- else
- getfileid thisfileid
- getmark firstmline, lastmline,firstmcol,lastmcol,mkfileid
- parse arg TheClass ThePhrase
- TheTag = StashPhrase(ThePhrase)
- if themarktype=="CHAR" then
- call find_insertion_points_for_region(firstmline, firstmcol, lastmline, lastmcol, mkfileid,
- foffset, loffset)
- -- assert: foffset is negative, loffset is positive
- insert_attribute TheClass, TheTag, 1/*push*/, foffset, firstmcol, firstmline, mkfileid
- insert_attribute ASSOCCLASS, TheTag, 2/*tag*/, foffset, firstmcol, firstmline, mkfileid
- insert_attribute TheClass, TheTag, 0/*pop*/, loffset, lastmcol, lastmline, mkfileid
- elseif themarktype=="BLOCK" then
- for i = firstmline to lastmline
- call find_insertion_points_for_region(i, firstmcol, i, lastmcol, mkfileid,
- foffset, loffset)
- -- assert: foffset is negative, loffset is positive
- insert_attribute TheClass, TheTag, 1/*push*/, foffset, firstmcol, i, mkfileid
- insert_attribute ASSOCCLASS, TheTag, 2/*tag*/, foffset, firstmcol, i, mkfileid
- insert_attribute TheClass, TheTag, 0/*pop*/, loffset, lastmcol, i, mkfileid
- endfor
- elseif themarktype=="LINE" then
- call find_insertion_points_for_region(i, 1, i+1, 0, mkfileid,
- foffset, loffset)
- -- assert: foffset is negative, loffset is positive
- insert_attribute TheClass, TheTag, 1/*push*/, foffset, 1, i, mkfileid
- insert_attribute ASSOCCLASS, TheTag, 2/*tag*/, foffset, 1, i, mkfileid
- insert_attribute TheClass, TheTag, 0/*pop*/, loffset, 0, i+1, mkfileid
- else
- sayerror "Internal Error: weird mark type." themarktype
- endif
- endif
-
- ------------------------------------------------------------------------------
- defproc Associated_Phrase(ArgClass)
- universal FIND_PREV_ATTR_SUBOP
- universal ASSOCCLASS
- call psave_pos(OldPos)
- compile if EVERSION < 5
- cursordata
- compile endif
- TheClass = ArgClass
- TheOffset = 0
- TheColm = .col
- TheLine = .line
- Level = 1
- while Level>0 do
- attribute_action FIND_PREV_ATTR_SUBOP, TheClass, TheOffset, TheColm, TheLine
- if TheClass==0 then
- call showmessage('assoc/button region not found')
- return ''
- endif
- query_attribute TheClass, TheTagNum, IsPush, TheOffset, TheColm, TheLine
- if IsPush==1 then
- Level = Level - 1
- else
- Level = Level + 1
- endif
- endwhile
- --TheOffset = signit(TheOffset)
- if TheOffset=-1 then
- -- this is because we expect a tag to the right. If the offset is
- -- -1, then there is not even an attribute to the right.
- call showmessage('The assocregion/button has been corrupted.(1)')
- return ''
- endif
- TheOffset = TheOffset+1
- query_attribute TheClass, TheTagNum, IsPush, TheOffset, TheColm, TheLine
- if TheClass<>ASSOCCLASS then
- call showmessage('The assocregion/button has been corrupted.(2)')
- return ''
- endif
- call GetPhraseTagged(TheTagNum, ThePhrase)
- return ThePhrase
-
-
- -----------------------------------------------------------------------------
- defc Show_Associated_phrase
- universal BUTTONCLASS;
- ThePhrase = Associated_phrase(BUTTONCLASS)
- call showmessage(" The associated phrase/command was... ",
- " '"ThePhrase"'")
-
-
- -----------------------------------------------------------------------------
- defc MH_executeclick
- -- this procedure executes the command associated with the location clicked
- .line - .cursory + .mousey -- Set .line
- .col = .col - .cursorx + .mousex
- "Execute_cursor"
-
- -----------------------------------------------------------------------------
- defc Execute_cursor
- universal BUTTONCLASS;
- ThePhrase = Associated_phrase(BUTTONCLASS)
- if ThePhrase=='' then
- call showmessage(" No associated text was found.")
- return
- endif
- ThePhrase
-
- -----------------------------------------------------------------------------
- definit
- universal ATTR_initialized
- universal HIDEIT_initialized
- if ATTR_initialized=='' then
- "link Attr"
- endif
- if HIDEIT_initialized=='' then
- "link hideit"
- endif
-