home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac2.zip / FONTS.E < prev    next >
Text File  |  1995-09-18  |  6KB  |  145 lines

  1.  
  2. include 'stdconst.e'
  3. include 'english.e'
  4.  
  5. const
  6.    ADD_FONT_ATTRIB_TITLE = 'Add font attribute'
  7.    ATTRIBS_PROMPT = 'Pull-down menu for adding font attributes to marked text.'
  8.    BOLD_PROMPT = 'Add the Bold attribute to marked text.'
  9.    ITALIC_PROMPT = 'Add the Italic attribute to marked text.'
  10.    UNDERLINE_PROMPT = 'Add the Underline attribute to marked text.'
  11.    OUTLINE_PROMPT = 'Add the Outline attribute to marked text.'
  12.    STRIKEOUT_PROMPT = 'Add the Strikeout attribute to marked text.'
  13.    BLOCKMARK_ONE_LINE__MSG =   'Block marks must begin and end on the same line.'
  14.    ATTRIBUTE_ON__MSG = 'Attribute is already on.'
  15.  
  16.    COLOR_CLASS = 1
  17.    BOOKMARK_CLASS = 13
  18.    STYLE_CLASS =  14
  19.    FONT_CLASS =  16
  20.  
  21.    Italic_ATTRIB     = 1
  22.    Underscore_ATTRIB = 2
  23.    Outline_ATTRIB    = 8
  24.    Strikeout_ATTRIB  = 16
  25.    Bold_ATTRIB       = 32
  26.  
  27.  
  28. defc fonts_actionlist
  29.    universal ActionsList_FileID  -- This is the fileid that gets the line(s)
  30.    insertline '|fonts_bold|'BOLD_PROMPT'|fonts|', ActionsList_FileID.last+1, ActionsList_FileID
  31.    insertline '|fonts_italic|'ITALIC_PROMPT'|fonts|', ActionsList_FileID.last+1, ActionsList_FileID
  32.    insertline '|fonts_underline|'UNDERLINE_PROMPT'|fonts|', ActionsList_FileID.last+1, ActionsList_FileID
  33.    insertline '|fonts_outline|'OUTLINE_PROMPT'|fonts|', ActionsList_FileID.last+1, ActionsList_FileID
  34.    insertline '|fonts_strikeout|'STRIKEOUT_PROMPT'|fonts|', ActionsList_FileID.last+1, ActionsList_FileID
  35.  
  36. defc fonts_attribs
  37.    fonts_common_action(arg(1), '', ATTRIBS_PROMPT)
  38. defc fonts_bold
  39.    fonts_common_action(arg(1), 'add_font_attrib' Bold_ATTRIB, BOLD_PROMPT)
  40. defc fonts_italic
  41.    fonts_common_action(arg(1), 'add_font_attrib' Italic_ATTRIB, ITALIC_PROMPT)
  42. defc fonts_underline
  43.    fonts_common_action(arg(1), 'add_font_attrib' Underscore_ATTRIB, UNDERLINE_PROMPT)
  44. defc fonts_outline
  45.    fonts_common_action(arg(1), 'add_font_attrib' Outline_ATTRIB, OUTLINE_PROMPT)
  46. defc fonts_strikeout
  47.    fonts_common_action(arg(1), 'add_font_attrib' Strikeout_ATTRIB, STRIKEOUT_PROMPT)
  48.  
  49.  
  50. defproc fonts_common_action(arg1, command, prompt)
  51.    parse value arg1 with action_letter parms
  52.    if action_letter = 'I' then       -- button Initialized
  53.       display -8
  54.       sayerror prompt
  55.       display 8
  56.    elseif action_letter = 'S' then   -- button Selected
  57.       sayerror 0
  58.       command
  59.    elseif action_letter = 'H' then   -- button Help
  60.       call winmessagebox(add_font_attrib_title, prompt, MB_OK + MB_INFORMATION + MB_MOVEABLE)
  61. ;; elseif action_letter = 'E' then   -- button End
  62. ;;    sayerror 0
  63.    endif
  64.  
  65. defc add_font_attrib
  66.    mt = marktype()
  67.    if mt='' then
  68.       sayerror -280  -- Text not marked
  69.       return
  70.    endif
  71.    getmark firstline, lastline, firstcol, lastcol, markfileid
  72.    getfileid fileid
  73.    if fileid<>markfileid then
  74.       sayerror OTHER_FILE_MARKED__MSG
  75.       return
  76.    endif
  77.    if leftstr(mt, 1) = 'B' & firstline<>lastline then
  78.       sayerror BLOCKMARK_ONE_LINE__MSG
  79.       return
  80.    endif
  81.    if leftstr(mt, 1) = 'L' then
  82.       lastcol = length(textline(lastline))
  83.    endif
  84.    parse arg attrib .
  85.    line=firstline; col=firstcol; offst=0
  86.    class = FONT_CLASS
  87.    attribute_action FIND_RULING_ATTR_SUBOP, class, offst, col, line
  88.    if class=0 then
  89.       font = .font
  90.    else
  91.       query_attribute class, font, IsPush, offst, col, line
  92.    endif
  93.    parse value queryfont(font) with fontname '.' fontsize '.' fontattrib
  94. compile if EVERSION >= '6.01b'
  95.    if fontattrib bitand attrib then
  96. compile else
  97.    if fontattrib%attrib - 2*(fontattrib%(attrib*2)) then
  98. compile endif
  99.       if class & line=firstline & col=firstcol then
  100.          offst2 = offst
  101.          attribute_action FIND_MATCH_ATTR_SUBOP, class, offst2, col, line
  102.          lc1 = lastcol+1
  103.          if class & line=lastline & col=lc1 then  -- Beginning & end matches; this is a toggle off.
  104.             offst1 = offst + 1
  105.             attribute_action DELETE_ATTR_SUBOP, class, offst, firstcol, firstline
  106.             attribute_action DELETE_ATTR_SUBOP, class, offst2, lc1, lastline
  107.             if fontattrib = attrib then  -- That was the only attribute set:
  108. ;                We've deleted the ruling attribute; now find the next outer one.
  109.                line=firstline; col=firstcol; offst=0
  110.                attribute_action FIND_RULING_ATTR_SUBOP, class, offst, col, line
  111.                if class=0 then
  112.                   font = .font
  113.                else
  114.                   query_attribute class, font, IsPush, offst, col, line
  115.                endif
  116.                parse value queryfont(font) with fontname '.' fontsize '.' fontattrib
  117. compile if EVERSION >= '6.01b'
  118.                if not (fontattrib bitand attrib) then  -- Already off?
  119. compile else
  120.                if not (fontattrib%attrib - 2*(fontattrib%(attrib*2))) then -- Already off?
  121. compile endif
  122.                   return                                            -- then all done.
  123.                endif
  124.             endif
  125. ;                We have to insert new attributes with the specified bit *off*.
  126.             newfont = registerfont(fontname, fontsize, fontattrib - attrib)
  127.             if not offst1 then
  128.                lastcol = lc1
  129.             endif
  130.             insert_attribute FONT_CLASS, newfont, 1, offst1, firstcol, firstline
  131.             insert_attribute FONT_CLASS, newfont, 0, -offst1, lastcol, lastline
  132.             return
  133.          else
  134.          endif
  135.       endif
  136.       sayerror ATTRIBUTE_ON__MSG
  137.       return
  138.    endif
  139.    newfont = registerfont(fontname, fontsize, fontattrib + attrib)
  140.    Insert_Attribute_Pair(FONT_CLASS, newfont, firstline, lastline, firstcol, lastcol, fileid)
  141.    call attribute_on(4)  -- Mixed fonts flag
  142.    call attribute_on(8)  -- "Save attributes" flag
  143.  
  144.  
  145.