ocrt.pp 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266
  1. Unit oCrt;
  2. {---------------------------------------------------------------------------
  3. CncWare
  4. (c) Copyright 1999-2000
  5. ---------------------------------------------------------------------------
  6. Filename..: ocrt.pp
  7. Programmer: Ken J. Wright, [email protected]
  8. Date......: 03/01/99
  9. Purpose - crt unit replacement plus OOP windows using ncurses.
  10. NOTE: All of the crt procedures & functions have been replaced with ncurses
  11. driven versions. This makes the ncurses library a little easier to use in a
  12. Pascal program and benefits from terminal independence.
  13. -------------------------------<< REVISIONS >>--------------------------------
  14. Ver | Date | Prog| Description
  15. -------+----------+-----+-----------------------------------------------------
  16. 1.00 | 03/01/99 | kjw | Initial Release.
  17. | 03/22/99 | kjw | Added nDelWindow(), delwin() does not nil pointer.
  18. 1.01 | 11/22/99 | kjw | Added the following: nEcho, ClrEol, ClrBot, InsLine,
  19. | DelLine, Delay, nClrEol, nClrBot, nInsLine, nDelLine,
  20. | nRefresh, nScroll, nDrawBox, nNewWindow, nWinColor,
  21. | nWriteScr, nFrame & some functions for returning
  22. | line drawing character values.
  23. 1.02 | 11/26/99 | kjw | Added nKeypressed().
  24. 1.03 | 12/01/99 | kjw | Added global boolean nIsActive.
  25. 1.04 | 12/03/99 | kjw | 1) Added procedures nHline, nVLine, & nWriteAC.
  26. | 2) Changed all the line draw character functions
  27. | (i.e., nHL, nVL) to return the longint value from
  28. | ncurses rather than the character value (which was
  29. | not very useful!). Now these can be passed to
  30. | nWriteAC() to correctly write the line drawing
  31. | characters.
  32. | 3) Added more of the ACS characters.
  33. 1.05 | 12/08/99 | kjw | 1) StartCurses() is now done as part of the unit
  34. | initialization block. EndCurses() is done via an
  35. | exit procedure.
  36. | 2) nIsActive is now a function (safer!).
  37. | 3) Added panel unit for windowing.
  38. | 4) Added tnWindow object.
  39. 1.10 | 12/12/99 | kjw | Added nSEdit().
  40. 1.11 | 12/12/99 | kjw | Added Special property to tEC object. Now any normal
  41. | character can trigger sedit to exit.
  42. ------------------------------------------------------------------------------
  43. 2.00 | 12/13/99 | kjw | nCrt renamed to oCrt. A new nCrt has been created
  44. | which is a drop-in replacement for the FPC crt unit.
  45. | oCrt contains all of nCrt plus the OOP extensions.
  46. | All of the common code is in ncrt.inc.
  47. 2.01 | 12/15/99 | kjw | 1) A tnWindow object now becomes the target for
  48. | stdout following Init & Show. A Hide will put the
  49. | target back to stdscr.
  50. | 2) Added nSetActiveWin() to manually pick a target
  51. | window for stdout.
  52. 2.02 | 12/15/99 | kjw | 1) PutFrame applied keypad to stdscr instead of sub.
  53. | 2) See ncrt.inc
  54. 2.03 | 12/16/99 | kjw | 1) See ncrt.inc
  55. | 2) Added shift/f-key constants.
  56. 2.04 | 01/04/00 | kjw | See ncrt.inc
  57. 2.05 | 01/06/00 | kjw | 1) See ncrt.inc.
  58. | 2) Added boolean internal_fwrite. FWrite was failing
  59. | when trying to write outside of the active window.
  60. | 3) nSEdit was not handling tec.firsttime correctly
  61. | when a tec.special was processed.
  62. 2.06 | 01/11/00 | kjw | See ncrt.inc.
  63. 2.07 | 01/31/00 | kjw | 1) See ncrt.inc.
  64. | 2) Added getcolor, getframecolor, getheadercolor
  65. | methods to tnWindow.
  66. 2.08 | 06/09/00 | kjw | 1) Added Picture property to tEC object. This is
  67. | used for picture input masking in nSEdit.
  68. | 2) Added nCheckPxPicture() function.
  69. | 3) nSEdit() changed to use picture input masking.
  70. | See pxpic.txt for a description of the picture
  71. | string format.
  72. 2.08.01 | 06/11/2000 | kjw
  73. | Fixed the spin cycle problem in nCheckPXPicture.
  74. 2.09.00 | 06/16/2000 | kjw
  75. | 1) nSEdit renamed to nEdit. Now nSEdit just calls nEdit() for
  76. | compatibility.
  77. | 2) Added overloaded nEdit functions for Integer, LongInt, and
  78. | Real types.
  79. | 3) Changed nEdit() embedding of control characters to preface
  80. | with a ^P. Also now uses a highlight attribute for the control
  81. | characters.
  82. | 4) Added control character cursor control to nEdit().
  83. | 5) Added Esc/1..0 = F1..F10 to nEdit().
  84. | 6) Added '@' to match set in pxpic.inc.
  85. | 7) tnWindow.Align was not positioning properly. Off by one.
  86. | 8) tnWindow.Init used wrong pointer for keypad and intrflush.
  87. | 9) tnWindow.Edit was messing up ec.Special.
  88. 2.09.01 | 06/16/2000 | kjw
  89. | 1) nStdScr (tnWindow) added and initialized at unit startup.
  90. | nStdScr can be used for a default full screen window.
  91. | 2) nEdit overloaded to work without a window pointer. It works
  92. | with the currently active window.
  93. 2.10.00 | 06/23/2000 | kjw
  94. | 1) Added character mapping to the tEC object. This includes the
  95. | ChMap property and the AddChMap() and ClrChMap() methods.
  96. | 2) Added AppendMode property to the tEC object. The character
  97. | typed in nEdit() is always appended to the current string
  98. | regardless of cursor position. Useful when ExitMode is true.
  99. | 3) tnWindow.Done was not re-assigning an ActiveWn.
  100. | 4) nEdit LeftArrow was allowing < x.
  101. | 5) Added nEditNumber() function.
  102. | 6) Added nEditDate() function.
  103. | 7) I made a command decision and renamed the tEC.FirstTime
  104. | property to tEC.ClearMode as it is more descriptive.
  105. 2.11.00 | 1) Cleaned up some loose ends with 2.10.
  106. | 2) Some more overloading
  107. | 3) Removed tnWindow.readln, write, and writeln methods.
  108. | 4) See ncrt.inc.
  109. 2.12.00 | 1) Remove the "n" from the tnWindow.editxxx functions for
  110. | consistancy. Procedurals are prefaced with an "n". Object methods
  111. | are not.
  112. | 2) Procedural FWrite renamed to nFWrite.
  113. | 3) tEC object type renamed to tnEC.
  114. | 4) Added nMakeWindow(), a one line procedural wrapper for
  115. | tnWindow.Init and tnWindow.PutHeader.
  116. | 5) Added GetX, GetY, IsFramed methods to tnWindow;
  117. | 6) Fixed nFWrite for too long strings;
  118. | 7) tnWindow.Align was wrong when justify was none.
  119. 2.13.00 | 06/30/00 | kjw | See ncrt.inc
  120. 2.14.00 | 07/05/00 | kjw | See ncrt.inc
  121. 2.15.00 | 07/12/00 | kjw |
  122. | 1) Renamed IsBold to nIsBold. Renamed SetColorPair to nSetColorPair.
  123. | 2) Added tnMenu object (not functional);
  124. | 07/17/00 | kjw |
  125. | 2) Argh!! Align method had another mistake. Changed x/y=1 to =0.
  126. | 3) Added nShowMessage() function.
  127. | 4) tnMenu is now minimally functional.
  128. | 07/25/00 | kjw |
  129. | 1) tnMenu fully functional for current level.
  130. 2.16.00 | 08/14/2000 | kjw |
  131. | 1) Added Get/SetMark(), IsActive(), IsValid(), IsAssigned(),
  132. | SetIndex() to tnMenu.
  133. | 08/18/2000 | kjw |
  134. | 1) Added nkXXX constants for all(?) extended keys.
  135. | 2) Changed all uses of extended keys to use new nkXXX's.
  136. | 3) Edit overloaded to return a nkXXX in ch rather that a char.
  137. | 4) Resize method added to tnWindow.
  138. | 5) AddChMap overloaded for preferred (easier) use with nkXXX's.
  139. | 08/24/2000 | kjw |
  140. | 1) Added nReadScr, nReadScrStr, nReadScrColor, nWriteScrStr,
  141. | nGrabScreen, nPopScreen, nReleaseScreen.
  142. | 2) Fixed some trouble with PrevWn accuracy.
  143. ------------------------------------------------------------------------------
  144. }
  145. Interface
  146. Uses
  147. {$ifdef unix}
  148. baseunix,
  149. termio,
  150. {$endif}
  151. ncurses,panel,menu,
  152. dos; {dos needed for TextRec}
  153. Const
  154. { decimal number format, us or european }
  155. nUS = 0;
  156. nEURO = 1;
  157. nDecFmt : byte = nUS;
  158. { border styles for text boxes }
  159. btNone : integer = 0;
  160. btSingle : integer = 1;
  161. btDouble : integer = 2;
  162. { ordinal keycodes, new style, preferred }
  163. nkEnter = 13; { Enter key }
  164. nkEsc = 27; { Home key }
  165. nkHome = -71; { Home key }
  166. nkUp = -72; { Up arrow }
  167. nkPgUp = -73; { PgUp key }
  168. nkLeft = -75; { Left arrow }
  169. nkRight = -77; { Right arrow }
  170. nkEnd = -79; { End key }
  171. nkDown = -80; { Down arrow }
  172. nkPgDn = -81; { PgDn key }
  173. nkIns = -82; { Insert key }
  174. nkDel = -83; { Delete key }
  175. nkCtrlLeft = -115; { Ctrl/left arrow }
  176. nkCtrlRight = -116; { Ctrl/right arrow }
  177. nkF1 = -59; { f1 key }
  178. nkF2 = -60; { f2 key }
  179. nkF3 = -61; { f3 key }
  180. nkF4 = -62; { f4 key }
  181. nkF5 = -63; { f5 key }
  182. nkF6 = -64; { f6 key }
  183. nkF7 = -65; { f7 key }
  184. nkF8 = -66; { f8 key }
  185. nkF9 = -67; { f9 key }
  186. nkF10 = -68; { f10 key }
  187. nkF11 = -84; { shift/f1 key }
  188. nkF12 = -85; { shift/f2 key }
  189. nkF13 = -86; { shift/f3 key }
  190. nkF14 = -87; { shift/f4 key }
  191. nkF15 = -88; { shift/f5 key }
  192. nkF16 = -89; { shift/f6 key }
  193. nkF17 = -90; { shift/f7 key }
  194. nkF18 = -91; { shift/f8 key }
  195. nkF19 = -92; { shift/f9 key }
  196. nkF20 = -93; { shift/f10 key }
  197. nkAltA = -30; { alt/a }
  198. nkAltB = -48; { alt/b }
  199. nkAltC = -46; { alt/c }
  200. nkAltD = -32; { alt/d }
  201. nkAltE = -18; { alt/e }
  202. nkAltF = -33; { alt/f }
  203. nkAltG = -34; { alt/g }
  204. nkAltH = -35; { alt/h }
  205. nkAltI = -23; { alt/i }
  206. nkAltJ = -36; { alt/j }
  207. nkAltK = -37; { alt/k }
  208. nkAltL = -38; { alt/l }
  209. nkAltM = -50; { alt/m }
  210. nkAltN = -49; { alt/n }
  211. nkAltO = -24; { alt/o }
  212. nkAltP = -25; { alt/p }
  213. nkAltQ = -16; { alt/q }
  214. nkAltR = -19; { alt/r }
  215. nkAltS = -31; { alt/s }
  216. nkAltT = -20; { alt/t }
  217. nkAltU = -22; { alt/u }
  218. nkAltV = -47; { alt/v }
  219. nkAltW = -17; { alt/w }
  220. nkAltX = -45; { alt/x }
  221. nkAltY = -21; { alt/y }
  222. nkAltZ = -44; { alt/z }
  223. nkAlt1 = -120; { alt/1 }
  224. nkAlt2 = -121; { alt/2 }
  225. nkAlt3 = -122; { alt/3 }
  226. nkAlt4 = -123; { alt/4 }
  227. nkAlt5 = -124; { alt/5 }
  228. nkAlt6 = -125; { alt/6 }
  229. nkAlt7 = -126; { alt/7 }
  230. nkAlt8 = -127; { alt/8 }
  231. nkAlt9 = -128; { alt/9 }
  232. nkAlt0 = -129; { alt/0 }
  233. nkAltMinus = -130; { alt/- }
  234. nkAltEqual = -131; { alt/= }
  235. nkAltTab = -15; { alt/tab }
  236. { ordinal key codes (old style, don't break any apps!) }
  237. nKeyEnter = nkEnter;
  238. nKeyEsc = nkEsc;
  239. nKeyHome = abs(nkHome);
  240. nKeyUp = abs(nkUp);
  241. nKeyPgUp = abs(nkPgUp);
  242. nKeyLeft = abs(nkLeft);
  243. nKeyRight = abs(nkRight);
  244. nKeyEnd = abs(nkEnd);
  245. nKeyDown = abs(nkDown);
  246. nKeyPgDn = abs(nkPgDn);
  247. nKeyIns = abs(nkIns);
  248. nKeyDel = abs(nkDel);
  249. nKeyCtrlLeft = abs(nkCtrlLeft);
  250. nKeyCtrlRight = abs(nkCtrlRight);
  251. nKeyF1 = abs(nkF1);
  252. nKeyF2 = abs(nkF2);
  253. nKeyF3 = abs(nkF3);
  254. nKeyF4 = abs(nkF4);
  255. nKeyF5 = abs(nkF5);
  256. nKeyF6 = abs(nkF6);
  257. nKeyF7 = abs(nkF7);
  258. nKeyF8 = abs(nkF8);
  259. nKeyF9 = abs(nkF9);
  260. nKeyF10 = abs(nkF10);
  261. nKeyF11 = abs(nkF11);
  262. nKeyF12 = abs(nkF12);
  263. nKeyF13 = abs(nkF13);
  264. nKeyF14 = abs(nkF14);
  265. nKeyF15 = abs(nkF15);
  266. nKeyF16 = abs(nkF16);
  267. nKeyF17 = abs(nkF17);
  268. nKeyF18 = abs(nkF18);
  269. nKeyF19 = abs(nkF19);
  270. nKeyF20 = abs(nkF20);
  271. { character mapping }
  272. nMaxChMaps = 255; { maximun index for character mapping }
  273. { menus }
  274. nMAXMENUITEMS = 100;
  275. Type
  276. {*** structures to save a screen via nGrabScreen ***}
  277. pnOneRow = pchar;
  278. { a buffer for a max of 256 chtype items accessed via pchar }
  279. tnOneRow = array [0..1023] of char;
  280. { a one way linked list of screen rows }
  281. pnRowBuf = ^tnRowBuf;
  282. tnRowBuf = Record
  283. row : pnOneRow; { one row of a screen }
  284. next : pnRowBuf; { next row in the list }
  285. End;
  286. { the header record of a saved screen }
  287. pnScreenBuf = ^tnScreenBuf;
  288. tnScreenBuf = Record
  289. x, { column origin }
  290. y, { row origin }
  291. n : integer; { number of columns }
  292. first : pnRowBuf; { pointer to first row in list }
  293. End;
  294. tnS10 = string[10];
  295. { for scrolling a window }
  296. tnUpDown = (up,down);
  297. { for window & header positioning }
  298. tnJustify = (none,left,center,right,top,bottom);
  299. { used for nEC character mapping }
  300. (********* Note : these are obsolete *******)
  301. nChMapStr = string[4];
  302. {nChMap = array [1..nMaxChMaps] of nChMapStr;}
  303. (*******************************************)
  304. nChMap = array [1..nMaxChMaps,1..2] of integer;
  305. { used for nSEdit }
  306. {------------------------------------------------------------------------
  307. ClearMode = true : passed string is initialized to ''.
  308. IsHidden = true : causes a string of '*' to display in place of
  309. the actual characters typed.
  310. InsMode : toggle for insert/overwrite mode.
  311. ExitMode = true : sedit exits after every keystroke.
  312. = false: sedit only exits when #27,#13, or any extended
  313. key *except* for Home,End,RArrow,LArrow.
  314. Special : If a pressed key is found in this string, then
  315. sedit exits without processing.
  316. Picture : An input mask string. See pxpic.txt for an
  317. explanation of picture strings.
  318. CtrlColor : The highlight color for embedded control characters.
  319. ChMap : An array of character triplets describing a character
  320. that is typed and what it should map to.
  321. ------------------------------------------------------------------------}
  322. tnEC = Object
  323. ClearMode,
  324. IsHidden,
  325. InsMode,
  326. ExitMode,
  327. AppendMode : boolean;
  328. Special : string;
  329. Picture : string;
  330. CtrlColor : integer;
  331. ChMap : nChMap;
  332. Constructor Init(ft,ih,im,em,ap : boolean;
  333. s,p : string;
  334. cc : integer;
  335. mp : nChMap);
  336. Destructor Done;
  337. Function AddChMap(_in,_out : integer) : integer;
  338. Function AddChMap(mp : nChMapStr) : integer;
  339. Procedure ClrChMap(idx : integer);
  340. End;
  341. pwin = ^Window;
  342. pnWindow = ^tnWindow;
  343. tnWindow = Object
  344. Private
  345. wn : pwindow; { pointer to win or sub to read/write to }
  346. win : pwindow; { pointer to main window record }
  347. sub : pwindow; { sub window if a bordered window }
  348. pan : ppanel; { pointer to panel record }
  349. subp : ppanel; { sub panel if a bordered window }
  350. visible : boolean; { is the window visible? }
  351. hasframe : boolean;
  352. wincolor, { window color }
  353. framecolor, { frame color }
  354. hdrcolor : integer; { header color }
  355. hdrpos : tnJustify; { header alignment }
  356. header : string[80]; { header string }
  357. Procedure init_wins(x,y,x1,y1 : integer);
  358. Procedure done_wins;
  359. Public
  360. data : pointer; { a pointer to user defined data }
  361. ec : tnEC; { edit control settings }
  362. Constructor Init(x,y,x1,y1,wcolor : integer;
  363. border : boolean;
  364. fcolor : integer);
  365. Destructor Done;
  366. Procedure Resize(cols_,rows_ : integer);
  367. Procedure Active; { make this the current window }
  368. Procedure Show; { display the window }
  369. Procedure Hide; { hide the window }
  370. Procedure ClrScr;
  371. Procedure ClrEol;
  372. Procedure ClrBot;
  373. Procedure InsLine;
  374. Procedure DelLine;
  375. Procedure GotoXY(x,y : integer);
  376. Function WhereX : integer;
  377. Function WhereY : integer;
  378. Function ReadKey : char;
  379. Procedure WriteAC(x,y,att,c : longint);
  380. Procedure FWrite(x,y,att,z : integer; s : string);
  381. Procedure DrawBox(LineStyle,x1,y1,x2,y2,att : Integer);
  382. Function GetHeader : string;
  383. Procedure PutHeader(hdr : string; hcolor : integer; hpos : tnJustify);
  384. Procedure SetColor(att : integer);
  385. Function GetColor : integer;
  386. Function GetFrameColor : integer;
  387. Function GetHeaderColor : integer;
  388. Procedure PutFrame(att : integer);
  389. Procedure Move(x,y : integer);
  390. Procedure Scroll(ln : integer; dir : tnUpDown);
  391. Procedure Align(hpos,vpos : tnJustify);
  392. Function Rows : integer;
  393. Function Cols : integer;
  394. Function GetX : integer;
  395. Function GetY : integer;
  396. Function IsFramed : boolean;
  397. Function IsVisible : Boolean;
  398. Function Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : integer) : String;
  399. Function Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  400. Function Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  401. Function Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  402. Function Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  403. Function Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;
  404. Function EditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : real;var esc : boolean) : real;
  405. Function EditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : longint;var esc : boolean) : longint;
  406. Function EditDate(x,y,att : integer;initv : string;var esc : boolean) : string;
  407. End;
  408. pnMenuStr = ^tnMenuStr;
  409. tnMenuStr = array [0..79] of char; { storage for menu item text }
  410. pnMenu = ^tnMenu;
  411. tnMenu = Object
  412. Private
  413. tc, { text (item) color }
  414. cc, { cursor (current item) color }
  415. fc, { frame color }
  416. hc, { header Color }
  417. gc, { non-selectable color }
  418. x,y, { top,left corner of window }
  419. r,c, { how many rows & columns of items to display }
  420. wid, { minimum window width }
  421. iidx, { item index }
  422. merr { menu error code }
  423. : integer;
  424. loopon,
  425. framed,
  426. posted : boolean; { is the menu posted? }
  427. mark : tnS10;
  428. items : array[1..nMAXMENUITEMS] of pnMenuStr;
  429. pi : array[1..nMAXMENUITEMS] of pItem;
  430. pm : pMenu;
  431. win : pnWindow;
  432. Procedure InitWin;
  433. Procedure ClearItem(idx : integer);
  434. Procedure AddItem(i : integer; s : string);
  435. Function Selectable(idx : integer) : boolean;
  436. Function IsValid(idx : integer) : boolean;
  437. Public
  438. Constructor Init(_x,_y,_w,_r,_c,_tc,_cc,_gc : integer;
  439. _fr : boolean; _fc : integer);
  440. Destructor Done;
  441. Procedure Post; { create the menu of current items }
  442. Procedure UnPost; { unbind the items and free the menu }
  443. Procedure Start; { start user input, includes show }
  444. Procedure Stop; { a shortcut for hide,unpost }
  445. Procedure Show; { display the menu, includes post }
  446. Procedure Hide; { remove the menu from the display }
  447. Function Wind : pnWindow; { pointer to the window object }
  448. Procedure Move(_x,_y : integer); { shortcut window move }
  449. Procedure Align(hpos,vpos : tnJustify);{ shortcut window align }
  450. Procedure PutHeader(hdr : string; hcolor : integer; hpos : tnJustify);
  451. Procedure Clear; { unpost and clear the menu item list }
  452. Function Add(s : string) : integer; { append a menu item }
  453. Procedure Insert(idx : integer; s : string); { insert a menu item }
  454. Procedure Remove(idx : integer); { delete a menu item }
  455. Procedure Change(idx : integer; s : string); { change an item }
  456. Procedure Active(idx : integer; b : boolean); { toggle gray }
  457. Function IsActive(idx : integer) : boolean; { item active ? }
  458. Procedure Spin(b : boolean);{ toggle item looping }
  459. Function Status : integer;{ return the current error/status code }
  460. Function Index : integer; { return the current item index }
  461. Procedure SetIndex(idx : integer); { set the item index }
  462. Function Count : integer; { number of items in the menu }
  463. Function Rows(_r : integer) : integer; {get/set menu rows }
  464. Function Cols(_c : integer) : integer; {get/set menu columns }
  465. Function IsAssigned(idx : integer) : boolean; { valid & assigned }
  466. Function GetMark : string; { return the item mark string }
  467. Procedure SetMark(ms : string); { set the mark string }
  468. Procedure Refresh;
  469. Procedure SetColor(att : byte); { change text color }
  470. Procedure SetCursorColor(att : byte); { change cursor color }
  471. Procedure SetFrameColor(att : byte); { change frame color }
  472. Procedure SetGrayColor(att : byte); { change inactive color }
  473. End;
  474. Var
  475. nStdScr : tnWindow; { default window created at unit initialization }
  476. nscreen : pwin; { pointer to ncurses stdscr }
  477. nEC : tnEC; { global edit control object }
  478. Procedure nSetActiveWin(win : pwindow);
  479. Procedure nDoNow(donow : boolean);
  480. Function nKeypressed(timeout : word) : boolean;
  481. Procedure nEcho(b : boolean);
  482. Procedure nWindow(var win : pWindow; x,y,x1,y1 : integer);
  483. Procedure nNewWindow(var win : pWindow; x,y,x1,y1 : integer);
  484. Procedure nDelWindow(var win : pWindow);
  485. Procedure nWinColor(win : pWindow; att : integer);
  486. Procedure nClrScr(win : pWindow; att : integer);
  487. Procedure nClrEol(win : pWindow);
  488. Procedure nClrBot(win : pWindow);
  489. Procedure nInsLine(win : pWindow);
  490. Procedure nDelLine(win : pWindow);
  491. Procedure nGotoXY(win : pWindow; x,y : integer);
  492. Function nWhereX(win : pWindow) : integer;
  493. Function nWhereY(win : pWindow) : integer;
  494. Function nReadkey(win : pWindow) : char;
  495. Function nReadln(win : pWindow) : string;
  496. Procedure nWrite(win : pWindow; s : string);
  497. Procedure nWriteln(win : pWindow; s : string);
  498. Procedure nWriteScr(win : pWindow; x,y,att : integer; s : string);
  499. Procedure nRefresh(win : pWindow);
  500. Procedure nScroll(win : pWindow; lines : integer; dir : tnUpDown);
  501. Procedure nDrawBox(win : pWindow; LineStyle,x1,y1,x2,y2,att : Integer);
  502. Procedure nFrame(win : pWindow);
  503. Function nRows(win : pWindow) : integer;
  504. Function nCols(win : pWindow) : integer;
  505. Function nHL : longint; { horizontal line }
  506. Function nVL : longint; { vertical line }
  507. Function nUL : longint; { upper left corner }
  508. Function nLL : longint; { lower loft corner }
  509. Function nUR : longint; { upper right corner }
  510. Function nLR : longint; { lower right corner }
  511. Function nLT : longint; { left tee }
  512. Function nRT : longint; { right tee }
  513. Function nTT : longint; { top tee }
  514. Function nBT : longint; { bottom tee }
  515. Function nPL : longint; { plus, + }
  516. Function nLA : longint; { left arrow }
  517. Function nRA : longint; { right arrow }
  518. Function nUA : longint; { up arror }
  519. Function nDA : longint; { down arrow }
  520. Function nDI : longint; { diamond }
  521. Function nCB : longint; { checkerboard }
  522. Function nDG : longint; { degree }
  523. Function nPM : longint; { plus/minus }
  524. Function nBL : longint; { bullet }
  525. Procedure nHLine(win : pwindow; col,row,attr,x : integer);
  526. Procedure nVLine(win : pwindow; col,row,attr,y : integer);
  527. Procedure nWriteAC(win : pwindow; x,y : integer; att,acs_char : longint);
  528. Function nIsBold(att : integer) : boolean;
  529. Function nSetColorPair(att : integer) : integer;
  530. Procedure nFWrite(win : pwindow; col,row,attrib : integer; clear : integer; s : string);
  531. Procedure nFWrite(col,row,attrib : integer; clear : integer; s : string);
  532. Function nSEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  533. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  534. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  535. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;
  536. Function nEdit(x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  537. Function nEdit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  538. Function nEdit(x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;
  539. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:String;Var chv : integer) : String;
  540. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  541. Function nEdit(win : pwindow; x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  542. Function nEdit(x,y,att,z,CursPos:Integer;es:String;Var ch : integer) : String;
  543. Function nEdit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  544. Function nEdit(x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  545. Function nEditNumber(win : pwindow; x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : real;var esc : boolean) : real;
  546. Function nEditNumber(win : pwindow; x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : longint;var esc : boolean) : longint;
  547. Function nEditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : real;var esc : boolean) : real;
  548. Function nEditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : longint;var esc : boolean) : longint;
  549. Function nEditDate(win : pwindow; x,y,att : integer;initv : string;var esc : boolean) : string;
  550. Function nEditDate(x,y,att : integer;initv : string;var esc : boolean) : string;
  551. Procedure nMakeWindow(var win : tnWindow;x1,y1,x2,y2,ta,ba,ha : integer;hasframe : boolean;hdrpos : tnJustify;hdrtxt : string);
  552. Procedure nMakeWindow(var win : pnWindow;x1,y1,x2,y2,ta,ba,ha : integer;hasframe : boolean;hdrpos : tnJustify;hdrtxt : string);
  553. Procedure nMakeMenu(var mnu : tnMenu;x,y,_w,_r,_c,ta,ca,ga,ba,ha : integer;hasframe : boolean;hdrpos : tnJustify;hdrtxt : string);
  554. Procedure nMakeMenu(var mnu : pnMenu;x,y,_w,_r,_c,ta,ca,ga,ba,ha : integer;hasframe : boolean;hdrpos : tnJustify;hdrtxt : string);
  555. Function nShowMessage(msg : string;matt : byte;hdr : string;hatt : byte;ack : boolean) : pnWindow;
  556. Function nReadScr(win : pWindow; x,y,n : integer) : string;
  557. Function nReadScr(x,y,n : integer) : string;
  558. Function nReadScrStr(win : pWindow; x,y,n : integer; buf : pchtype) : pchtype;
  559. Function nReadScrStr(x,y,n : integer; buf : pchtype) : pchtype;
  560. Function nReadScrColor(win : pWindow; x,y : integer) : integer;
  561. Function nReadScrColor(x,y : integer) : integer;
  562. Procedure nWriteScrStr(win : pWindow; x,y : integer; s : pchtype);
  563. Procedure nWriteScrStr(x,y : integer; s : pchtype);
  564. Procedure nGrabScreen(var p : pnScreenBuf; x,y,c,r : integer; win : pWindow);
  565. Procedure nGrabScreen(var p : pnScreenBuf; x,y,c,r : integer);
  566. Procedure nGrabScreen(var p : pnScreenBuf);
  567. Procedure nPopScreen(p : pnScreenBuf; x,y : integer; win : pWindow);
  568. Procedure nPopScreen(p : pnScreenBuf; x,y : integer);
  569. Procedure nPopScreen(p : pnScreenBuf);
  570. Procedure nReleaseScreen(p : pnScreenBuf);
  571. Function nCheckPxPicture(var s, Pic : string; var CPos : integer) : word;
  572. {$i ncrt.inc}
  573. {$i pxpic.inc}
  574. Var
  575. _chmap : nChMap;
  576. {---------------------------------------------------------------------
  577. tnWindow.Init
  578. Create a new window.
  579. x = upper left corner x, screen relative
  580. y = upper left corner y, screen relative
  581. x1 = lower right corner x, screen relative
  582. y1 = lower right corner y, screen relative
  583. wcolor = window/text color
  584. border = include a frame?
  585. fcolor = frame color
  586. ---------------------------------------------------------------------}
  587. Constructor tnWindow.Init(x,y,x1,y1,wcolor : integer;
  588. border : boolean;
  589. fcolor : integer);
  590. Var
  591. mp : nChMap;
  592. Begin
  593. hasframe := border;
  594. wincolor := wcolor;
  595. framecolor := fcolor;
  596. hdrcolor := wcolor;
  597. header := '';
  598. data := nil;
  599. visible := false;
  600. init_wins(x,y,x1,y1);
  601. FillChar(mp,SizeOf(mp),#0);
  602. ec.Init(false,false,false,false,false,'','',15,mp);
  603. ec.ClrChMap(0);
  604. SetActiveWn(wn);
  605. End;
  606. { deallocate the window }
  607. Destructor tnWindow.Done;
  608. Begin
  609. done_wins;
  610. ec.Done;
  611. SetActiveWn(nscreen);
  612. End;
  613. Procedure tnWindow.init_wins(x,y,x1,y1 : integer);
  614. Begin
  615. win := nil;
  616. sub := nil;
  617. pan := nil;
  618. subp := nil;
  619. win := newwin(y1-y+1,x1-x+1,y-1,x-1);
  620. pan := new_panel(win);
  621. hide_panel(pan);
  622. If hasframe Then
  623. PutFrame(framecolor)
  624. Else Begin
  625. wn := win;
  626. wbkgd(win,COLOR_PAIR(nSetColorPair(wincolor)));
  627. If nisbold(wincolor) then wattr_on(win,A_BOLD);
  628. scrollok(win,bool(true));
  629. intrflush(win,bool(false));
  630. keypad(win,bool(true));
  631. End;
  632. End;
  633. Procedure tnWindow.done_wins;
  634. Begin
  635. If subp <> nil Then del_panel(subp);
  636. If pan <> nil Then del_panel(pan);
  637. If sub <> nil Then delwin(sub);
  638. If (win <> nil) and (win <> stdscr) Then delwin(win);
  639. subp := nil;
  640. pan := nil;
  641. sub := nil;
  642. If win <> stdscr Then win := nil;
  643. End;
  644. Procedure tnWindow.ReSize(cols_,rows_ : integer);
  645. Var
  646. xx,yy,
  647. mx,my : integer;
  648. vis : boolean;
  649. Begin
  650. xx := GetX;
  651. yy := GetY;
  652. { can't be larger than full screen }
  653. If cols_ > nMaxCols Then cols_ := nMaxCols;
  654. If rows_ > nMaxRows Then rows_ := nMaxRows;
  655. { set the bottom, right corner }
  656. mx := xx+cols_-1;
  657. my := yy+rows_-1;
  658. { expand left? }
  659. If mx > nMaxCols Then xx := nMaxCols-cols_+1;
  660. { expand up? }
  661. If my > nMaxRows Then yy := nMaxRows-rows_+1;
  662. If xx < 1 Then xx := 1;
  663. If yy < 1 Then yy := 1;
  664. { reset the bottom, right corner }
  665. mx := xx+cols_-1;
  666. my := yy+rows_-1;
  667. { constrain to full screen }
  668. If mx > nMaxCols Then mx := nMaxCols;
  669. If my > nMaxRows Then my := nMaxRows;
  670. vis := visible;
  671. Hide;
  672. visible := vis;
  673. done_wins;
  674. init_wins(xx,yy,mx,my);
  675. If visible Then Show;
  676. End;
  677. { make the window current for all normal crt requests }
  678. Procedure tnWindow.Active;
  679. Begin
  680. SetActiveWn(wn);
  681. End;
  682. { display the window and move to the top }
  683. Procedure tnWindow.Show;
  684. Begin
  685. SetActiveWn(wn);
  686. visible := true;
  687. show_panel(pan);
  688. If subp <> nil Then show_panel(subp);
  689. update_panels;
  690. doupdate;
  691. End;
  692. { hide the window }
  693. Procedure tnWindow.Hide;
  694. Begin
  695. { don't go back to yourself }
  696. If PrevWn <> wn Then
  697. SetActiveWn(PrevWn)
  698. Else
  699. SetActiveWn(stdscr);
  700. visible := false;
  701. If subp <> nil Then hide_panel(subp);
  702. hide_panel(pan);
  703. update_panels;
  704. doupdate;
  705. GotoXY(WhereX,WhereY);
  706. End;
  707. Procedure tnWindow.ClrScr;
  708. Begin
  709. tmp_b := dorefresh;
  710. dorefresh := visible;
  711. nClrScr(wn,wincolor);
  712. dorefresh := tmp_b;
  713. End;
  714. Procedure tnWindow.ClrEol;
  715. Begin
  716. tmp_b := dorefresh;
  717. dorefresh := visible;
  718. nClrEol(wn);
  719. dorefresh := tmp_b;
  720. End;
  721. Procedure tnWindow.ClrBot;
  722. Begin
  723. tmp_b := dorefresh;
  724. dorefresh := visible;
  725. nClrBot(wn);
  726. dorefresh := tmp_b;
  727. End;
  728. Procedure tnWindow.InsLine;
  729. Begin
  730. tmp_b := dorefresh;
  731. dorefresh := visible;
  732. nInsLine(wn);
  733. dorefresh := tmp_b;
  734. End;
  735. Procedure tnWindow.DelLine;
  736. Begin
  737. tmp_b := dorefresh;
  738. dorefresh := visible;
  739. nDelLine(wn);
  740. dorefresh := tmp_b;
  741. End;
  742. { return the window border header string }
  743. Function tnWindow.GetHeader : string;
  744. Begin
  745. GetHeader := header;
  746. End;
  747. {----------------------------------------------------------------------
  748. put/replace a header string at the top of a bordered window
  749. hdr = header string (top line of window, only if hasframe = true)
  750. hcolor = header line color
  751. hpos = justfication of header string, left, center, or right
  752. ----------------------------------------------------------------------}
  753. Procedure tnWindow.PutHeader(hdr : string; hcolor : integer; hpos : tnJustify);
  754. Var
  755. cp,
  756. hx,
  757. len : integer;
  758. att,
  759. mx,my : longint;
  760. Begin
  761. If Hasframe Then Begin
  762. If hdr <> '' Then Begin
  763. header := hdr;
  764. hdrcolor := hcolor;
  765. hdrpos := hpos;
  766. getmaxyx(win,my,mx);
  767. nHline(win,2,1,framecolor,mx-1);
  768. len := mx-2;
  769. hdr := Copy(hdr,1,len);
  770. len := Length(hdr);
  771. Case hpos of
  772. left : hx := 1;
  773. center : hx := (mx - len) div 2;
  774. right : hx := (mx - len) - 1;
  775. End;
  776. mvwaddstr(win,0,hx,StrPCopy(ps,hdr));
  777. cp := nSetColorPair(hcolor);
  778. If nIsBold(hcolor) Then
  779. att := A_BOLD
  780. Else
  781. att := A_NORMAL;
  782. mvwchgat(win,0,hx,len,att,cp,0);
  783. End;
  784. End;
  785. End;
  786. { set the the color of the writable window }
  787. Procedure tnWindow.SetColor(att : integer);
  788. Begin
  789. wbkgd(wn,COLOR_PAIR(nSetColorPair(att)));
  790. If nisbold(att) then wattr_set(wn,A_BOLD);
  791. wincolor := att;
  792. If visible Then wrefresh(wn);
  793. End;
  794. { get the writeable window color }
  795. Function tnWindow.GetColor : integer;
  796. Begin
  797. GetColor := wincolor;
  798. End;
  799. { get the frame color }
  800. Function tnWindow.GetFrameColor : integer;
  801. Begin
  802. GetFrameColor := framecolor;
  803. End;
  804. { get the header color }
  805. Function tnWindow.GetHeaderColor : integer;
  806. Begin
  807. GetHeaderColor := hdrcolor;
  808. End;
  809. { frame an un-framed window, or update the frame color of a framed window }
  810. Procedure tnWindow.PutFrame(att : integer);
  811. Var
  812. x,y,
  813. mx,my,
  814. atts : longint;
  815. Begin
  816. wbkgd(win,COLOR_PAIR(nSetColorPair(att)));
  817. atts := wattr_get(win);
  818. If nisbold(att) then wattr_on(win,atts or A_BOLD);
  819. box(win,ACS_VLINE,ACS_HLINE);
  820. framecolor := att;
  821. If framecolor = -1 Then framecolor := wincolor;
  822. hasframe := true;
  823. If header <> '' Then PutHeader(header,hdrcolor,hdrpos);
  824. If sub = nil Then Begin
  825. getbegyx(win,y,x);
  826. getmaxyx(win,my,mx);
  827. sub := newwin(my-2,mx-2,y+1,x+1);
  828. If sub <> nil Then Begin
  829. subp := new_panel(sub);
  830. hide_panel(subp);
  831. wbkgd(sub,COLOR_PAIR(nSetColorPair(wincolor)));
  832. If nisbold(wincolor) then wattr_on(sub,A_BOLD);
  833. scrollok(sub,bool(true));
  834. intrflush(sub,bool(false));
  835. keypad(sub,bool(true));
  836. wn := sub;
  837. End;
  838. End;
  839. touchwin(sub);
  840. If visible Then Begin
  841. wrefresh(win);
  842. wrefresh(sub);
  843. End;
  844. End;
  845. { move the window }
  846. Procedure tnWindow.Move(x,y : integer);
  847. Begin
  848. move_panel(pan,y-1,x-1);
  849. If subp <> nil Then move_panel(subp,y,x);
  850. If visible Then Begin
  851. update_panels;
  852. doupdate;
  853. End;
  854. End;
  855. Procedure tnWindow.Align(hpos,vpos : tnJustify);
  856. Var
  857. x,y,
  858. bx,by : longint;
  859. Begin
  860. getmaxyx(win,y,x);
  861. getbegyx(win,by,bx);
  862. Case hpos of
  863. none : x := bx;
  864. left : x := 0;
  865. right : x := MaxCols - x;
  866. center : x := (MaxCols - x) div 2;
  867. End;
  868. Case vpos of
  869. none : y := by;
  870. top : y := 0;
  871. bottom : y := MaxRows - y;
  872. center : y := (MaxRows - y) div 2;
  873. End;
  874. move(x+1,y+1);
  875. End;
  876. Procedure tnWindow.Scroll(ln : integer; dir : tnUpDown);
  877. Begin
  878. nScroll(wn,ln,dir);
  879. End;
  880. Procedure tnWindow.GotoXY(x,y : integer);
  881. Begin
  882. tmp_b := dorefresh;
  883. dorefresh := visible;
  884. nGotoXY(wn,x,y);
  885. dorefresh := tmp_b;
  886. End;
  887. Function tnWindow.WhereX : integer;
  888. Begin
  889. WhereX := nWhereX(wn);
  890. End;
  891. Function tnWindow.WhereY : integer;
  892. Begin
  893. WhereY := nWhereY(wn);
  894. End;
  895. Function tnWindow.ReadKey : char;
  896. Begin
  897. ReadKey := nReadKey(wn);
  898. End;
  899. Procedure tnWindow.WriteAC(x,y,att,c : longint);
  900. Begin
  901. tmp_b := dorefresh;
  902. dorefresh := visible;
  903. nWriteAC(wn,x,y,att,c);
  904. dorefresh := tmp_b;
  905. End;
  906. Procedure tnWindow.FWrite(x,y,att,z : integer; s : string);
  907. Begin
  908. tmp_b := dorefresh;
  909. dorefresh := visible;
  910. nFWrite(wn,x,y,att,z,s);
  911. dorefresh := tmp_b;
  912. End;
  913. Procedure tnWindow.DrawBox(LineStyle,x1,y1,x2,y2,att : Integer);
  914. Begin
  915. tmp_b := dorefresh;
  916. dorefresh := visible;
  917. nDrawBox(wn,LineStyle,x1,y1,x2,y2,att);
  918. dorefresh := tmp_b;
  919. End;
  920. Function tnWindow.Rows : integer;
  921. Begin
  922. Rows := nRows(wn);
  923. End;
  924. Function tnWindow.Cols : integer;
  925. Begin
  926. Cols := nCols(wn);
  927. End;
  928. Function tnWindow.GetX : integer;
  929. Var
  930. x,y : longint;
  931. Begin
  932. getbegyx(win,y,x);
  933. GetX := x+1;
  934. End;
  935. Function tnWindow.GetY : integer;
  936. Var
  937. x,y : longint;
  938. Begin
  939. getbegyx(win,y,x);
  940. GetY := y+1;
  941. End;
  942. Function tnWindow.IsFramed : boolean;
  943. Begin
  944. IsFramed := hasframe;
  945. End;
  946. Function tnWindow.IsVisible : boolean;
  947. Begin
  948. IsVisible := visible;
  949. End;
  950. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : integer) : String;
  951. var
  952. tmp_ec : tnec;
  953. Begin
  954. { save global ec}
  955. tmp_ec := nEC;
  956. { init global ec to window ec }
  957. nEC := ec;
  958. Edit := nEdit(wn,x,y,att,z,CursPos,es,ch);
  959. { re-init window ec to possible changed values }
  960. ec.ClearMode := nEC.ClearMode;
  961. ec.InsMode := nEC.InsMode;
  962. { init global ec to saved }
  963. nEC := tmp_ec;
  964. End;
  965. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  966. var
  967. i : integer;
  968. Begin
  969. Edit := Edit(x,y,att,z,CursPos,es,i);
  970. ch := chr(abs(i));
  971. End;
  972. { overload for longint }
  973. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  974. var
  975. tmp_ec : tnec;
  976. Begin
  977. tmp_ec := nEC;
  978. nEC := ec;
  979. Edit := nEdit(wn,x,y,att,z,CursPos,es,ch);
  980. ec.ClearMode := nEC.ClearMode;
  981. ec.InsMode := nEC.InsMode;
  982. nEC := tmp_ec;
  983. End;
  984. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  985. var
  986. i : integer;
  987. Begin
  988. Edit := Edit(x,y,att,z,CursPos,es,i);
  989. ch := chr(abs(i));
  990. End;
  991. { overload for real }
  992. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  993. var
  994. tmp_ec : tnec;
  995. Begin
  996. tmp_ec := nEC;
  997. nEC := ec;
  998. Edit := nEdit(wn,x,y,att,z,CursPos,es,ch);
  999. ec.ClearMode := nEC.ClearMode;
  1000. ec.InsMode := nEC.InsMode;
  1001. nEC := tmp_ec;
  1002. End;
  1003. Function tnWindow.Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;
  1004. var
  1005. i : integer;
  1006. Begin
  1007. Edit := Edit(x,y,att,z,CursPos,es,i);
  1008. ch := chr(abs(i));
  1009. End;
  1010. Function tnWindow.EditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : real;var esc : boolean) : real;
  1011. var
  1012. tmp_ec : tnec;
  1013. Begin
  1014. tmp_ec := nEC;
  1015. nEC := ec;
  1016. EditNumber := nEditNumber(wn,x,y,att,wid,decm,bgd,initv,minv,maxv,esc);
  1017. ec.ClearMode := nEC.ClearMode;
  1018. ec.InsMode := nEC.InsMode;
  1019. nEC := tmp_ec;
  1020. End;
  1021. Function tnWindow.EditNumber(x,y,att,wid,decm : integer;bgd : string;initv,minv,maxv : longint;var esc : boolean) : longint;
  1022. var
  1023. tmp_ec : tnec;
  1024. Begin
  1025. tmp_ec := nEC;
  1026. nEC := ec;
  1027. EditNumber := nEditNumber(wn,x,y,att,wid,decm,bgd,initv,minv,maxv,esc);
  1028. ec.ClearMode := nEC.ClearMode;
  1029. ec.InsMode := nEC.InsMode;
  1030. nEC := tmp_ec;
  1031. End;
  1032. Function tnWindow.EditDate(x,y,att : integer;initv : string;var esc : boolean) : string;
  1033. var
  1034. tmp_ec : tnec;
  1035. Begin
  1036. tmp_ec := nEC;
  1037. nEC := ec;
  1038. EditDate := nEditDate(wn,x,y,att,initv,esc);
  1039. ec.ClearMode := nEC.ClearMode;
  1040. ec.InsMode := nEC.InsMode;
  1041. nEC := tmp_ec;
  1042. End;
  1043. {--------------------------- tnEC -------------------------------}
  1044. Constructor tnEC.Init(ft,ih,im,em,ap : boolean;
  1045. s,p : string;
  1046. cc : integer;
  1047. mp : nChMap);
  1048. Begin
  1049. ClearMode := ft;
  1050. IsHidden := ih;
  1051. InsMode := im;
  1052. ExitMode := em;
  1053. AppendMode := ap;
  1054. Special := s;
  1055. Picture := p;
  1056. CtrlColor := cc;
  1057. ChMap := mp;
  1058. End;
  1059. Destructor tnEC.Done;
  1060. Begin
  1061. End;
  1062. { Add or replace a character map }
  1063. { Preferred }
  1064. Function tnEC.AddChMap(_in,_out : integer) : integer;
  1065. Var
  1066. i : integer;
  1067. Begin
  1068. i := 0;
  1069. Repeat
  1070. inc(i);
  1071. Until (i > nMaxChMaps) or (ChMap[i,1] = _in) or (ChMap[i,1] = 0);
  1072. If i <= nMaxChMaps Then Begin
  1073. AddChMap := i;
  1074. ChMap[i,1] := _in;
  1075. ChMap[i,2] := _out;
  1076. End Else
  1077. AddChMap := 0;
  1078. End;
  1079. { Add or replace a character map }
  1080. { Obsolete, overloaded }
  1081. Function tnEC.AddChMap(mp : nChMapStr) : integer;
  1082. Var
  1083. i : integer;
  1084. _in,_out : integer;
  1085. Begin
  1086. { convert to new type }
  1087. If mp[1] = #0 Then
  1088. _in := ord(mp[2]) * (-1)
  1089. Else
  1090. _in := ord(mp[1]);
  1091. If mp[3] = #0 Then
  1092. _out := ord(mp[4]) * (-1)
  1093. Else
  1094. _out := ord(mp[3]);
  1095. AddChMap := AddChMap(_in,_out);
  1096. End;
  1097. Procedure tnEC.ClrChMap(idx : integer);
  1098. Begin
  1099. Case idx of
  1100. 0 : FillChar(ChMap,SizeOf(ChMap),0);
  1101. 1..nMaxChMaps : Begin
  1102. ChMap[idx,1] := 0;
  1103. ChMap[idx,2] := 0;
  1104. End;
  1105. End;
  1106. End;
  1107. {==========================================================================}
  1108. { set the active window for write(ln), read(ln) }
  1109. Procedure nSetActiveWin(win : pwindow);
  1110. Begin
  1111. SetActiveWn(win);
  1112. End;
  1113. {----------------------------------------------------------------
  1114. Set the refresh toggle.
  1115. If true, then all changes to a window are immediate. If false,
  1116. then changes appear following the next call to nRefresh.
  1117. ----------------------------------------------------------------}
  1118. Procedure nDoNow(donow : boolean);
  1119. Begin
  1120. dorefresh := donow;
  1121. End;
  1122. {-----------------------------------------------------
  1123. Set the echo flag.
  1124. This determines whether or not, characters are
  1125. echoed to the display when entered via the keyboard.
  1126. -----------------------------------------------------}
  1127. Procedure nEcho(b : boolean);
  1128. Begin
  1129. Case b of
  1130. true : echo;
  1131. false: noecho;
  1132. End;
  1133. isEcho := b;
  1134. End;
  1135. { create a new subwindow of stdscr }
  1136. Procedure nWindow(var win : pWindow; x,y,x1,y1 : integer);
  1137. Begin
  1138. nDelWindow(win);
  1139. win := subwin(stdscr,y1-y+1,x1-x+1,y-1,x-1);
  1140. If win = nil then Exit;
  1141. intrflush(win,bool(false));
  1142. keypad(win,bool(true));
  1143. scrollok(win,bool(true));
  1144. SetActiveWn(win);
  1145. End;
  1146. { create a new window }
  1147. Procedure nNewWindow(var win : pWindow; x,y,x1,y1 : integer);
  1148. Begin
  1149. nDelWindow(win);
  1150. win := newwin(y1-y+1,x1-x+1,y-1,x-1);
  1151. If win = nil then Exit;
  1152. intrflush(win,bool(false));
  1153. keypad(win,bool(true));
  1154. scrollok(win,bool(true));
  1155. SetActiveWn(win);
  1156. End;
  1157. { repaint a window }
  1158. Procedure nRefresh(win : pWindow);
  1159. Begin
  1160. touchwin(win);
  1161. wrefresh(win);
  1162. End;
  1163. {----------------------------------------------
  1164. Wait for a key to be pressed, with a timeout.
  1165. If a key is pressed, then nKeypressed returns
  1166. immediately as true, otherwise it return as
  1167. false after the timeout period.
  1168. ----------------------------------------------}
  1169. function nKeypressed(timeout : word) : boolean;
  1170. var
  1171. fds : TFDSet;
  1172. maxFD : longint;
  1173. Begin
  1174. fpFD_Zero(fds);
  1175. maxFD := 1;
  1176. { turn on stdin bit }
  1177. If fpFD_IsSet(STDIN,fds)=0 Then
  1178. fpFD_Set(STDIN,fds);
  1179. { wait for some input }
  1180. If fpSelect(maxFD,@fds,nil,nil,timeout) > 0 Then
  1181. nKeypressed := TRUE
  1182. Else
  1183. nKeypressed := FALSE;
  1184. End;
  1185. {---------------------------------
  1186. read input string from a window
  1187. ---------------------------------}
  1188. Function nReadln(win : pWindow) : string;
  1189. Begin
  1190. wgetstr(win,ps);
  1191. nReadln := StrPas(ps);
  1192. End;
  1193. { write a string to a window without refreshing screen }
  1194. { DON'T update PrevWn! }
  1195. Procedure nWriteScr(win : pWindow; x,y,att : integer; s : string);
  1196. Var
  1197. tmp : pwindow;
  1198. Begin
  1199. tmp := ActiveWn;
  1200. tmp_b := doRefresh;
  1201. ActiveWn := win;
  1202. doRefresh := false;
  1203. nFWrite(win,x,y,att,0,s);
  1204. ActiveWn := tmp;
  1205. doRefresh := tmp_b;
  1206. End;
  1207. {----------------------------------------------------------
  1208. Scroll a window, up or down, a specified number of lines.
  1209. lines = number of lines to scroll.
  1210. dir = direction, up or down.
  1211. ----------------------------------------------------------}
  1212. Procedure nScroll(win : pWindow; lines : integer; dir : tnUpDown);
  1213. Begin
  1214. ScrollOk(win,bool(True));
  1215. Case dir of
  1216. up : lines := abs(lines);
  1217. down : lines := abs(lines) * (-1);
  1218. End;
  1219. wscrl(win,lines);
  1220. If doRefresh Then wRefresh(win);
  1221. End;
  1222. { draw a colored box, with or without a border }
  1223. Procedure nDrawBox(win : pWindow; LineStyle,x1,y1,x2,y2,att : Integer);
  1224. Var
  1225. sub : pWindow;
  1226. x,y : longint;
  1227. Begin
  1228. getbegyx(win,y,x);
  1229. sub := subwin(win,y2-y1+1,x2-x1+1,y+y1-1,x+x1-1);
  1230. If sub = nil Then exit;
  1231. wbkgd(sub,CursesAtts(att));
  1232. werase(sub);
  1233. case LineStyle of
  1234. 1,2 : box(sub, ACS_VLINE, ACS_HLINE);
  1235. End;
  1236. If doRefresh Then wrefresh(sub);
  1237. nDelWindow(sub);
  1238. End;
  1239. {---------------------------
  1240. add a border to a window,
  1241. waits for a refresh
  1242. ---------------------------}
  1243. Procedure nFrame(win : pWindow);
  1244. Begin
  1245. box(win, ACS_VLINE, ACS_HLINE);
  1246. End;
  1247. {-----------------------------------------------------------
  1248. write a string to a window at the current cursor position
  1249. followed by a newline
  1250. -----------------------------------------------------------}
  1251. Procedure nWriteln(win : pWindow; s : string);
  1252. Begin
  1253. waddstr(win,StrPCopy(ps,s+#10));
  1254. If doRefresh Then wrefresh(win);
  1255. End;
  1256. { return then number of rows in a window }
  1257. Function nRows(win : pWindow) : integer;
  1258. Var
  1259. x,y : longint;
  1260. Begin
  1261. getmaxyx(win,y,x);
  1262. nRows := y;
  1263. End;
  1264. { return then number of columns in a window }
  1265. Function nCols(win : pWindow) : integer;
  1266. Var
  1267. x,y : longint;
  1268. Begin
  1269. getmaxyx(win,y,x);
  1270. nCols := x;
  1271. End;
  1272. {-------------------------------------------------------
  1273. Line drawing characters have to be handled specially.
  1274. Use nWriteAC() to write these characters. They cannot
  1275. be simply included as characters in a string.
  1276. -------------------------------------------------------}
  1277. { returns horizontal line character }
  1278. Function nHL : longint;
  1279. Begin
  1280. nHL := ACS_HLINE;
  1281. End;
  1282. { returns vertical line character }
  1283. Function nVL : longint;
  1284. Begin
  1285. nVL := ACS_VLINE;
  1286. End;
  1287. { returns upper left corner character }
  1288. Function nUL : longint;
  1289. Begin
  1290. nUL := ACS_ULCORNER;
  1291. End;
  1292. { returns lower left corner character }
  1293. Function nLL : longint;
  1294. Begin
  1295. nLL := ACS_LLCORNER;
  1296. End;
  1297. { returns upper right corner character }
  1298. Function nUR : longint;
  1299. Begin
  1300. nUR := ACS_URCORNER;
  1301. End;
  1302. { returns lower right corner character }
  1303. Function nLR : longint;
  1304. Begin
  1305. nLR := ACS_LRCORNER;
  1306. End;
  1307. { returns left tee character }
  1308. Function nLT : longint;
  1309. Begin
  1310. nLT := ACS_LTEE;
  1311. End;
  1312. { returns right tee character }
  1313. Function nRT : longint;
  1314. Begin
  1315. nRT := ACS_RTEE;
  1316. End;
  1317. { returns top tee character }
  1318. Function nTT : longint;
  1319. Begin
  1320. nTT := ACS_TTEE;
  1321. End;
  1322. { returns bottom tee character }
  1323. Function nBT : longint;
  1324. Begin
  1325. nBT := ACS_BTEE;
  1326. End;
  1327. { returns plus/cross character }
  1328. Function nPL : longint;
  1329. Begin
  1330. nPL := ACS_PLUS;
  1331. End;
  1332. { returns left arrow character }
  1333. Function nLA : longint;
  1334. Begin
  1335. nLA := ACS_LARROW;
  1336. End;
  1337. { returns right arrow character }
  1338. Function nRA : longint;
  1339. Begin
  1340. nRA := ACS_RARROW;
  1341. End;
  1342. { returns up arrow character }
  1343. Function nUA : longint;
  1344. Begin
  1345. nUA := ACS_UARROW;
  1346. End;
  1347. { returns down arrow character }
  1348. Function nDA : longint;
  1349. Begin
  1350. nDA := ACS_DARROW;
  1351. End;
  1352. { returns diamond character }
  1353. Function nDI : longint;
  1354. Begin
  1355. nDI := ACS_DIAMOND;
  1356. End;
  1357. { returns checkerboard character }
  1358. Function nCB : longint;
  1359. Begin
  1360. nCB := ACS_CKBOARD;
  1361. End;
  1362. { returns degree character }
  1363. Function nDG : longint;
  1364. Begin
  1365. nDG := ACS_DEGREE;
  1366. End;
  1367. { returns plus/minus character }
  1368. Function nPM : longint;
  1369. Begin
  1370. nPM := ACS_PLMINUS;
  1371. End;
  1372. { returns bullet character }
  1373. Function nBL : longint;
  1374. Begin
  1375. nBL := ACS_BULLET;
  1376. End;
  1377. { draw a horizontal line with color and a start & end position }
  1378. Procedure nHLine(win : pwindow; col,row,attr,x : integer);
  1379. var
  1380. sub : pwindow;
  1381. bx,by : longint;
  1382. Begin
  1383. getbegyx(win,by,bx);
  1384. sub := subwin(win,1,x-col+1,by+row-1,bx+col-1);
  1385. If sub = nil Then Exit;
  1386. x := getmaxx(sub);
  1387. wbkgd(sub,CursesAtts(attr));
  1388. mvwhline(sub,0,0,ACS_HLINE,x);
  1389. If doRefresh Then wrefresh(sub);
  1390. delwin(sub);
  1391. End;
  1392. { draw a vertical line with color and a start & end position }
  1393. Procedure nVLine(win : pwindow; col,row,attr,y : integer);
  1394. var sub : pwindow;
  1395. Begin
  1396. sub := subwin(win,y-row+1,1,row-1,col-1);
  1397. If sub = nil Then Exit;
  1398. wbkgd(sub,CursesAtts(attr));
  1399. mvwvline(sub,0,0,ACS_VLINE,y);
  1400. If doRefresh Then wrefresh(sub);
  1401. delwin(sub);
  1402. End;
  1403. {----------------------------------------------------------------
  1404. Write a character from the alternate character set. A normal
  1405. value from the alternate character set is larger than $400000.
  1406. If the value passed here is 128..255, then we assume it to be
  1407. the ordinal value from the IBM extended character set, and try
  1408. to map it to curses correctly. If it does not map, then we just
  1409. make it an alternate character and hope the output is what the
  1410. programmer expected. Note: this will work on the Linux console
  1411. just fine, but for other terminals the passed value must match
  1412. the termcap definition for the alternate character.
  1413. Note: The cursor returns to it's original position.
  1414. ----------------------------------------------------------------}
  1415. Procedure nWriteAC(win : pwindow; x,y : integer; att,acs_char : longint);
  1416. var
  1417. xx,yy,
  1418. cp : longint;
  1419. Begin
  1420. If acs_char in [0..255] Then Begin
  1421. Case acs_char of
  1422. 176 : acs_char := ACS_CKBOARD;
  1423. 179 : acs_char := ACS_VLINE;
  1424. 180 : acs_char := ACS_RTEE;
  1425. 191 : acs_char := ACS_URCORNER;
  1426. 192 : acs_char := ACS_LLCORNER;
  1427. 193 : acs_char := ACS_BTEE;
  1428. 194 : acs_char := ACS_TTEE;
  1429. 195 : acs_char := ACS_LTEE;
  1430. 196 : acs_char := ACS_HLINE;
  1431. 197 : acs_char := ACS_PLUS;
  1432. 218 : acs_char := ACS_ULCORNER;
  1433. 217 : acs_char := ACS_LRCORNER;
  1434. 241 : acs_char := ACS_PLMINUS;
  1435. 248 : acs_char := ACS_DEGREE;
  1436. 249 : acs_char := ACS_BULLET;
  1437. else acs_char := acs_char or A_ALTCHARSET;
  1438. End;
  1439. End;
  1440. { save the current cursor position }
  1441. getyx(win,yy,xx);
  1442. cp := nSetColorPair(att);
  1443. { write character with current attributes }
  1444. mvwaddch(win,y-1,x-1,acs_char);
  1445. { update with new attributes }
  1446. If nIsBold(att) Then
  1447. att := A_BOLD or A_ALTCHARSET
  1448. Else
  1449. att := A_NORMAL or A_ALTCHARSET;
  1450. mvwchgat(win,y-1,x-1,1,att,cp,0);
  1451. { return cursor to saved position }
  1452. wmove(win,yy,xx);
  1453. If doRefresh Then wrefresh(win);
  1454. End;
  1455. {-------------------------------------------------------------------
  1456. write a string to stdscr with color, without moving the cursor
  1457. Col = x start position
  1458. Row = y start position
  1459. Attrib = color (0..127), note color = (background*16)+foreground
  1460. Clear = clear line up to x position
  1461. s = string to write
  1462. -------------------------------------------------------------------}
  1463. Procedure nFWrite(win : pwindow; col,row,attrib : integer; clear : integer; s : string);
  1464. var
  1465. clr : array [0..255] of char;
  1466. cs : string;
  1467. sub : pWindow;
  1468. x,y,
  1469. mx,my,
  1470. xx,yy : longint;
  1471. ctrl : boolean;
  1472. Begin
  1473. if Clear > 0 Then Begin
  1474. FillChar(clr,SizeOf(clr),' ');
  1475. clr[SizeOf(clr)-1] := #0;
  1476. If Clear > MaxCols Then Clear := MaxCols;
  1477. cs := Copy(StrPas(clr),1,(Clear-Col)-Length(s)+1);
  1478. End Else
  1479. cs := '';
  1480. s := s+cs;
  1481. If s = '' Then Exit;
  1482. getyx(win,yy,xx);
  1483. getbegyx(win,y,x);
  1484. getmaxyx(win,my,mx);
  1485. If Length(s) > mx Then s := Copy(s,1,mx);
  1486. sub := subwin(win,1,Length(s),y+row-1,x+col-1);
  1487. If sub = nil Then Exit;
  1488. cs := s;
  1489. ctrl := false;
  1490. { look for embedded control characters }
  1491. For x := 1 to Length(s) Do Begin
  1492. If s[x] in [#0..#31] Then Begin
  1493. s[x] := ' ';
  1494. ctrl := true;
  1495. End;
  1496. End;
  1497. wbkgd(sub,COLOR_PAIR(nSetColorPair(Attrib)));
  1498. If nisbold(Attrib) then
  1499. wattr_on(sub,A_BOLD);
  1500. mvwaddstr(sub,0,0,StrPCopy(ps,s));
  1501. { highlight the embedded control characters substitutes }
  1502. If ctrl Then Begin
  1503. { nEC is always the current edit control object }
  1504. If Attrib <> nEC.CtrlColor Then
  1505. nWinColor(sub,nEC.CtrlColor)
  1506. Else Begin
  1507. { reverse the highlight color if same as current attribute }
  1508. bg := nEC.CtrlColor div 16;
  1509. fg := nEC.CtrlColor - (bg * 16);
  1510. While bg > 7 Do dec(bg,8);
  1511. While fg > 7 Do dec(fg,8);
  1512. nWinColor(sub,(fg*16)+bg);
  1513. End;
  1514. For x := 1 to Length(cs) Do Begin
  1515. If cs[x] in [#0..#31] Then
  1516. mvwaddch(sub,0,x-1,ord(cs[x])+64);
  1517. End;
  1518. End;
  1519. If doRefresh Then wrefresh(sub);
  1520. delwin(sub);
  1521. wmove(win,yy,xx);
  1522. End;
  1523. { overload - no pointer }
  1524. Procedure nFWrite(col,row,attrib : integer; clear : integer; s : string);
  1525. Begin
  1526. nFWrite(ActiveWn,col,row,attrib,clear,s);
  1527. End;
  1528. { compatibility for the old function name }
  1529. Function nSEdit(win : pwindow; x,y,att,z,CursPos:integer;
  1530. es:string;var ch : char) : string;
  1531. Var
  1532. s : string;
  1533. Begin
  1534. s := nEdit(win,x,y,att,z,CursPos,es,ch);
  1535. nSEdit := s;
  1536. End;
  1537. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1538. { String Editor }
  1539. Function nEdit(win : pwindow; { window to work in }
  1540. x,y, { base x,y coordinates of edit region }
  1541. att, { color attribute }
  1542. z, { right-most column of edit region }
  1543. CursPos:integer; { place cursor on this column at start }
  1544. es:string; { initial value of string }
  1545. var chv : integer { ordinal value of character typed, }
  1546. { negative for extended keys }
  1547. ) : string;
  1548. Var
  1549. ZMode,
  1550. AppendMode,
  1551. SEditExit : boolean;
  1552. prvx,
  1553. prvy,
  1554. pidx,
  1555. pres,
  1556. Index : integer;
  1557. ts,
  1558. hes : string;
  1559. isextended : boolean;
  1560. ch : char;
  1561. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1562. Procedure NewString;
  1563. BEGIN
  1564. nEdit := es;
  1565. hes := es;
  1566. FillChar(hes[1],Length(hes),'*');
  1567. END;
  1568. Procedure WriteString;
  1569. Var
  1570. xx,yy : integer;
  1571. Begin
  1572. xx := nWhereX(win);
  1573. yy := nWhereY(win);
  1574. If nEC.IsHidden Then
  1575. nFWrite(win,x,y,att,z,hes)
  1576. Else
  1577. nFWrite(win,x,y,att,z,es);
  1578. nGotoXY(win,xx,yy);
  1579. End;
  1580. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1581. Procedure EInsMode;
  1582. Begin
  1583. nEC.InsMode := (not nEC.InsMode)
  1584. End;
  1585. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1586. Procedure WriteChar;
  1587. var s : string;
  1588. Begin
  1589. ts := es;
  1590. If AppendMode Then Begin
  1591. es := es + ' ';
  1592. Index := Length(es);
  1593. End Else Begin
  1594. If nWhereX(win) >= Length(es)+x Then Repeat
  1595. es := es + ' ';
  1596. Until Length(es)+x-1 = nWhereX(win);
  1597. If es = '' Then es := ' ';
  1598. If Length(es)+x-1 = nWhereX(win) Then Index := Length(es);
  1599. End;
  1600. es[Index] := ch;
  1601. s := Copy(es,1,Index);
  1602. If nCheckPxPicture(s,nEC.Picture,pidx) <> 0 Then Begin
  1603. { no error, picture satisfied }
  1604. If (Length(s) > Length(es)) or
  1605. ((Length(s) = Length(es)) and (s <> es)) Then Begin
  1606. { expanded/changed by picture }
  1607. es := s;
  1608. End;
  1609. If pidx > Index Then Begin
  1610. If pidx > Length(es) Then pidx := Length(es);
  1611. If pidx > Index Then Index := pidx;
  1612. End;
  1613. End Else Begin
  1614. { error, did not fit the picture }
  1615. Sound(1000);
  1616. Delay(50);
  1617. NoSound;
  1618. es := ts;
  1619. Dec(Index);
  1620. End;
  1621. NewString;
  1622. WriteString;
  1623. If (Index < z-x+1) or not ZMode Then Begin
  1624. Index := Index+1;
  1625. nGotoXY(win,x+Index-1,y);
  1626. End;
  1627. End;
  1628. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1629. Procedure EInsert; { Insert }
  1630. Begin
  1631. If Length(es) < Z-X+1 Then Begin
  1632. ts := es;
  1633. Insert(' ',es,Index);
  1634. If nCheckPXPicture(es,nEC.Picture,pidx) = 0 Then Begin
  1635. Sound(1000);
  1636. Delay(50);
  1637. NoSound;
  1638. es := ts;
  1639. ch := #255;
  1640. End;
  1641. NewString;
  1642. WriteString;
  1643. End;
  1644. End;
  1645. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1646. Procedure EDelete; { Delete }
  1647. Begin
  1648. ts := es;
  1649. Delete(es,Index,1);
  1650. If nCheckPXPicture(es,nEC.Picture,pidx) = 0 Then Begin
  1651. Sound(1000);
  1652. Delay(50);
  1653. NoSound;
  1654. es := ts;
  1655. ch := #255;
  1656. End;
  1657. NewString;
  1658. WriteString;
  1659. End;
  1660. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1661. Procedure ECtrlEnd; { <CTRL> End }
  1662. Begin
  1663. Delete(es,Index,Length(es));
  1664. NewString;
  1665. WriteString;
  1666. End;
  1667. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1668. Procedure EHome; { Home }
  1669. Begin
  1670. Index := 1;
  1671. nGotoXY(win,x,y);
  1672. End;
  1673. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1674. Procedure ELeftArrow; { Left Arrow }
  1675. Begin
  1676. If nWhereX(win) > x Then Begin
  1677. dec(Index);
  1678. nGotoXY(win,nWhereX(win)-1,nWhereY(win));
  1679. End;
  1680. End;
  1681. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1682. Procedure ERightArrow; { Right Arrow }
  1683. Begin
  1684. If Index < z-x+1 Then Begin
  1685. nGotoXY(win,nWhereX(win)+1,nWhereY(win));
  1686. Index := Index + 1;
  1687. End;
  1688. End;
  1689. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1690. Procedure EEnd; { End }
  1691. Begin
  1692. Index := Length(es)+1;
  1693. If Index > z-x+1 Then Index := Length(es);
  1694. If Index < 1 Then Index := 1;
  1695. If Index > MaxCols Then Index := MaxCols;
  1696. nGotoXY(win,x+(Index-1),y);
  1697. End;
  1698. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1699. Procedure EBackSpace; { Backspace }
  1700. Begin
  1701. Index := Index - 1;
  1702. If Index < 1 Then Begin
  1703. Index := 1;
  1704. Exit;
  1705. End Else
  1706. If nWhereX(win) > x Then nGotoXY(win,nWhereX(win) - 1,nWhereY(win));
  1707. Delete(es,Index,1);
  1708. NewString;
  1709. WriteString;
  1710. nGotoXY(win,x+(Index-1),y);
  1711. End;
  1712. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1713. Procedure ETurboBackSpace; { Ctrl/Backspace }
  1714. Begin
  1715. If Index = 1 Then Exit;
  1716. Delete(es,1,Index-1);
  1717. NewString;
  1718. Index := 1;
  1719. If nWhereX(win) > x Then nGotoXY(win,1,nWhereY(win));
  1720. WriteString;
  1721. nGotoXY(win,x,y);
  1722. END;
  1723. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1724. Procedure ECtrlLeftArrow;{ Ctrl Left Arrow }
  1725. Begin
  1726. If nEC.IsHidden Then Begin
  1727. EHome;
  1728. Exit;
  1729. End;
  1730. If es[Index-1] = ' ' Then Index := Index-1;
  1731. If es[Index] <> ' ' Then Begin
  1732. While (Index > 1) And (es[Index] <> ' ') Do
  1733. Index := Index-1;
  1734. End Else
  1735. If es[Index] = ' ' Then Begin
  1736. While (Index > 1) And (es[Index] = ' ') Do
  1737. Index := Index-1;
  1738. While (Index > 1) And (es[Index] <> ' ') Do
  1739. Index := Index-1;
  1740. End;
  1741. If Index = 1 Then
  1742. nGotoXY(win,x,y)
  1743. Else Begin
  1744. nGotoXY(win,x+Index,y);
  1745. Index := Index+1;
  1746. End;
  1747. End;
  1748. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1749. Procedure ECtrlRightArrow;{ Ctrl Right Arrow }
  1750. Begin
  1751. If nEC.IsHidden Then Begin
  1752. EEnd;
  1753. Exit;
  1754. End;
  1755. While (Index < Length(es)) And (es[Index] <> ' ') Do
  1756. Begin
  1757. Index := Index+1;
  1758. End;
  1759. While (Index < Length(es)) And (es[Index] = ' ') Do
  1760. Begin
  1761. Index := Index+1;
  1762. End;
  1763. nGotoXY(win,x+Index-1,y);
  1764. End;
  1765. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1766. Procedure CheckForWriteChar(embed : boolean);
  1767. Begin
  1768. If embed or Not (Ch In [#27,#255]) Then Begin
  1769. If (ch in [#10,#13]) and (not embed) {and not ControlKey} Then exit;
  1770. If nEC.ClearMode Then Begin
  1771. es := '';
  1772. WriteString;
  1773. nGotoXY(win,X,Y);
  1774. Index := 1;
  1775. WriteChar;
  1776. nEC.ClearMode := False;
  1777. End Else Begin
  1778. If nEC.InsMode Then Begin
  1779. EInsert;
  1780. WriteChar;
  1781. End Else WriteChar;
  1782. End;
  1783. End;
  1784. End;
  1785. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1786. Procedure ProcessSpecialKey;
  1787. begin
  1788. If ch = #129 Then ch := #68; { Linux, map Esc/0 to F10 }
  1789. chv := ord(ch) * (-1); { set the return value }
  1790. Case ch of
  1791. #16..#25,
  1792. #30..#38,
  1793. #44..#50,
  1794. #59..#68,
  1795. #84..#90,
  1796. #92..#113,
  1797. #118,
  1798. #132,
  1799. #72,
  1800. #73,
  1801. #80,
  1802. #81 : Begin SEditExit:=True;Exit;End;
  1803. #71 : EHome;
  1804. #75 : ELeftArrow;
  1805. #77 : ERightArrow;
  1806. #79 : EEnd;
  1807. #82 : EInsMode;
  1808. #83 : EDelete;
  1809. #15,
  1810. #115 : ECtrlLeftArrow;
  1811. #116 : ECtrlRightArrow;
  1812. #117 : ECtrlEnd;
  1813. End;
  1814. End;
  1815. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  1816. Procedure ProcessNormalKey;
  1817. Var
  1818. i : integer;
  1819. ctrl : boolean;
  1820. begin
  1821. chv := ord(ch); { set the return value }
  1822. For i := 1 to Length(nEC.Special) Do Begin
  1823. If ch = nEC.Special[i] Then Begin
  1824. SEditExit:=True;
  1825. Exit;
  1826. End;
  1827. End;
  1828. ctrl := false;
  1829. { standard control key assignments }
  1830. case ch of
  1831. #0..#15,
  1832. #17..#31 : Begin
  1833. nEC.ClearMode := False;
  1834. Case ch of
  1835. #1 : EHome;
  1836. #5 : EEnd;
  1837. #2 : ELeftArrow;
  1838. #6 : ERightArrow;
  1839. #19 : ECtrlLeftArrow;
  1840. #4 : ECtrlRightArrow;
  1841. #7 : EDelete;
  1842. #9 : EInsMode;
  1843. #8 : EBackSpace;
  1844. #10 : ch := #13;
  1845. #13 : Begin
  1846. pres := nCheckPxPicture(es,nEC.Picture,pidx);
  1847. If pres <> 2 Then Begin
  1848. Sound(1000);
  1849. Delay(50);
  1850. NoSound;
  1851. ch := #255;
  1852. End;
  1853. End;
  1854. #27 : If KeyPressed Then Begin
  1855. { covers up a Linux peculiarity where the next }
  1856. { character typed bleeds through with esc/1..9 }
  1857. nGotoXY(win,prvx,prvy);
  1858. WriteString;
  1859. ch := ReadKey;
  1860. { make it a function key }
  1861. If ch in ['1'..'9'] Then Begin
  1862. ch := Char(Ord(ch)+10);
  1863. chv := ord(ch) * (-1);
  1864. End Else ch := #27;
  1865. SEditExit := true;
  1866. End;
  1867. End;
  1868. Exit;
  1869. End;
  1870. #16 : Begin
  1871. { embed control characters in the string }
  1872. ch := UpCase(ReadKey);
  1873. If ch in ['@','2','A'..'Z'] Then Begin
  1874. ctrl := true;
  1875. If ch = '2' Then ch := '@';
  1876. ch := Char(Ord(ch)-64);
  1877. chv := ord(ch);
  1878. End;
  1879. End;
  1880. #127 : Begin nEC.ClearMode := False;ETurboBackSpace;Exit;End;
  1881. end;
  1882. CheckForWriteChar(ctrl);
  1883. ch := #0;
  1884. end;
  1885. {-----------------------------------------------------------------------
  1886. Map a keystroke to another character, normal or extended.
  1887. The maps are 4 character strings interpreted as 2 sets of character
  1888. pairs that represent the following:
  1889. 1st char - If it is #0 then it is an extended char. Use the 2nd
  1890. character to identify.
  1891. 2nd char - Only used if 1st char is #0.
  1892. The first pair of the string is the actual key pressed.
  1893. The second pair is what that key should be become.
  1894. #0#59 = F1, extended key
  1895. #59#0 = ; , normal key
  1896. So a map of #0#59#59#0 maps the F1 key to the ; key,
  1897. and #0#59#0#60 maps the F1 key to the F2 key,
  1898. and #0#59#0#0 maps the F1 key to a null.
  1899. Examples:
  1900. #0#59#0#60 = map F1 to F2
  1901. #1#0#0#59 = map ^A to F1
  1902. #0#59#1#0 = map F1 to ^A
  1903. #0#59#0#0 = map F1 to ^@ (null)
  1904. #0#0#0#59 = map ^@ to F1
  1905. #97#0#65#0 = map a to A
  1906. }
  1907. Procedure MapKey(var ch : char;var eflag : boolean);
  1908. Var
  1909. i,
  1910. cv : integer;
  1911. s2 : string[2];
  1912. s4 : string[4];
  1913. Begin
  1914. cv := Ord(ch);
  1915. If eflag Then cv := cv * (-1);
  1916. i := 0;
  1917. { look for a character map assignment }
  1918. Repeat
  1919. inc(i);
  1920. Until (i > nMaxChMaps) or (nEC.ChMap[i,1] = cv);
  1921. { if found, then re-assign ch to the mapped key }
  1922. If i <= nMaxChMaps Then Begin
  1923. cv := nEC.ChMap[i,2];
  1924. eflag := (cv < 0);
  1925. ch := chr(abs(cv));
  1926. End;
  1927. (*
  1928. { look for a character map assignment }
  1929. i := 0;
  1930. s4 := #0#0#0#0;
  1931. Case eflag of
  1932. true : s2 := #0+ch;
  1933. false : s2 := ch+#0;
  1934. End;
  1935. Repeat
  1936. inc(i);
  1937. Until (i > nMaxChMaps) or (pos(s2,nEC.ChMap[i]) = 1);
  1938. { if found, then re-assign ch to the mapped key }
  1939. If i <= nMaxChMaps Then Begin
  1940. system.Move(nEC.ChMap[i,1],s4[1],Length(nEC.ChMap[i]));
  1941. s2 := Copy(s4,3,2);
  1942. eflag := (s2[1] = #0);
  1943. Case eflag of
  1944. true : ch := s2[2];
  1945. false : ch := s2[1];
  1946. End;
  1947. If ch = #0 Then eflag := false;
  1948. End;
  1949. *)
  1950. End;
  1951. {============================================================================}
  1952. Begin
  1953. SEditExit := nEC.ExitMode;
  1954. AppendMode := nEC.AppendMode;
  1955. ZMode := z <> 0;
  1956. If CursPos > Length(es)+x Then
  1957. Index := Length(es)+1 { End Of String }
  1958. Else Index := CursPos+1-x; { Inside Of String }
  1959. If Not ZMode then z := x+length(es);
  1960. Newstring;
  1961. WriteString;
  1962. nGotoXY(win,CursPos,y);
  1963. Repeat
  1964. prvx := nWhereX(win); { save for ProcessNormalKey }
  1965. prvy := nWhereY(win);
  1966. If Not ZMode then z := x+length(es);
  1967. ch := ReadKey;
  1968. isextended := (ch = #0);
  1969. If isextended Then
  1970. ch := ReadKey;
  1971. MapKey(ch,isextended);
  1972. If isextended Then
  1973. ProcessSpecialKey
  1974. Else
  1975. ProcessNormalKey;
  1976. Until (ch In [#13,#27]) or SEditExit;
  1977. nEC.ClearMode := False;
  1978. NewString;
  1979. End;{ of nEdit }
  1980. { compatibility for old ch type }
  1981. Function nEdit(win : pwindow; x,y,att,z,CursPos:integer;
  1982. es:string;var ch : char) : string;
  1983. Var i : integer;
  1984. Begin
  1985. nEdit := nEdit(win,x,y,att,z,CursPos,es,i);
  1986. ch := chr(abs(i));
  1987. End;
  1988. { nEdit using currently active window }
  1989. Function nEdit(x,y,att,z,CursPos:integer;
  1990. es:string;var ch : integer) : string;
  1991. Begin
  1992. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,ch);
  1993. End;
  1994. Function nEdit(x,y,att,z,CursPos:integer;
  1995. es:string;var ch : char) : string;
  1996. Var i : integer;
  1997. Begin
  1998. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,i);
  1999. ch := chr(ord(i));
  2000. End;
  2001. { overload for longint type }
  2002. Function nEdit(x,y,att,z,CursPos:integer;
  2003. es:longint;var ch : integer) : longint;
  2004. Begin
  2005. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,ch);
  2006. End;
  2007. Function nEdit(x,y,att,z,CursPos:integer;
  2008. es:longint;var ch : char) : longint;
  2009. Begin
  2010. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,ch);
  2011. End;
  2012. { longint with pointer }
  2013. Function nEdit(win : pwindow; x,y,att,z,CursPos:integer;
  2014. es:LongInt;var ch : integer) : LongInt;
  2015. Var
  2016. savpic,
  2017. ess : string;
  2018. esv,
  2019. err : longint;
  2020. Begin
  2021. Str(es:0,ess);
  2022. savpic := nEC.Picture;
  2023. If savpic = '' Then nEC.Picture := '[-]#*#';
  2024. ess := nEdit(win,x,y,att,z,CursPos,ess,ch);
  2025. nEC.Picture := savpic;
  2026. val(ess,esv,err);
  2027. nEdit := esv;
  2028. End;
  2029. Function nEdit(win : pwindow; x,y,att,z,CursPos:integer;
  2030. es:longint;var ch : char) : longint;
  2031. Var i : integer;
  2032. Begin
  2033. nEdit := nEdit(win,x,y,att,z,CursPos,es,i);
  2034. ch := chr(abs(i));
  2035. End;
  2036. { overload for real type }
  2037. Function nEdit(x,y,att,z,CursPos:integer;
  2038. es:real;var ch : integer) : real;
  2039. Begin
  2040. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,ch);
  2041. End;
  2042. Function nEdit(x,y,att,z,CursPos:integer;
  2043. es:real;var ch : char) : real;
  2044. Var i : integer;
  2045. Begin
  2046. nEdit := nEdit(ActiveWn,x,y,att,z,CursPos,es,i);
  2047. ch := chr(abs(i));
  2048. End;
  2049. { with pointer }
  2050. Function nEdit(win : pwindow; x,y,att,z,CursPos:integer;
  2051. es:Real;var ch : integer) : Real;
  2052. Var
  2053. savpic,
  2054. ess : string;
  2055. esv : real;
  2056. i,
  2057. err : Integer;
  2058. Begin
  2059. Str(es:0:12,ess);
  2060. While ess[Length(ess)] = '0' Do Delete(ess,Length(ess),1);
  2061. savpic := nEC.Picture;
  2062. If savpic = '' Then Begin
  2063. Case nDecFmt of
  2064. nUS : nEC.Picture := '[+,-]#*#[[.*#][{E,e}[+,-]#[#][#][#]]]';
  2065. nEURO : Begin
  2066. nEC.Picture := '[+,-]#*#[[;,*#][{E,e}[+,-]#[#][#][#]]]';
  2067. For i := 1 to Length(ess) Do
  2068. If ess[i] = '.' Then ess[i] := ',';
  2069. End;
  2070. End;
  2071. End;
  2072. ess := nEdit(win,x,y,att,z,CursPos,ess,ch);
  2073. nEC.Picture := savpic;
  2074. For i := 1 to Length(ess) Do If ess[i] = ',' Then ess[i] := '.';
  2075. val(ess,esv,err);
  2076. nEdit := esv;
  2077. End;
  2078. Function nEdit(win : pwindow; x,y,att,z,CursPos:integer;
  2079. es:real;var ch : char) : real;
  2080. Var i : integer;
  2081. Begin
  2082. nEdit := nEdit(win,x,y,att,z,CursPos,es,i);
  2083. ch := chr(abs(i));
  2084. End;
  2085. { And now some sugar for Rainer Hantsch! }
  2086. {------------------------------------------------------------------------
  2087. This is a right justified number editor. As a digit is typed, the
  2088. existing number string gets pushed left and the new digit is appended.
  2089. If decimal columns are specified, then pressing <space> will enter the
  2090. decimal character (. or ,). A background string can be specified that
  2091. fills the empty spaces.
  2092. ------------------------------------------------------------------------}
  2093. Function nEditNumber(
  2094. win : pwindow;
  2095. x, { edit field start column }
  2096. y, { edit field start row }
  2097. att, { edit field color attribute }
  2098. wid, { edit field width }
  2099. decm : integer; { number of decimal columns }
  2100. bgd : string; { background string -
  2101. if bgd = '', then no background
  2102. if bgd = a single character, then is used as the
  2103. background fill character.
  2104. if bgd length is longer than wid, then the entire
  2105. bgd string is used as the background.}
  2106. initv, { initial value }
  2107. minv, { range minimum value }
  2108. maxv : real; { range maximum value }
  2109. var esc : boolean { if Esc key pressed = true, else = false }
  2110. ) : real;
  2111. Const
  2112. { up to 12 decimal places }
  2113. decs : string = '[#][#][#][#][#][#][#][#][#][#][#][#]';
  2114. Var
  2115. r : real;
  2116. s,s1,s2 : string;
  2117. i,
  2118. e,
  2119. bc,
  2120. bx : integer;
  2121. ch : char;
  2122. fill : array [0..255] of char;
  2123. tmp_ec : tnEC;
  2124. Begin
  2125. tmp_ec := nEC;
  2126. nEC.ExitMode := true;
  2127. nEC.AppendMode := true;
  2128. nEC.ClrChMap(0);
  2129. nEC.AddChMap(#7#0#0+Char(nKeyDel));
  2130. nEC.AddChMap(#8#0#0+Char(nKeyDel));
  2131. If decm > (Length(decs) div 3) Then
  2132. decm := (Length(decs) div 3);
  2133. If decm >= wid Then decm := (wid - 1);
  2134. If decm > 0 Then Begin
  2135. nEC.Picture := '[-]*#[{.}'+Copy(decs,1,(decm*3))+']';
  2136. If nDecFmt = nEURO Then Begin
  2137. nEC.Picture[8] := ',';
  2138. Insert(';',nEC.Picture,8);
  2139. nEC.AddChMap('.'+#0+','+#0);
  2140. End;
  2141. End Else
  2142. nEC.Picture := '[-]*#';
  2143. If bgd = '' Then Begin
  2144. bgd := ' ';
  2145. bc := att;
  2146. End Else
  2147. bc := nEC.CtrlColor;
  2148. If Length(bgd) < wid Then Begin
  2149. FillChar(fill,wid,bgd[1]);
  2150. fill[wid] := #0;
  2151. bgd := StrPas(fill);
  2152. End;
  2153. bx := x;
  2154. If Length(bgd) > wid Then inc(x);
  2155. str(initv:wid:decm,s);
  2156. While s[1] = ' ' Do Delete(s,1,1);
  2157. If Pos('.',s) <> 0 Then
  2158. While s[Length(s)] = '0' Do Delete(s,Length(s),1);
  2159. If decm = 0 Then Delete(s,Pos('.',s),1);
  2160. If nDecFmt = nEURO Then For i := 1 to Length(s) Do
  2161. If s[i] = '.' Then s[i] := ',';
  2162. Repeat
  2163. nFWrite(win,bx,y,bc,bx+Length(bgd)-(x-bx),copy(bgd,1,wid-length(s)+(x-bx)));
  2164. If x > bx Then
  2165. nFWrite(win,x+wid,y,bc,0,copy(bgd,wid+2,length(bgd)));
  2166. s1 := nEdit(win,x+wid-Length(s),y,att,x+wid-1,x+wid-1,s,ch);
  2167. s2 := s1;
  2168. If nDecFmt = nEURO Then For i := 1 to Length(s2) Do
  2169. If s2[i] = ',' Then s2[i] := '.';
  2170. val(s2,r,e);
  2171. If (s1 = '') or ((e = 0) and (r >= minv) and (r <= maxv)) Then
  2172. s := s1
  2173. Else
  2174. If ch <> #27 then Begin
  2175. ch := #0;
  2176. Sound(1000);
  2177. Delay(50);
  2178. NoSound;
  2179. End;
  2180. nEC.AppendMode := Length(s) < wid;
  2181. Until ch in [#13,#27];
  2182. esc := (ch = #27);
  2183. nEditNumber := r;
  2184. nEC := tmp_ec;
  2185. End;
  2186. { overload - real, no pointer }
  2187. Function nEditNumber(
  2188. x,y,att,wid,decm : integer;
  2189. bgd : string;
  2190. initv,
  2191. minv,
  2192. maxv : real;
  2193. var esc : boolean) : real;
  2194. Begin
  2195. nEditNumber := nEditNumber(ActiveWn,x,y,att,wid,decm,bgd,initv,minv,maxv,esc);
  2196. End;
  2197. { overload for longint }
  2198. Function nEditNumber(
  2199. win : pwindow;
  2200. x,y,att,wid,decm : integer;
  2201. bgd : string;
  2202. initv,
  2203. minv,
  2204. maxv : longint;
  2205. var esc : boolean) : longint;
  2206. Var
  2207. r : real;
  2208. Begin
  2209. r := nEditNumber(win,x,y,att,wid,0,bgd,Real(initv),Real(minv),Real(maxv),esc);
  2210. nEditNumber := Trunc(r);
  2211. End;
  2212. { overload - longint, no pointer }
  2213. Function nEditNumber(
  2214. x,y,att,wid,decm : integer;
  2215. bgd : string;
  2216. initv,
  2217. minv,
  2218. maxv : longint;
  2219. var esc : boolean) : longint;
  2220. Var
  2221. r : real;
  2222. Begin
  2223. r := nEditNumber(ActiveWn,x,y,att,wid,0,bgd,Real(initv),Real(minv),Real(maxv),esc);
  2224. nEditNumber := Trunc(r);
  2225. End;
  2226. { More sugar for Rainer }
  2227. {------------------------------------------------------------------------
  2228. A date string editor.
  2229. ------------------------------------------------------------------------}
  2230. Function nEditDate(
  2231. win : pwindow;
  2232. x, { edit field start column }
  2233. y, { edit field start row }
  2234. att : integer; { edit field color attribute }
  2235. initv : string; { initial value }
  2236. var esc : boolean { if Esc key pressed = true, else = false }
  2237. ) : string;
  2238. Var
  2239. s : string;
  2240. i : integer;
  2241. ch : char;
  2242. tmp_ec : tnEC;
  2243. Begin
  2244. tmp_ec := nEC;
  2245. nEC.InsMode := false;
  2246. nEC.ClearMode := false;
  2247. nEC.ExitMode := false;
  2248. nEC.AppendMode := false;
  2249. Case nDecFmt of
  2250. nUS : Begin
  2251. nEC.Picture := '{#,m,M}{#,m,M}/{#,d,D}{#,d,D}/{#,y,Y}{#,y,Y}{#,y,Y}{#,y,Y}';
  2252. s := 'mm/dd/yyyy';
  2253. End;
  2254. nEURO : Begin
  2255. nEC.Picture := '{#,d,D}{#,d,D}/{#,m,M}{#,m,M}/{#,y,Y}{#,y,Y}{#,y,Y}{#,y,Y}';
  2256. s := 'dd/mm/yyyy';
  2257. End;
  2258. End;
  2259. If nCheckPxPicture(initv,nEC.Picture,i) <> 0 Then
  2260. system.move(initv[1],s[1],Length(initv));
  2261. nEC.AddChMap(#7#0#0+Char(nKeyLeft));
  2262. nEC.AddChMap(#8#0#0+Char(nKeyLeft));
  2263. nEC.AddChMap(#0+Char(nKeyDel)+#0+Char(nKeyLeft));
  2264. Repeat
  2265. s := nEdit(win,x,y,att,x+9,x,s,ch);
  2266. If ch = #13 Then Begin
  2267. For i := 1 to Length(s) Do
  2268. If s[i] in ['m','d','y'] Then ch := #0;
  2269. End;
  2270. Until ch in [#13,#27];
  2271. esc := (ch = #27);
  2272. nEditDate := s;
  2273. nEC := tmp_ec;
  2274. End;
  2275. { overload - no pointer }
  2276. Function nEditDate(x,y,att : integer;initv : string;var esc : boolean) : string;
  2277. Begin
  2278. nEditDate := nEditDate(ActiveWn,x,y,att,initv,esc);
  2279. End;
  2280. { A one-line procedural wrapper }
  2281. Procedure nMakeWindow(
  2282. var win : tnWindow;
  2283. x1,y1,
  2284. x2,y2,
  2285. ta,ba,ha : integer;
  2286. hasframe : boolean;
  2287. hdrpos : tnJustify;
  2288. hdrtxt : string);
  2289. Begin
  2290. win.init(x1,y1,x2,y2,ta,hasframe,ba);
  2291. If hdrtxt <> '' Then win.PutHeader(hdrtxt,ha,hdrpos);
  2292. End;
  2293. { And with a window pointer }
  2294. Procedure nMakeWindow(
  2295. var win : pnWindow;
  2296. x1,y1,
  2297. x2,y2,
  2298. ta,ba,ha : integer;
  2299. hasframe : boolean;
  2300. hdrpos : tnJustify;
  2301. hdrtxt : string);
  2302. Begin
  2303. New(win,init(x1,y1,x2,y2,ta,hasframe,ba));
  2304. If hdrtxt <> '' Then win^.PutHeader(hdrtxt,ha,hdrpos);
  2305. End;
  2306. {--------------------------------------------------------------------
  2307. Display a message in a centered and framed box. With ack set to
  2308. false, the window remains active for further use in the program.
  2309. Inputs:
  2310. msg = message to display
  2311. matt = message color
  2312. hdr = header text at frame top
  2313. hatt = header/frame color
  2314. ack = TRUE : display ftr text and wait for a keypress, then
  2315. remove the window.
  2316. FALSE: don't display ftr, don't wait for a keypress, and
  2317. don't remove the window.
  2318. Output:
  2319. a nil pointer if ack = true,
  2320. a pointer to the tnWindow object if ack = false
  2321. --------------------------------------------------------------------}
  2322. Function nShowMessage(msg : string;
  2323. matt : byte;
  2324. hdr : string;
  2325. hatt : byte;
  2326. ack : boolean) : pnWindow;
  2327. const
  2328. ftr = 'Press Any Key';
  2329. acklns : shortint = 0;
  2330. var
  2331. i,j,
  2332. cr,
  2333. wid,
  2334. maxwid,
  2335. lines : integer;
  2336. mwin : pnWindow;
  2337. Begin
  2338. wid := 0;
  2339. maxwid := Length(hdr);
  2340. If ack and (Length(ftr) > maxwid) Then
  2341. maxwid := Length(ftr);
  2342. lines := 1;
  2343. { how many rows does this window need ? }
  2344. For i := 1 to Length(msg) Do Begin
  2345. inc(wid);
  2346. { let's be consistant! }
  2347. If msg[i] = #13 Then msg[i] := #10;
  2348. { either a forced line break or we need to word-wrap }
  2349. If (msg[i] = #10) or (wid >= (MaxCols-2)) Then Begin
  2350. inc(lines);
  2351. j := 0;
  2352. If not (msg[i] in [#10,#32]) Then Begin
  2353. { we're in a word, so find the previous space (if any) }
  2354. Repeat
  2355. inc(j);
  2356. Until (j=wid) or ((i-j) <= 0) or (msg[i-j] = #32);
  2357. If ((i-j) > 0) and (msg[i-j] = #32) Then Begin
  2358. wid := wid-j;
  2359. msg[i-j] := #10 { force a line break }
  2360. End Else
  2361. j := 0;
  2362. End;
  2363. If wid > maxwid Then maxwid := wid;
  2364. wid := j; { either 0 or word-wrap remnent }
  2365. End;
  2366. End;
  2367. If wid > maxwid Then maxwid := wid;
  2368. If ack Then acklns := 1 else acklns := 0;
  2369. { make the message window }
  2370. New(mwin,Init(1,1,maxwid+2,lines+acklns+2,matt,true,hatt));
  2371. With mwin^ Do Begin
  2372. PutHeader(hdr,hatt,center);
  2373. Align(center,center);
  2374. If lines = 1 Then
  2375. { one-liners get centered }
  2376. Write(msg:Length(msg)+((maxwid-Length(msg)) div 2))
  2377. Else
  2378. Write(msg);
  2379. Show;
  2380. If ack Then Begin
  2381. cr := nCursor(cOff);
  2382. FWrite(((cols-Length(ftr)) div 2)+1,rows,matt,0,ftr);
  2383. {
  2384. The following line can be used in place of the line above to place the
  2385. footer text in the frame instead of with the message body. Make sure to
  2386. keep acklns=0.
  2387. nFWrite(win,((ncols(win)-Length(ftr)) div 2)+1,nrows(win),hatt,0,ftr);
  2388. }
  2389. Readkey;
  2390. While Keypressed Do Readkey;
  2391. Hide;
  2392. nCursor(cr);
  2393. End;
  2394. End;
  2395. If ack Then Begin
  2396. Dispose(mwin,Done);
  2397. mwin := nil;
  2398. End;
  2399. nShowMessage := mwin;
  2400. End;
  2401. {---------------------------------------
  2402. Read a character string from a window
  2403. win - window to extract info from.
  2404. x - starting column.
  2405. y - starting row.
  2406. n - number of characters to read.
  2407. ---------------------------------------}
  2408. Function nReadScr(win : pWindow; x,y,n : integer) : string;
  2409. Var
  2410. i,idx : integer;
  2411. s : string;
  2412. c : longint;
  2413. { array of char/attr values, 4 bytes each, max 256 }
  2414. buf : array[0..1023] of char;
  2415. p : pchar;
  2416. Begin
  2417. s := '';
  2418. p := nReadScrStr(win,x,y,n,buf);
  2419. If p <> nil Then Begin
  2420. idx := 0;
  2421. For i := 1 to n Do Begin
  2422. system.move(buf[idx],c,SizeOf(c));
  2423. s := s + chr(c and A_CHARTEXT);
  2424. inc(idx,SizeOf(c));
  2425. End;
  2426. End;
  2427. nReadScr := s;
  2428. End;
  2429. { overload for current window }
  2430. Function nReadScr(x,y,n : integer) : string;
  2431. Begin
  2432. nReadScr := nReadScr(ActiveWn,x,y,n);
  2433. End;
  2434. Function nReadScrStr(win : pWindow; x,y,n : integer; buf : pchtype) : pchtype;
  2435. Var
  2436. cx,cy : integer;
  2437. mx,my : longint;
  2438. Begin
  2439. cx := nWhereX(win);
  2440. cy := nWhereY(win);
  2441. If win <> nil Then Begin
  2442. getmaxyx(win,my,mx);
  2443. If (x in [1..mx]) and (y in [1..my]) Then Begin
  2444. { n is contrained to the right margin, so no need to range check }
  2445. mvwinchnstr(win,y-1,x-1,buf,n);
  2446. nGotoXY(win,cx,cy);
  2447. End;
  2448. End;
  2449. nReadScrStr := buf;
  2450. End;
  2451. { overload for current window }
  2452. Function nReadScrStr(x,y,n : integer; buf : pchtype) : pchtype;
  2453. Begin
  2454. nReadScrStr := nReadScrStr(ActiveWn,x,y,n,buf);
  2455. End;
  2456. Function nReadScrColor(win : pWindow; x,y : integer) : integer;
  2457. Var
  2458. cl,
  2459. fg,bg,
  2460. cx,cy : integer;
  2461. c,cv,
  2462. mx,my : longint;
  2463. Begin
  2464. cl := -1;
  2465. cx := nWhereX(win);
  2466. cy := nWhereY(win);
  2467. If win <> nil Then Begin
  2468. getmaxyx(win,my,mx);
  2469. If (x in [1..mx]) and (y in [1..my]) Then Begin
  2470. c := mvwinch(win,y-1,x-1);
  2471. nGotoXY(win,cx,cy);
  2472. cv := PAIR_NUMBER(c and A_COLOR);
  2473. pair_content(cv,@fg,@bg);
  2474. fg := c2ibm(fg);
  2475. bg := c2ibm(bg);
  2476. cv := (c and A_ATTRIBUTES);
  2477. If A_BOLD and cv = A_BOLD Then inc(fg,8);
  2478. cl := (bg*16)+fg;
  2479. End;
  2480. End;
  2481. nReadScrColor := cl;
  2482. End;
  2483. { overload for current window }
  2484. Function nReadScrColor(x,y : integer) : integer;
  2485. Begin
  2486. nReadScrColor := nReadScrColor(ActiveWn,x,y);
  2487. End;
  2488. { write a string with attributes, previously saved with nReadScrStr }
  2489. Procedure nWriteScrStr(win : pWindow; x,y : integer; s : pchtype);
  2490. Begin
  2491. mvwaddchstr(win,y-1,x-1,s);
  2492. If doRefresh Then wrefresh(win);
  2493. End;
  2494. { overload for current window }
  2495. Procedure nWriteScrStr(x,y : integer; s : pchtype);
  2496. Begin
  2497. mvwaddchstr(ActiveWn,y-1,x-1,s);
  2498. If doRefresh Then wrefresh(ActiveWn);
  2499. End;
  2500. {---------------------------------------
  2501. save a rectangular portion of a window
  2502. x = start column
  2503. y = start row
  2504. c = number of columns
  2505. r = number of rows
  2506. ---------------------------------------}
  2507. Procedure nGrabScreen(var p : pnScreenBuf; x,y,c,r : integer; win : pWindow);
  2508. Var
  2509. mx,my : longint;
  2510. i,
  2511. cx,cy : integer;
  2512. prb,trb : pnRowBuf;
  2513. Begin
  2514. nReleaseScreen(p);
  2515. getmaxyx(win,my,mx);
  2516. If not (x in [1..mx]) or Not (y in [1..my]) Then Begin
  2517. p := nil;
  2518. Exit;
  2519. End;
  2520. cx := nWhereX(win);
  2521. cy := nWhereY(win);
  2522. New(p);
  2523. p^.x := x;
  2524. p^.y := y;
  2525. p^.n := c;
  2526. p^.first := nil;
  2527. trb := nil;
  2528. For i := 0 to r-1 Do Begin
  2529. If (y+i in [1..my]) Then Begin
  2530. New(prb);
  2531. GetMem(prb^.row,c*SizeOf(chtype));
  2532. mvwinchnstr(win,y-1+i,x-1,prb^.row,c);
  2533. If trb <> nil Then trb^.Next := prb;
  2534. prb^.next := nil;
  2535. trb := prb;
  2536. If i = 0 Then p^.First := prb;
  2537. End;
  2538. End;
  2539. nGotoXY(win,cx,cy);
  2540. End;
  2541. { overload for current window }
  2542. Procedure nGrabScreen(var p : pnScreenBuf; x,y,c,r : integer);
  2543. Begin
  2544. nGrabScreen(p,x,y,c,r,ActiveWn);
  2545. End;
  2546. { overload for current full window }
  2547. Procedure nGrabScreen(var p : pnScreenBuf);
  2548. Var
  2549. c,r : longint;
  2550. Begin
  2551. getmaxyx(ActiveWn,r,c);
  2552. nGrabScreen(p,1,1,c,r,ActiveWn);
  2553. End;
  2554. {-----------------------------------------
  2555. restore a window saved with nGrabScreen
  2556. p = pointer to the saved buffer
  2557. x = start restore to this column
  2558. y = start restore to this row
  2559. win = restore to this window
  2560. -----------------------------------------}
  2561. Procedure nPopScreen(p : pnScreenBuf; x,y : integer; win : pWindow);
  2562. Var
  2563. cx,cy : integer;
  2564. mx,my : longint;
  2565. pb : pnRowBuf;
  2566. Begin
  2567. If p = nil Then Exit;
  2568. getmaxyx(win,my,mx);
  2569. If Not (x in [1..mx]) or Not (y in [1..my]) Then Exit;
  2570. dec(x);
  2571. cx := nWhereX(win);
  2572. cy := nWhereY(win);
  2573. pb := p^.First;
  2574. While pb <> nil Do Begin
  2575. If (pb^.row <> nil) and (y in [1..my]) Then
  2576. mvwaddchnstr(win,y-1,x,pb^.row,p^.n);
  2577. inc(y);
  2578. pb := pb^.next;
  2579. End;
  2580. nGotoXY(win,cx,cy);
  2581. If doRefresh Then wrefresh(win);
  2582. End;
  2583. { overload for current window, defined position }
  2584. Procedure nPopScreen(p : pnScreenBuf; x,y : integer);
  2585. Begin
  2586. nPopScreen(p,x,y,ActiveWn);
  2587. End;
  2588. { overload for current window, saved position }
  2589. Procedure nPopScreen(p : pnScreenBuf);
  2590. Begin
  2591. If p = nil Then Exit;
  2592. nPopScreen(p,p^.x,p^.y,ActiveWn);
  2593. End;
  2594. { free up the memory used to store a grabbed screen }
  2595. Procedure nReleaseScreen(p : pnScreenBuf);
  2596. Var
  2597. cur,tmp : pnRowBuf;
  2598. Begin
  2599. If p = nil Then Exit;
  2600. If p^.first <> nil Then Begin
  2601. cur := p^.first;
  2602. While cur <> nil Do Begin
  2603. tmp := cur^.next;
  2604. If cur^.row <> nil Then FreeMem(cur^.row,p^.n * SizeOf(chtype));
  2605. Dispose(cur);
  2606. cur := tmp;
  2607. End;
  2608. End;
  2609. Dispose(p);
  2610. End;
  2611. {============================== tnMenu ====================================}
  2612. { A one-line procedural wrapper }
  2613. Procedure nMakeMenu(
  2614. var mnu : tnMenu;
  2615. x,y,
  2616. _w,_r,_c,
  2617. ta,ca,ga,ba,ha : integer;
  2618. hasframe : boolean;
  2619. hdrpos : tnJustify;
  2620. hdrtxt : string);
  2621. Begin
  2622. mnu.init(x,y,_w,_r,_c,ta,ca,ga,hasframe,ba);
  2623. If hdrtxt <> '' Then mnu.PutHeader(hdrtxt,ha,hdrpos);
  2624. End;
  2625. { And with a menu pointer }
  2626. Procedure nMakeMenu(
  2627. var mnu : pnMenu;
  2628. x,y,
  2629. _w,_r,_c,
  2630. ta,ca,ga,ba,ha : integer;
  2631. hasframe : boolean;
  2632. hdrpos : tnJustify;
  2633. hdrtxt : string);
  2634. Begin
  2635. New(mnu,init(x,y,_w,_r,_c,ta,ca,ga,hasframe,ba));
  2636. If hdrtxt <> '' Then mnu^.PutHeader(hdrtxt,ha,hdrpos);
  2637. End;
  2638. Constructor tnMenu.Init(_x,_y,_w,_r,_c,_tc,_cc,_gc : integer;
  2639. _fr : boolean; _fc : integer);
  2640. Begin
  2641. x := _x;
  2642. y := _y;
  2643. wid := _w;
  2644. r := _r;
  2645. c := _c;
  2646. tc := _tc;
  2647. cc := _cc;
  2648. gc := _gc;
  2649. framed := _fr;
  2650. fc := _fc;
  2651. hc := fc;
  2652. iidx := 0;
  2653. mark := '';
  2654. posted := false;
  2655. If wid > MaxCols Then wid := MaxCols;
  2656. InitWin;
  2657. Spin(false);
  2658. End;
  2659. Destructor tnMenu.Done;
  2660. Begin
  2661. UnPost;
  2662. Clear;
  2663. Dispose(win,Done);
  2664. End;
  2665. Procedure tnMenu.InitWin;
  2666. Const
  2667. xhgt : shortint = 0;
  2668. Begin
  2669. If framed Then xhgt := 2 Else xhgt := 0;
  2670. New(win,Init(x,y,(x+wid-1),(y+r+xhgt-1),tc,framed,fc));
  2671. End;
  2672. Procedure tnMenu.Post;
  2673. Var
  2674. bx,by,
  2675. mx,my : longint;
  2676. p : pchar;
  2677. a : array[0..SizeOf(tnS10)-1] of char;
  2678. Begin
  2679. { could already be posted }
  2680. UnPost;
  2681. { see if the window size has changed (a new longer item added?) }
  2682. getmaxyx(win^.win,my,mx);
  2683. If (wid <> mx) Then Begin
  2684. getbegyx(win^.win,by,bx);
  2685. Dispose(win,Done);
  2686. x := bx+1;
  2687. y := by+1;
  2688. InitWin;
  2689. End;
  2690. { create the new menu }
  2691. pm := new_menu(@pi);
  2692. { only show item text }
  2693. menu_opts_off(pm,O_SHOWDESC);
  2694. { bind the windows }
  2695. set_menu_win(pm,win^.win);
  2696. set_menu_sub(pm,win^.wn);
  2697. { set the rows and columns }
  2698. set_menu_format(pm,r,c);
  2699. { set the colors }
  2700. set_menu_fore(pm,CursesAtts(cc));
  2701. set_menu_back(pm,CursesAtts(tc));
  2702. set_menu_grey(pm,CursesAtts(gc));
  2703. p := StrPCopy(a,mark);
  2704. set_menu_mark(pm,p);
  2705. merr := post_menu(pm);
  2706. posted := (merr = E_OK);
  2707. Spin(loopon);
  2708. End;
  2709. Procedure tnMenu.UnPost;
  2710. Begin
  2711. merr := unpost_menu(pm);
  2712. merr := free_menu(pm);
  2713. pm := nil;
  2714. posted := false;
  2715. End;
  2716. Procedure tnMenu.Show;
  2717. Begin
  2718. If not posted Then Post;
  2719. win^.Show;
  2720. End;
  2721. { Start user interaction loop }
  2722. Procedure tnMenu.Start;
  2723. Const
  2724. select = #13;
  2725. cancel = #27;
  2726. Var
  2727. key : char;
  2728. i,cnt,
  2729. prev,
  2730. savecurs,
  2731. xkey : integer;
  2732. direction : longint;
  2733. Begin
  2734. Show;
  2735. iidx := 0;
  2736. savecurs := nCursor(cOFF);
  2737. Repeat
  2738. prev := iidx;
  2739. win^.Show;
  2740. key := readkey;
  2741. xkey := 0;
  2742. case key of
  2743. #0 : xkey := ord(readkey);
  2744. ^F : xkey := nKeyHome;
  2745. ^L : xkey := nKeyEnd;
  2746. #9,
  2747. ^N : xkey := nKeyDown;
  2748. ^P : xkey := nKeyUp;
  2749. else menu_driver(pm,ord(key));
  2750. end;
  2751. case xkey of
  2752. nKeyHome : menu_driver(pm,REQ_FIRST_ITEM);
  2753. nKeyEnd : menu_driver(pm,REQ_LAST_ITEM);
  2754. nKeyRight,
  2755. nKeyDown : menu_driver(pm,REQ_NEXT_ITEM);
  2756. nKeyLeft,
  2757. nKeyUp : menu_driver(pm,REQ_PREV_ITEM);
  2758. end;
  2759. iidx := item_index(current_item(pm)) + 1;
  2760. If (not Selectable(iidx)) and (key <> cancel) Then Begin
  2761. cnt := Count;
  2762. If cnt > 1 Then Begin
  2763. { temporarily enable spinning }
  2764. If not loopon Then
  2765. menu_opts_off(pm,O_NONCYCLIC);
  2766. { which way to another item? }
  2767. If iidx > prev Then
  2768. direction := REQ_NEXT_ITEM
  2769. Else
  2770. direction := REQ_PREV_ITEM;
  2771. Repeat
  2772. menu_driver(pm,direction);
  2773. i := item_index(current_item(pm)) + 1;
  2774. Until Selectable(i) or (i = iidx);
  2775. { reset spin }
  2776. Spin(loopon);
  2777. { keep prev honest }
  2778. iidx := item_index(current_item(pm)) + 1;
  2779. End;
  2780. End;
  2781. Until key in [select,cancel];
  2782. menu_driver(pm,REQ_CLEAR_PATTERN);
  2783. If iidx = ERR Then merr := iidx;
  2784. If key = cancel Then iidx := 0;
  2785. nCursor(savecurs);
  2786. End;
  2787. Procedure tnMenu.Stop;
  2788. Begin
  2789. Hide;
  2790. UnPost;
  2791. End;
  2792. Procedure tnMenu.Hide;
  2793. Begin
  2794. win^.Hide;
  2795. End;
  2796. Function tnMenu.Wind : pnWindow;
  2797. Begin
  2798. Wind := win;
  2799. End;
  2800. Procedure tnMenu.Align(hpos,vpos : tnJustify);
  2801. Begin
  2802. win^.Align(hpos,vpos);
  2803. End;
  2804. Procedure tnMenu.Move(_x,_y : integer);
  2805. Begin
  2806. win^.Move(_x,_y);
  2807. End;
  2808. Procedure tnMenu.PutHeader(hdr : string; hcolor : integer; hpos : tnJustify);
  2809. Begin
  2810. win^.PutHeader(hdr,hcolor,hpos);
  2811. End;
  2812. Procedure tnMenu.Clear;
  2813. Var
  2814. i : integer;
  2815. Begin
  2816. UnPost;
  2817. For i := 1 to nMAXMENUITEMS Do ClearItem(i);
  2818. End;
  2819. { is this menu item selectable }
  2820. Function tnMenu.Selectable(idx : integer) : boolean;
  2821. Begin
  2822. Selectable := IsAssigned(idx) and
  2823. ((O_SELECTABLE and item_opts(pi[idx])) = O_SELECTABLE);
  2824. End;
  2825. Function tnMenu.IsValid(idx : integer) : boolean;
  2826. Begin
  2827. IsValid := ((idx >= 1) and (idx <= nMAXMENUITEMS));
  2828. End;
  2829. Function tnMenu.IsAssigned(idx : integer) : boolean;
  2830. Begin
  2831. IsAssigned := IsValid(idx) and (pi[idx] <> nil);
  2832. End;
  2833. Procedure tnMenu.ClearItem(idx : integer);
  2834. Begin
  2835. If IsValid(idx) Then Begin
  2836. If items[idx] <> nil Then Begin
  2837. merr := free_item(pi[idx]);
  2838. If merr = E_OK Then Begin
  2839. FreeMem(items[idx],StrLen(items[idx]^)+1);
  2840. pi[idx] := nil;
  2841. items[idx] := nil;
  2842. End;
  2843. End;
  2844. End Else merr := E_BAD_ARGUMENT;
  2845. End;
  2846. Procedure tnMenu.AddItem(i : integer; s : string);
  2847. Const
  2848. fwid : shortint = 0;
  2849. iwid : shortint = 1;
  2850. Var
  2851. rl : integer;
  2852. sp1,sp2,sp3 : plongint;
  2853. Begin
  2854. If IsValid(i) Then Begin
  2855. sp1:=nil; sp2:=nil; sp3:=nil;
  2856. ClearItem(i);
  2857. GetMem(items[i],Length(s)+1);
  2858. StrPCopy(items[i]^,s);
  2859. pi[i] := new_item(pchar(items[i]),nil);
  2860. If pi[i] <> Nil Then Begin
  2861. merr := E_OK;
  2862. { Expand the window width if necessary. Limit to screen width.
  2863. Add possibly 2 for the frame, the item indicator length, and
  2864. the item spacing value. }
  2865. If framed Then fwid := 2;
  2866. if c > 1 Then Begin
  2867. If posted Then Begin
  2868. { need a valid pm }
  2869. menu_spacing(pm,sp1,sp2,sp3);
  2870. iwid := Length(GetMark) + sp3^;
  2871. End Else
  2872. iwid := Length(GetMark) + 1;
  2873. End Else
  2874. iwid := 0;
  2875. { required length }
  2876. rl := ((Length(s)+iwid)*c)+fwid;
  2877. { expand? }
  2878. If rl > wid Then wid := rl;
  2879. If wid > MaxCols Then wid := MaxCols;
  2880. End Else merr := E_REQUEST_DENIED;
  2881. End Else merr := E_BAD_ARGUMENT;
  2882. End;
  2883. Function tnMenu.Add(s : string) : integer;
  2884. Var
  2885. i : integer;
  2886. Begin
  2887. i := 0;
  2888. Add := 0;
  2889. Repeat
  2890. inc(i);
  2891. Until (i > nMAXMENUITEMS) or (items[i] = nil);
  2892. AddItem(i,s);
  2893. If merr = E_OK Then Add := i;
  2894. End;
  2895. Procedure tnMenu.Insert(idx : integer; s : string);
  2896. Begin
  2897. If IsValid(idx) Then Begin
  2898. ClearItem(nMAXMENUITEMS);
  2899. If idx < nMAXMENUITEMS Then Begin
  2900. { shift the pointer list up and keep lists syncronized }
  2901. system.Move(pi[idx],pi[idx+1],SizeOf(pnMenuStr)*(nMAXMENUITEMS-idx));
  2902. system.Move(items[idx],items[idx+1],SizeOf(pItem)*(nMAXMENUITEMS-idx));
  2903. pi[idx] := nil;
  2904. items[idx] := nil;
  2905. End;
  2906. AddItem(idx,s);
  2907. End Else merr := E_BAD_ARGUMENT;
  2908. End;
  2909. Procedure tnMenu.Remove(idx : integer);
  2910. Begin
  2911. If IsValid(idx) Then Begin
  2912. ClearItem(idx);
  2913. { shift the pointer list down and keep lists syncronized }
  2914. system.Move(pi[idx+1],pi[idx],SizeOf(pnMenuStr)*(nMAXMENUITEMS-idx));
  2915. system.Move(items[idx+1],items[idx],SizeOf(pItem)*(nMAXMENUITEMS-idx));
  2916. pi[nMAXMENUITEMS] := nil;
  2917. items[nMAXMENUITEMS] := nil;
  2918. End Else merr := E_BAD_ARGUMENT;
  2919. End;
  2920. Procedure tnMenu.Change(idx : integer; s : string);
  2921. Begin
  2922. AddItem(idx,s);
  2923. End;
  2924. { toggle a menu item's selectability }
  2925. Procedure tnMenu.Active(idx : integer; b : boolean);
  2926. Begin
  2927. Case b of
  2928. true : item_opts_on(pi[idx],O_SELECTABLE);
  2929. false : item_opts_off(pi[idx],O_SELECTABLE);
  2930. End;
  2931. End;
  2932. { is the item selectable? }
  2933. Function tnMenu.IsActive(idx : integer) : boolean;
  2934. Begin
  2935. IsActive := Selectable(idx);
  2936. End;
  2937. { Toggle item looping. Moves to first/last when bottom/top is reached }
  2938. Procedure tnMenu.Spin(b : boolean);
  2939. Begin
  2940. loopon := b;
  2941. If posted Then
  2942. Case b of
  2943. true : menu_opts_off(pm,O_NONCYCLIC);
  2944. false : menu_opts_on(pm,O_NONCYCLIC);
  2945. End;
  2946. End;
  2947. { return most recent error status }
  2948. Function tnMenu.Status : integer;
  2949. Begin
  2950. Status := merr;
  2951. End;
  2952. Function tnMenu.Index : integer;
  2953. Begin
  2954. Index := iidx;
  2955. End;
  2956. Procedure tnMenu.SetIndex(idx : integer);
  2957. Begin
  2958. If IsValid(idx) and IsAssigned(idx) and Selectable(idx) Then Begin
  2959. set_current_item(pm,pi[idx]);
  2960. iidx := idx;
  2961. End;
  2962. End;
  2963. Function tnMenu.Count : integer;
  2964. Begin
  2965. Count := item_count(pm);
  2966. End;
  2967. Function tnMenu.Rows(_r : integer) : integer;
  2968. Begin
  2969. Rows := r;
  2970. If _r > 0 Then r := _r;
  2971. End;
  2972. Function tnMenu.Cols(_c : integer) : integer;
  2973. Begin
  2974. Cols := c;
  2975. If _c > 0 Then c := _c;
  2976. End;
  2977. { get the item indicator prefix string }
  2978. Function tnMenu.GetMark : string;
  2979. Begin
  2980. If posted Then
  2981. GetMark := StrPas(menu_mark(pm))
  2982. Else
  2983. GetMark := mark;
  2984. End;
  2985. { set the item indicator prefix string }
  2986. Procedure tnMenu.SetMark(ms : string);
  2987. Begin
  2988. mark := ms;
  2989. End;
  2990. Procedure tnMenu.Refresh;
  2991. Begin
  2992. Post;
  2993. Show;
  2994. End;
  2995. Procedure tnMenu.SetColor(att : byte);
  2996. Begin
  2997. tc := att;
  2998. If posted Then set_menu_back(pm,CursesAtts(tc));
  2999. End;
  3000. Procedure tnMenu.SetCursorColor(att : byte);
  3001. Begin
  3002. cc := att;
  3003. If posted Then set_menu_fore(pm,CursesAtts(cc));
  3004. End;
  3005. Procedure tnMenu.SetFrameColor(att : byte);
  3006. Begin
  3007. fc := att;
  3008. If posted Then Wind^.PutFrame(att);
  3009. End;
  3010. Procedure tnMenu.SetGrayColor(att : byte);
  3011. Begin
  3012. gc := att;
  3013. If posted Then set_menu_grey(pm,CursesAtts(gc));
  3014. End;
  3015. {----------------------- initialize the unit!------------------------- }
  3016. Begin
  3017. FillChar(_chmap,SizeOf(_chmap),0);
  3018. nEC.Init(false,false,false,false,false,'','',15,_chmap);
  3019. { load the color pairs array with color pair indices (0..63) }
  3020. For bg := 0 to 7 Do For fg := 0 to 7 do cp[bg,fg] := (bg*8)+fg;
  3021. { initialize ncurses }
  3022. If StartCurses(ActiveWn) Then Begin
  3023. { save pointer to ncurses stdscr }
  3024. nscreen := ActiveWn;
  3025. { defaults, crtassign, etc. }
  3026. nInit;
  3027. { create the default full screen, non-bordered window object }
  3028. nStdScr.Init(1,1,MaxCols,MaxRows,7,false,0);
  3029. { default read/write to stdscr }
  3030. ActiveWn := nscreen;
  3031. End Else Begin
  3032. CursesFailed;
  3033. End;
  3034. End. { of Unit oCrt }