ocrt.pp 94 KB

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