ocrt.pp 94 KB

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