ocrt.pp 93 KB

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