ocrt.pp 94 KB

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