ocrt.pp 93 KB

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