home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a066 / 1.img / WINMSG.PRG < prev    next >
Encoding:
Text File  |  1992-03-20  |  2.0 KB  |  68 lines

  1. /*
  2.    winMsg.prg
  3.  
  4.    Copyright (c) 1991 Anton van Straaten
  5.  
  6.    Displays a message in an automatically-sized window and returns the
  7.    window handle.  Message can contain \n for newlines.
  8.  
  9.    Converted from Summer '87
  10. */
  11.  
  12. #include "win.ch"
  13.  
  14.  
  15. function winMsg(msg, Border, BordAtt, IntAtt)
  16.     local Pos, Pos1, TotLines, LineLen, Line, BotHght, TopHght, Width
  17.     local i, row, col, lines := {}
  18.     local win
  19.  
  20.     if at('\n', msg) != 0                       // split lines?
  21.         Pos := 1
  22.         TotLines := LineLen := 0
  23.  
  24.         while Pos > 0                           // extract chr()
  25.            Pos1 := at('\n', substr(msg, Pos))   // extract '\n' a la 'C'
  26.            if Pos1 == 0
  27.               Line := substr(msg, Pos)          // last line in string
  28.               Pos := 0
  29.            else
  30.               Line := substr(msg, Pos, Pos1 - 1)
  31.               Pos += Pos1 + 1                   // '+ 1' is for double \n
  32.            end
  33.  
  34.            if len(Line) > LineLen               // get longest line length
  35.               LineLen := len(Line) + 3
  36.            end
  37.  
  38.            aAdd(lines, Line)                    // add lines to array
  39.            ++TotLines
  40.         end
  41.     else                                        // no split lines
  42.         aadd(Lines, msg)
  43.         LineLen  = len(msg) + 3
  44.         TotLines = 1
  45.     end
  46.  
  47.     Width   = int(LineLen/2) + 1                // work out height/width
  48.     BotHght = int(TotLines/2)
  49.     TopHght = TotLines - BotHght
  50. *   Alternative box style:                            "╓─╖║╜─╙║ "
  51.     win := Window():new(12 - TopHght, 40 - Width, 13 + BotHght, 40 + Width,;
  52.                     if(Border == NIL, "╒═╕│╛═╘│ ", Border), BordAtt, IntAtt)
  53.     row := col := 0
  54.     for i = 1 to TotLines
  55.         @ i - 1, 1 say Lines[i]
  56.         if !empty(Lines[i])
  57.             row = row()
  58.             col = col()
  59.         end
  60.     next
  61.  
  62.     // tbd: need window method for below
  63.     SetPos(win:top + row, win:left + col)
  64.  
  65. return win
  66.  
  67. * eof winmsg.prg
  68.