WMTextView.Mod 145 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417
  1. MODULE WMTextView; (** AUTHOR "TF"; PURPOSE "Generic unicode text viewer"; *)
  2. IMPORT
  3. Kernel, Modules, Inputs, KernelLog, XML, Texts, TextUtilities, SyntaxHighlighter,
  4. WMGraphics, WMGraphicUtilities, WMMessages, WMComponents,
  5. WMStandardComponents, Strings, WMDropTarget, Raster,
  6. WMRectangles, WMWindowManager, WMProperties,
  7. Commands, FileHandlers, Streams, WMPopups, FP1616,
  8. WMPieMenu, WMEvents, UnicodeBidirectionality, PositionDebugging, ContextualDependency, D := Debugging;
  9. CONST
  10. TraceRenderOptimize = 0;
  11. TraceLayout = 1;
  12. TraceBaseLine = 2;
  13. TraceInvalidate = 3;
  14. TraceCopy = 4;
  15. TraceCommands = 5;
  16. Trace = {};
  17. (* When pressing the middle mouse button and holding down ALT, execute this command with
  18. the actual command and its parameters as parameter *)
  19. AltMMCommand = "WMUtilities.Call";
  20. CallURLPointer = 0; (* mousebutton which will invoke the URL *)
  21. (** Text wrapping modes (default = WrapWord) *)
  22. NoWrap* = 0; Wrap* = 1; WrapWord* = 2;
  23. AlignLeft = 0; AlignCenter = 1; AlignRight = 2;
  24. DragDist = 5;
  25. MaxCallParameterBuf = 1 * 1024 * 1024;
  26. MaxCommandLength = 256; (* without parameters *)
  27. (* If TRUE, a mouse right click will open a pie menu *)
  28. UsePieMenu = TRUE;
  29. InterclickNone = 0;
  30. Interclick01 = 1; (* mouse button 0 & 1 *)
  31. Interclick02 = 2; (* mouse button 0 & 2 *)
  32. InterclickCancelled = 99;
  33. SelectionColor = 0000FF60H;
  34. SelectionColorInterclick01 = LONGINT(0FFFF0060H);
  35. SelectionColorInterclick02 = LONGINT(0FF000060H);
  36. TYPE
  37. Char32 = Texts.Char32;
  38. ClickInfo = OBJECT
  39. VAR
  40. cmd, cmdPar : Strings.String;
  41. END ClickInfo;
  42. TabStops* = OBJECT
  43. VAR tabDist : LONGINT;
  44. (* return the next TabStop from the x position *)
  45. PROCEDURE GetNextTabStop*(x : LONGINT) : LONGINT;
  46. BEGIN
  47. RETURN ((x DIV tabDist) + 1) * tabDist
  48. END GetNextTabStop;
  49. END TabStops;
  50. TabPositions* = POINTER TO ARRAY OF LONGINT;
  51. CustomTabStops* = OBJECT (TabStops)
  52. VAR
  53. positions : TabPositions;
  54. PROCEDURE GetNextTabStop*(x : LONGINT) : LONGINT;
  55. VAR
  56. idx : LONGINT;
  57. BEGIN
  58. idx := 0;
  59. ASSERT(positions # NIL);
  60. IF x >= positions[LEN(positions) - 1] THEN RETURN GetNextTabStop^(x) END; (* return default tab stop *)
  61. WHILE x >= positions[idx] DO INC(idx) END;
  62. RETURN positions[idx]
  63. END GetNextTabStop;
  64. PROCEDURE &New *(tp : TabPositions);
  65. VAR
  66. idx : LONGINT;
  67. BEGIN
  68. idx := 0; tabDist := 150;
  69. WHILE idx < LEN(tp)-1 DO ASSERT(tp[idx] <= tp[idx+1]); INC(idx) END;
  70. positions := tp
  71. END New;
  72. END CustomTabStops;
  73. LineInfo = RECORD
  74. leftIndent, rightIndent, firstIndent, spaceBefore, spaceAfter : LONGINT;
  75. firstInParagraph, lastInParagraph : BOOLEAN;
  76. height, width, ascent : LONGINT;
  77. pos : LONGINT; (* the position in the text, where this line starts *)
  78. align : LONGINT;
  79. tabStops : TabStops;
  80. END;
  81. LineInfoArray = POINTER TO ARRAY OF LineInfo;
  82. TYPE
  83. Layout = OBJECT
  84. VAR
  85. nofLines : LONGINT;
  86. lines : LineInfoArray;
  87. text : Texts.Text;
  88. paperWidth : LONGINT;
  89. textWidth : LONGINT; (* maximal width of the text <= textWidth *)
  90. textHeight : LONGINT;
  91. layoutLineProc : PROCEDURE {DELEGATE} (VAR pos : LONGINT; VAR ch : Char32; VAR lineInfo : LineInfo; wrapWidth, stopPos, stopXPos : LONGINT);
  92. bidiFormatter : UnicodeBidirectionality.BidiFormatter;
  93. initialized : BOOLEAN;
  94. PROCEDURE &New*;
  95. BEGIN
  96. NEW(lines, 4);
  97. (* this helps saving some bidi computations *)
  98. initialized := FALSE;
  99. END New;
  100. (** Replace the text *)
  101. PROCEDURE SetText(text : Texts.Text);
  102. BEGIN
  103. ASSERT(text # NIL);
  104. SELF.text := text;
  105. END SetText;
  106. PROCEDURE GrowLines;
  107. VAR i : LONGINT; newLines : LineInfoArray;
  108. BEGIN
  109. NEW(newLines, LEN(lines) * 2);
  110. FOR i := 0 TO LEN(lines) - 1 DO newLines[i] := lines[i] END;
  111. lines := newLines
  112. END GrowLines;
  113. (** find the linenumber by the position *)
  114. PROCEDURE FindLineNrByPos(pos : LONGINT) : LONGINT;
  115. VAR a, b, m : LONGINT;
  116. BEGIN
  117. a := 0; b := nofLines - 1;
  118. WHILE (a < b) DO m := (a + b) DIV 2;
  119. IF lines[m].pos <= pos THEN a := m + 1
  120. ELSE b := m
  121. END
  122. END;
  123. (* last line hack *)
  124. IF lines[a].pos <= pos THEN INC(a) END;
  125. RETURN a - 1
  126. END FindLineNrByPos;
  127. PROCEDURE GetLineStartPos(lineNr : LONGINT) : LONGINT;
  128. BEGIN
  129. IF (lineNr >= 0) & (lineNr < nofLines) THEN RETURN lines[lineNr].pos ELSE RETURN 0 END
  130. END GetLineStartPos;
  131. (** return the length in characters of this line *)
  132. PROCEDURE GetLineLength(lineNr : LONGINT) : LONGINT;
  133. BEGIN
  134. IF (lineNr >= 0) & (lineNr < nofLines - 1) THEN RETURN lines[lineNr + 1].pos - lines[lineNr].pos
  135. ELSE
  136. IF (lineNr >= 0) & (lineNr < nofLines) THEN RETURN text.GetLength() - lines[lineNr].pos + 1
  137. ELSE RETURN 0
  138. END
  139. END
  140. END GetLineLength;
  141. PROCEDURE GetNofLines() : LONGINT;
  142. BEGIN
  143. RETURN nofLines
  144. END GetNofLines;
  145. PROCEDURE LayoutLine(VAR pos : LONGINT; VAR lineInfo : LineInfo);
  146. VAR
  147. dummyCh : Char32;
  148. BEGIN
  149. IF layoutLineProc # NIL THEN layoutLineProc(pos, dummyCh, lineInfo, paperWidth, -1, -1) END
  150. END LayoutLine;
  151. (* generate a new layout from scratch. if the text has not actually changed, no bidi-reformatting needs to be done *)
  152. PROCEDURE FullLayout(textChanged : BOOLEAN);
  153. VAR i, pos, oldpos : LONGINT;
  154. BEGIN
  155. ASSERT((text # NIL) & (lines#NIL));
  156. text.AcquireRead;
  157. textWidth := 0;
  158. IF TraceLayout IN Trace THEN KernelLog.String("FullLayout"); KernelLog.Ln END;
  159. (* create a new bidiformatter and reformat the whole text if necessary *)
  160. IF textChanged & initialized & text.isUTF THEN
  161. NEW(bidiFormatter,text);
  162. bidiFormatter.ReformatText;
  163. END;
  164. i := 0;
  165. pos := 0; nofLines := 0; textHeight := 0;
  166. WHILE pos < text.GetLength() DO
  167. oldpos := pos;
  168. LayoutLine(pos, lines[nofLines]); INC(textHeight, lines[nofLines].height);
  169. textWidth := Strings.Max(textWidth, lines[nofLines].width);
  170. ASSERT(pos > oldpos);
  171. IF TraceLayout IN Trace THEN KernelLog.String("Line from : "); KernelLog.Int(lines[nofLines].pos, 5); KernelLog.Ln END;
  172. INC(nofLines); IF nofLines >= LEN(lines) THEN GrowLines END
  173. END;
  174. IF TraceLayout IN Trace THEN KernelLog.String("FullLayout found "); KernelLog.Int(nofLines, 4); KernelLog.String(" lines"); KernelLog.Ln END;
  175. text.ReleaseRead
  176. END FullLayout;
  177. (** Fix the layouting of the text starting at pos where delta characters have been inserted (delta negativ if deleted) *)
  178. PROCEDURE FixLayoutFrom(pos, delta : LONGINT; VAR first, last : LONGINT; VAR linesChanged : BOOLEAN);
  179. VAR l, dl, oldh : LONGINT;
  180. BEGIN
  181. ASSERT(text # NIL);
  182. text.AcquireRead;
  183. linesChanged := FALSE;
  184. l := FindLineNrByPos(pos);
  185. IF (l < 0) THEN FullLayout(TRUE); first := 0; last := nofLines; text.ReleaseRead; RETURN END;
  186. pos := lines[l].pos;
  187. oldh := lines[l].height;
  188. LayoutLine(pos, lines[l]);
  189. IF oldh # lines[l].height THEN linesChanged := TRUE END;
  190. first := l;
  191. INC(l); dl := 0;
  192. IF (delta < 0) THEN
  193. IF (l >= nofLines) OR (lines[l].pos + delta = pos) THEN
  194. last := l;
  195. WHILE (l < nofLines) DO lines[l].pos := lines[l].pos + delta; INC(l) END
  196. ELSE
  197. linesChanged := TRUE;
  198. WHILE (pos < text.GetLength()) DO
  199. DEC(textHeight, lines[l].height);
  200. LayoutLine(pos, lines[l]);
  201. textWidth := Strings.Max(textWidth, lines[l].width);
  202. INC(textHeight, lines[nofLines].height);
  203. INC(dl);
  204. IF TraceLayout IN Trace THEN KernelLog.String("Line from : "); KernelLog.Int(lines[nofLines].pos, 5); KernelLog.Ln END;
  205. INC(l);
  206. IF l >= LEN(lines) THEN GrowLines END
  207. END;
  208. nofLines := l ;
  209. last := nofLines - 1
  210. END
  211. ELSE
  212. WHILE (pos < text.GetLength()) & (lines[l].pos + delta # pos) DO
  213. linesChanged := TRUE;
  214. DEC(textHeight, (lines[l].height));
  215. LayoutLine(pos, lines[l]);
  216. textWidth := Strings.Max(textWidth, lines[l].width);
  217. INC(textHeight, (lines[nofLines].height));
  218. INC(dl);
  219. IF TraceLayout IN Trace THEN KernelLog.String("Line from : "); KernelLog.Int(lines[nofLines].pos, 5); KernelLog.Ln END;
  220. INC(l); IF l >= LEN(lines) THEN GrowLines END
  221. END;
  222. last := l;
  223. IF TraceLayout IN Trace THEN
  224. KernelLog.String("Delta Lines : "); KernelLog.Int(dl, 4); KernelLog.Ln;
  225. KernelLog.String("Lines to redraw : "); KernelLog.Int(first, 5); KernelLog.String(" to "); KernelLog.Int(last, 5); KernelLog.Ln
  226. END;
  227. (* fix up the positions *)
  228. IF l < nofLines THEN WHILE (l < nofLines) DO lines[l].pos := lines[l].pos + delta; INC(l) END
  229. ELSE nofLines := l
  230. END
  231. END;
  232. text.ReleaseRead
  233. END FixLayoutFrom;
  234. END Layout;
  235. CONST HLOver* = 0; HLUnder* = 1; HLWave* = 2;
  236. TYPE
  237. Highlight* = OBJECT
  238. VAR
  239. kind : LONGINT;
  240. from*, to* : Texts.TextPosition;
  241. a*, b* : LONGINT; (* only valid after sort, while holding the lock *)
  242. active* : BOOLEAN; (* only valid after sort, while holding the lock *)
  243. oldFrom, oldTo : LONGINT;
  244. oldColor, color : WMGraphics.Color;
  245. text : Texts.UnicodeText;
  246. onChanged : WMMessages.CompCommand;
  247. PROCEDURE &New*;
  248. BEGIN
  249. color := SelectionColor;
  250. oldColor := color;
  251. END New;
  252. PROCEDURE SetKind*(kind : LONGINT);
  253. BEGIN
  254. IF SELF.kind # kind THEN
  255. SELF.kind := kind;
  256. onChanged(SELF, NIL)
  257. END
  258. END SetKind;
  259. PROCEDURE SetColor*(color : WMGraphics.Color);
  260. BEGIN
  261. oldColor := SELF.color;
  262. IF SELF.color # color THEN
  263. SELF.color := color;
  264. onChanged(SELF, NIL)
  265. END
  266. END SetColor;
  267. PROCEDURE SetFrom*(from : LONGINT);
  268. BEGIN
  269. IF text = NIL THEN RETURN END; (* if no text is set, the position within is undef *)
  270. text.AcquireRead;
  271. oldFrom := SELF.from.GetPosition();
  272. IF oldFrom # from THEN
  273. SELF.from.SetPosition(from);
  274. onChanged(SELF, NIL)
  275. END;
  276. text.ReleaseRead
  277. END SetFrom;
  278. PROCEDURE SetTo*(to : LONGINT);
  279. BEGIN
  280. IF text = NIL THEN RETURN END; (* if no text is set, the position within is undef *)
  281. text.AcquireRead;
  282. oldTo := SELF.to.GetPosition();
  283. IF oldTo # to THEN
  284. SELF.to.SetPosition(to);
  285. onChanged(SELF, NIL)
  286. END;
  287. text.ReleaseRead
  288. END SetTo;
  289. PROCEDURE SetFromTo*(from, to : LONGINT);
  290. BEGIN
  291. IF text = NIL THEN RETURN END; (* if no text is set, the position within is undef *)
  292. text.AcquireRead;
  293. oldTo := SELF.to.GetPosition();
  294. oldFrom := SELF.from.GetPosition();
  295. IF (oldTo # to) OR (oldFrom # from) THEN
  296. IF ((oldTo = oldFrom) & (to = from)) THEN
  297. SELF.to.SetPosition(to);
  298. SELF.from.SetPosition(from)
  299. ELSE
  300. SELF.to.SetPosition(to);
  301. SELF.from.SetPosition(from);
  302. onChanged(SELF, NIL)
  303. END
  304. END;
  305. text.ReleaseRead
  306. END SetFromTo;
  307. PROCEDURE Sort*;
  308. VAR t : LONGINT;
  309. BEGIN
  310. a := from.GetPosition();
  311. b := to.GetPosition();
  312. IF a > b THEN t := a; a := b; b := t END;
  313. active := a # b
  314. END Sort;
  315. PROCEDURE SetText(text : Texts.UnicodeText);
  316. BEGIN
  317. IF text # NIL THEN SELF.text := text; NEW(from, text); NEW(to, text) END
  318. END SetText;
  319. END Highlight;
  320. HighlightArray = POINTER TO ARRAY OF Highlight;
  321. TYPE
  322. PositionMarker* = OBJECT
  323. VAR
  324. pos : Texts.TextPosition;
  325. img : WMGraphics.Image;
  326. color : WMGraphics.Color;
  327. hotX, hotY : LONGINT;
  328. currentArea : WMRectangles.Rectangle;
  329. text : Texts.UnicodeText;
  330. onChanged : WMMessages.CompCommand;
  331. visible : BOOLEAN;
  332. PROCEDURE &Init*;
  333. BEGIN
  334. color := LONGINT(0FF0000CCH); visible := TRUE
  335. END Init;
  336. PROCEDURE Draw(canvas : WMGraphics.Canvas; x, y, ascent : LONGINT);
  337. BEGIN
  338. IF ~visible THEN RETURN END;
  339. IF img # NIL THEN canvas.DrawImage(x - hotX, y - hotY, img, WMGraphics.ModeSrcOverDst)
  340. ELSE
  341. currentArea := GetArea(x, y, ascent);
  342. canvas.Fill(currentArea, LONGINT(0FF0000CCH), WMGraphics.ModeSrcOverDst)
  343. END
  344. END Draw;
  345. PROCEDURE GetArea(x, y, ascent : LONGINT) : WMRectangles.Rectangle;
  346. BEGIN
  347. IF img # NIL THEN RETURN WMRectangles.MakeRect(x - hotX, y - hotY, x - hotX + img.width, y - hotY + img.height)
  348. ELSE RETURN WMRectangles.MakeRect(x , y - ascent, x + 2, y)
  349. END
  350. END GetArea;
  351. PROCEDURE Load*(CONST filename : ARRAY OF CHAR);
  352. BEGIN
  353. img := WMGraphics.LoadImage(filename, TRUE);
  354. IF img # NIL THEN hotX := img.width DIV 2; hotY := img.height DIV 2 END;
  355. onChanged(SELF, NIL)
  356. END Load;
  357. PROCEDURE SetVisible*(visible : BOOLEAN);
  358. BEGIN
  359. IF SELF.visible # visible THEN
  360. SELF.visible := visible;
  361. onChanged(SELF, NIL)
  362. END
  363. END SetVisible;
  364. PROCEDURE SetPosition*(pos : LONGINT);
  365. BEGIN
  366. IF text = NIL THEN RETURN END; (* if no text is set, the position within is undef *)
  367. text.AcquireRead;
  368. IF pos # SELF.pos.GetPosition() THEN
  369. SELF.pos.SetPosition(pos);
  370. onChanged(SELF, NIL)
  371. END;
  372. text.ReleaseRead
  373. END SetPosition;
  374. PROCEDURE GetPosition*() : LONGINT;
  375. BEGIN
  376. RETURN pos.GetPosition()
  377. END GetPosition;
  378. PROCEDURE SetColor*(color : WMGraphics.Color);
  379. BEGIN
  380. IF SELF.color # color THEN
  381. SELF.color := color;
  382. onChanged(SELF, NIL)
  383. END
  384. END SetColor;
  385. PROCEDURE SetText(text : Texts.UnicodeText);
  386. BEGIN
  387. IF text # NIL THEN
  388. SELF.text := text;
  389. NEW(pos, text);
  390. END
  391. END SetText;
  392. PROCEDURE SetNextInternalPosition*(next : LONGINT);
  393. BEGIN
  394. pos.nextInternalPos := next;
  395. END SetNextInternalPosition;
  396. PROCEDURE GetNextInternalPosition*() : LONGINT;
  397. BEGIN
  398. RETURN pos.nextInternalPos;
  399. END GetNextInternalPosition;
  400. END PositionMarker;
  401. PositionMarkerArray = POINTER TO ARRAY OF PositionMarker;
  402. TYPE
  403. Cursor = OBJECT(PositionMarker)
  404. VAR
  405. isVisible : BOOLEAN;
  406. PROCEDURE &Init*;
  407. BEGIN
  408. isVisible := TRUE;
  409. END Init;
  410. PROCEDURE SetCurrentVisibility(isVisible : BOOLEAN);
  411. BEGIN
  412. IF (SELF.isVisible # isVisible) THEN
  413. SELF.isVisible := isVisible;
  414. onChanged(SELF, NIL);
  415. END;
  416. END SetCurrentVisibility;
  417. PROCEDURE GetArea(x, y, ascent : LONGINT) : WMRectangles.Rectangle;
  418. BEGIN
  419. IF img # NIL THEN RETURN WMRectangles.MakeRect(x - hotX, y - hotY, x - hotX + img.width, y - hotY + img.height)
  420. ELSE RETURN WMRectangles.MakeRect(x , y - ascent - 2, x + 1, y + 2)
  421. END
  422. END GetArea;
  423. PROCEDURE Draw(canvas : WMGraphics.Canvas; x, y, ascent : LONGINT);
  424. BEGIN
  425. IF ~visible OR ~isVisible THEN RETURN END;
  426. IF img # NIL THEN canvas.DrawImage(x - hotX, y - hotY, img, WMGraphics.ModeSrcOverDst)
  427. ELSE
  428. currentArea := GetArea(x, y, ascent);
  429. canvas.Fill(currentArea, WMGraphics.Black, WMGraphics.ModeSrcOverDst)
  430. END
  431. END Draw;
  432. END Cursor;
  433. TYPE
  434. CursorBlinkerCallback = PROCEDURE {DELEGATE} (isVisible : BOOLEAN);
  435. (** Global thread that periodically toggles the visibility of the currently active cursor *)
  436. CursorBlinker* = OBJECT
  437. VAR
  438. cursor : ANY;
  439. callback : CursorBlinkerCallback;
  440. interval : LONGINT;
  441. isVisible : BOOLEAN;
  442. alive, dead : BOOLEAN;
  443. timer : Kernel.Timer;
  444. PROCEDURE &Init;
  445. BEGIN
  446. cursor := NIL; callback := NIL;
  447. interval := 500;
  448. isVisible := TRUE;
  449. alive := TRUE; dead := FALSE;
  450. NEW(timer);
  451. END Init;
  452. (** Set the currently active cursor and a callback that will be periodically called *)
  453. PROCEDURE Set*(cursor : ANY; callback : CursorBlinkerCallback);
  454. BEGIN {EXCLUSIVE}
  455. ASSERT((cursor # NIL) & (callback # NIL));
  456. IF (SELF.cursor # NIL) THEN callback(TRUE); END;
  457. SELF.cursor := cursor;
  458. SELF.callback := callback;
  459. isVisible := TRUE;
  460. timer.Wakeup;
  461. END Set;
  462. (** Set the cursor blinking interval in milliseconds. An interval of MAX(LONGINT) means don't blink *)
  463. PROCEDURE SetInterval*(ms : LONGINT);
  464. BEGIN {EXCLUSIVE}
  465. ASSERT(ms > 0);
  466. interval := ms;
  467. timer.Wakeup;
  468. IF (interval = MAX(LONGINT)) & (cursor # NIL) THEN
  469. isVisible := TRUE;
  470. callback(isVisible);
  471. END;
  472. END SetInterval;
  473. (** If 'cursor' is the currently active cursor, set the currently active cursor to NIL *)
  474. PROCEDURE Remove*(cursor : ANY);
  475. BEGIN {EXCLUSIVE}
  476. ASSERT(cursor # NIL);
  477. IF (SELF.cursor = cursor) THEN
  478. SELF.cursor := NIL;
  479. SELF.callback := NIL;
  480. END;
  481. END Remove;
  482. (** If 'cursor' is the currently active cursor, show it for one period *)
  483. PROCEDURE Show*(cursor : ANY);
  484. BEGIN {EXCLUSIVE}
  485. ASSERT(cursor # NIL);
  486. IF (SELF.cursor = cursor) THEN
  487. isVisible := TRUE;
  488. timer.Wakeup;
  489. END;
  490. END Show;
  491. PROCEDURE Finalize;
  492. BEGIN
  493. BEGIN {EXCLUSIVE} alive := FALSE; END;
  494. timer.Wakeup;
  495. BEGIN {EXCLUSIVE} AWAIT(dead); END;
  496. END Finalize;
  497. BEGIN {ACTIVE}
  498. WHILE alive DO
  499. BEGIN {EXCLUSIVE}
  500. AWAIT(~alive OR ((cursor # NIL) & (interval # MAX(LONGINT))));
  501. IF alive THEN
  502. callback(isVisible);
  503. isVisible := ~isVisible;
  504. END;
  505. END;
  506. timer.Sleep(interval);
  507. END;
  508. BEGIN {EXCLUSIVE} dead := TRUE; END;
  509. END CursorBlinker;
  510. TYPE
  511. TextDropTarget* = OBJECT(WMDropTarget.DropTarget);
  512. VAR text : Texts.Text;
  513. pos : Texts.TextPosition;
  514. PROCEDURE &New*(text : Texts.Text; pos : Texts.TextPosition);
  515. BEGIN
  516. SELF.text := text; SELF.pos := pos
  517. END New;
  518. PROCEDURE GetInterface*(type : LONGINT) : WMDropTarget.DropInterface;
  519. VAR di : WMDropTarget.DropText;
  520. BEGIN
  521. IF type = WMDropTarget.TypeText THEN
  522. NEW(di); di.text := text; di.pos := pos;
  523. RETURN di
  524. ELSE RETURN NIL
  525. END
  526. END GetInterface;
  527. END TextDropTarget;
  528. TYPE
  529. LinkWrapper* = POINTER TO RECORD
  530. link* : Texts.Link;
  531. END;
  532. TYPE
  533. TextView* = OBJECT(WMComponents.VisualComponent)
  534. VAR
  535. defaultTextColor-, defaultTextBgColor- : WMProperties.ColorProperty;
  536. defaultTextColorI, defaultTextBgColorI : WMGraphics.Color;
  537. isMultiLine- : WMProperties.BooleanProperty;
  538. isMultiLineI : BOOLEAN;
  539. (** Text wrapping mode: NoWrap, Wrap or WrapWord (default : WrapWord) *)
  540. wrapMode- : WMProperties.Int32Property;
  541. wrapModeI : LONGINT;
  542. firstLine- : WMProperties.Int32Property;
  543. firstLineI : LONGINT;
  544. leftShift- : WMProperties.Int32Property;
  545. leftShiftI : LONGINT; (* number of units, the view is shifted to left -> line scrolling *)
  546. showBorder- : WMProperties.BooleanProperty;
  547. showBorderI : BOOLEAN;
  548. borders- : WMProperties.RectangleProperty;
  549. bordersI, borderClip : WMRectangles.Rectangle;
  550. x0 : LONGINT; (* text starts at x = x0. Used to get column for line numbers in subclass CodeView *)
  551. alwaysShowCursor- : WMProperties.BooleanProperty;
  552. alwaysShowCursorI : BOOLEAN;
  553. showLabels- : WMProperties.BooleanProperty;
  554. (** Is set to TRUE, the characters will be replaced by passwordChar *)
  555. isPassword- : WMProperties.BooleanProperty;
  556. isPasswordI : BOOLEAN; (* cache of the property value to avoid per-character-locks *)
  557. passwordChar- : WMProperties.Int32Property; (* not cached *)
  558. (** Mouse wheel scrolling speed multiplier? (default: 3, 0: disable mouse wheel scrolling) *)
  559. mouseWheelScrollSpeed- : WMProperties.Int32Property;
  560. mouseWheelScrollSpeedI : LONGINT;
  561. (** Allow middle-click command execution? (default: TRUE) *)
  562. allowCommandExecution- : WMProperties.BooleanProperty;
  563. (** Allow text selection using the mouse? (default: TRUE) *)
  564. allowTextSelection- : WMProperties.BooleanProperty;
  565. (** Should a mouse right-click open the pie menu? (default : TRUE) *)
  566. allowPiemenu- : WMProperties.BooleanProperty;
  567. (** Syntax highlighting *)
  568. highlighting- : WMProperties.StringProperty;
  569. highlighter : SyntaxHighlighter.Highlighter;
  570. state : SyntaxHighlighter.State;
  571. fontCache : FontCache;
  572. (** vertical centering -- momentarily only working for a single line *)
  573. textAlignV-: WMProperties.Int32Property;
  574. showLineNumbers- : WMProperties.BooleanProperty;
  575. showLineNumbersI : BOOLEAN;
  576. lineNumberColor-, lineNumberBgColor- : WMProperties.ColorProperty;
  577. lineNumberColorI, lineNumberBgColorI : WMGraphics.Color;
  578. lineNumberFont, lineNumberFont10 : WMGraphics.Font;
  579. indicateTabs- : WMProperties.BooleanProperty;
  580. indicateTabsI : BOOLEAN;
  581. clBgCurrentLine- : WMProperties.ColorProperty;
  582. clBgCurrentLineI : WMGraphics.Color;
  583. selection- : Highlight;
  584. cursor- : Cursor;
  585. onLinkClicked- : WMEvents.EventSource;
  586. onCtrlClicked- : WMEvents.EventSource;
  587. (** Commands.Context.caller will be set to this object when executing a command *)
  588. commandCaller*: OBJECT;
  589. commandWriter*, errorWriter*: Streams.Writer;
  590. (** Called whenever the cursor position changes *)
  591. onCursorChanged* : PROCEDURE {DELEGATE};
  592. optimize* : BOOLEAN;
  593. piemenu : WMPieMenu.Menu;
  594. text : Texts.Text;
  595. layout : Layout;
  596. utilreader : Texts.TextReader; (* single process ! *)
  597. clipState : WMGraphics.CanvasState;
  598. defaultTabStops : TabStops;
  599. vScrollbar : WMStandardComponents.Scrollbar;
  600. hScrollbar : WMStandardComponents.Scrollbar;
  601. (* highlighting *)
  602. nofHighlights : LONGINT;
  603. highlights : HighlightArray;
  604. (* marked positions *)
  605. nofPositionMarkers : LONGINT;
  606. positionMarkers : PositionMarkerArray;
  607. lastCursorPos: LONGINT;
  608. selecting : BOOLEAN;
  609. doubleclickedWord : BOOLEAN;
  610. dragPossible : BOOLEAN;
  611. dragSelA, dragSelB : Texts.TextPosition;
  612. dragCopy : BOOLEAN;
  613. canStart, openFile : BOOLEAN; (* set for command selection mode *)
  614. commandMarker : Highlight;
  615. downX, downY : LONGINT;
  616. selectWords : BOOLEAN;
  617. wordSelOrdered : BOOLEAN;
  618. lineEnter : LONGINT;
  619. modifierFlags : SET;
  620. oldFlags : SET; (* old pointer flags *)
  621. interclick : LONGINT;
  622. lastTimeStamp : LONGINT;
  623. oldObject, focusObject : ANY;
  624. oldPos, focusPos : LONGINT;
  625. objHasFocus : BOOLEAN;
  626. PROCEDURE &Init*;
  627. BEGIN
  628. Init^;
  629. SetGenerator("WMTextView.GenTextView");
  630. SetNameAsString(StrTextView);
  631. (* properties *)
  632. NEW(defaultTextColor, PTVdefaultTextColor, NIL, NIL); properties.Add(defaultTextColor);
  633. NEW(defaultTextBgColor, PTVdefaultTextBgColor, NIL, NIL); properties.Add(defaultTextBgColor);
  634. NEW(isMultiLine, PTVIsMultiLine, NIL, NIL); properties.Add(isMultiLine);
  635. NEW(wrapMode, PTVWrapMode, NIL, NIL); properties.Add(wrapMode);
  636. NEW(firstLine, PTVfirstLine, NIL, NIL); properties.Add(firstLine);
  637. NEW(leftShift, PTVleftShift, NIL, NIL); properties.Add(leftShift);
  638. NEW(showBorder, PTVShowBorder, NIL, NIL); properties.Add(showBorder);
  639. NEW(borders, PTVborders, NIL, NIL); properties.Add(borders);
  640. NEW(alwaysShowCursor, PTValwaysShowCursor, NIL, NIL); properties.Add(alwaysShowCursor);
  641. NEW(showLabels, PTVShowLabels, NIL, NIL); properties.Add(showLabels);
  642. NEW(isPassword, PTVIsPassword, NIL, NIL); properties.Add(isPassword);
  643. NEW(passwordChar, PTVPasswordChar, NIL, NIL); properties.Add(passwordChar);
  644. NEW(mouseWheelScrollSpeed, PTVMouseWheelScrollSpeed, NIL, NIL); properties.Add(mouseWheelScrollSpeed);
  645. NEW(allowCommandExecution, PTVAllowCommandExecution, NIL, NIL); properties.Add(allowCommandExecution);
  646. NEW(allowTextSelection, PTVAllowTextSelection, NIL, NIL); properties.Add(allowTextSelection);
  647. NEW(allowPiemenu, PTVAllowPiemenu, NIL, NIL); properties.Add(allowPiemenu);
  648. NEW(highlighting, PTVHighlighting, NIL, NIL); properties.Add(highlighting);
  649. highlighter := NIL; state := NIL; fontCache := NIL;
  650. NEW(showLineNumbers, PTVShowLineNumbers, NIL, NIL); properties.Add(showLineNumbers);
  651. NEW(lineNumberColor, PTVLineNumberColor, NIL, NIL); properties.Add(lineNumberColor);
  652. NEW(lineNumberBgColor, PTVLineNumberBgColor, NIL, NIL); properties.Add(lineNumberBgColor);
  653. lineNumberFont := NIL; lineNumberFont10 := NIL;
  654. NEW(indicateTabs, PTVIndicateTabs, NIL, NIL); properties.Add(indicateTabs);
  655. NEW(clBgCurrentLine, PTVclBgCurrentLine, NIL, NIL); properties.Add(clBgCurrentLine);
  656. NEW(textAlignV, PVTtextAlignV, NIL, NIL); properties.Add(textAlignV);
  657. (* events *)
  658. NEW(onLinkClicked, SELF, PTVonLinkClick, PTVonLinkClickInfo, SELF.StringToCompCommand); events.Add(onLinkClicked);
  659. onLinkClicked.Add(LinkClicked);
  660. NEW(onCtrlClicked, SELF, PTVonCtrlLinkClick, PTVonCtrlLinkClickInfo, SELF.StringToCompCommand); events.Add(onCtrlClicked);
  661. (* selection and cursor *)
  662. NEW(layout);
  663. layout.layoutLineProc := LayoutLine;
  664. nofHighlights := 0;
  665. NEW(highlights, 4);
  666. nofPositionMarkers := 0;
  667. NEW(positionMarkers, 4); nofPositionMarkers := 0;
  668. selection := CreateHighlight();
  669. selection.kind := HLOver;
  670. selection.color := SelectionColor;
  671. cursor := CreateCursor();
  672. commandCaller := NIL;
  673. commandWriter := NIL;
  674. onCursorChanged := NIL;
  675. (* Initialization of internal fields *)
  676. optimize := FALSE;
  677. piemenu := NIL;
  678. text := NIL;
  679. utilreader := NIL;
  680. NEW(defaultTabStops); defaultTabStops.tabDist := 20;
  681. vScrollbar := NIL; hScrollbar := NIL;
  682. lastCursorPos := -1;
  683. selecting := FALSE;
  684. doubleclickedWord := FALSE;
  685. dragPossible := FALSE;
  686. dragSelA := NIL; dragSelB := NIL;
  687. canStart := FALSE; openFile := FALSE;
  688. downX := 0; downY := 0;
  689. selectWords := FALSE;
  690. wordSelOrdered := FALSE;
  691. lineEnter := 0;
  692. modifierFlags := {}; oldFlags := {};
  693. interclick := InterclickNone;
  694. lastTimeStamp := 0;
  695. oldObject := NIL; focusObject := NIL;
  696. oldPos := 0; focusPos := 0;
  697. objHasFocus := FALSE;
  698. takesFocus.Set(TRUE);
  699. needsTab.Set(TRUE);
  700. SetPointerInfo(manager.pointerText);
  701. END Init;
  702. PROCEDURE Initialize*;
  703. BEGIN
  704. ASSERT(IsCallFromSequencer());
  705. (*Initialize^; RecacheProperties;*)
  706. IF text#NIL THEN Resized END; (*implicit redundant invalidate in Resized *)(*! Resized is probably redundant*)
  707. (* from now on, bidi-formatting can be done *)
  708. layout.initialized := TRUE;
  709. Initialize^;
  710. cursor.SetVisible(FALSE);
  711. END Initialize;
  712. PROCEDURE Finalize*;
  713. BEGIN
  714. Finalize^;
  715. IF text # NIL THEN text.onTextChanged.Remove(TextChanged); END;
  716. cursorBlinker.Remove(cursor);
  717. END Finalize;
  718. PROCEDURE FocusReceived*;
  719. BEGIN
  720. FocusReceived^;
  721. cursor.SetVisible(TRUE);
  722. cursorBlinker.Set(cursor, cursor.SetCurrentVisibility);
  723. (* let the module know that this is the currently visible TextView *)
  724. currentTextView := SELF;
  725. END FocusReceived;
  726. PROCEDURE FocusLost*;
  727. BEGIN
  728. FocusLost^;
  729. modifierFlags := {};
  730. cursorBlinker.Remove(cursor);
  731. SetInterclick(InterclickNone);
  732. IF ~alwaysShowCursorI THEN cursor.SetVisible(FALSE); END;
  733. END FocusLost;
  734. (* Inserts a character directly into the text. This should be used by external tools that insert character
  735. without the usage of the keyboard, e.g. WMUnicodeMarkerTool) *)
  736. PROCEDURE InsertChar(char : Char32) : INTEGER;
  737. VAR oneCharString : ARRAY 2 OF Texts.Char32;
  738. BEGIN
  739. (* Only insert a character into a valid text, that is either utf-formatted or gets a simple ASCII-character
  740. as input. *)
  741. IF text # NIL THEN
  742. IF text.isUTF OR (char < 256) THEN
  743. oneCharString[0] := char;
  744. oneCharString[1] := 0H;
  745. text.AcquireWrite;
  746. text.InsertUCS32(GetInternalPos(cursor.GetPosition()),oneCharString);
  747. text.ReleaseWrite;
  748. RETURN 0;
  749. ELSE
  750. RETURN -1;
  751. END;
  752. ELSE
  753. RETURN -2;
  754. END;
  755. END InsertChar;
  756. PROCEDURE RecacheProperties*;
  757. VAR
  758. highlighter : SyntaxHighlighter.Highlighter;
  759. oldBorders : WMRectangles.Rectangle;
  760. string : Strings.String;
  761. BEGIN
  762. ASSERT(IsCallFromSequencer());
  763. RecacheProperties^;
  764. defaultTextColorI := defaultTextColor.Get();
  765. defaultTextBgColorI := defaultTextBgColor.Get();
  766. isMultiLineI := isMultiLine.Get();
  767. wrapModeI := wrapMode.Get();
  768. firstLineI := firstLine.Get();
  769. leftShiftI := leftShift.Get();
  770. showBorderI := showBorder.Get();
  771. oldBorders := bordersI;
  772. bordersI := borders.Get();
  773. alwaysShowCursorI := alwaysShowCursor.Get();
  774. mouseWheelScrollSpeedI := mouseWheelScrollSpeed.Get();
  775. isPasswordI := isPassword.Get();
  776. showLineNumbersI := showLineNumbers.Get();
  777. ShowLineNumbers(showLineNumbersI);
  778. lineNumberColorI := lineNumberColor.Get();
  779. lineNumberBgColorI := lineNumberBgColor.Get();
  780. indicateTabsI := indicateTabs.Get();
  781. clBgCurrentLineI := clBgCurrentLine.Get();
  782. string := highlighting.Get();
  783. IF (string # NIL) THEN
  784. highlighter := SyntaxHighlighter.GetHighlighter(string^);
  785. ELSE
  786. highlighter := NIL;
  787. END;
  788. IF text#NIL THEN
  789. SetSyntaxHighlighter(highlighter);
  790. UpdateScrollbars;
  791. IF ~WMRectangles.IsEqual(oldBorders, bordersI) THEN BordersChanged END;
  792. END;
  793. (*Invalidate;*)
  794. END RecacheProperties;
  795. PROCEDURE SetScrollbars*(hScrollbar, vScrollbar : WMStandardComponents.Scrollbar);
  796. BEGIN
  797. Acquire;
  798. IF hScrollbar # NIL THEN hScrollbar.onPositionChanged.Remove(ScrollbarsChanged) END;
  799. IF vScrollbar # NIL THEN vScrollbar.onPositionChanged.Remove(ScrollbarsChanged) END;
  800. SELF.hScrollbar := hScrollbar; SELF.vScrollbar := vScrollbar;
  801. IF hScrollbar # NIL THEN hScrollbar.onPositionChanged.Add(ScrollbarsChanged) END;
  802. IF vScrollbar # NIL THEN vScrollbar.onPositionChanged.Add(ScrollbarsChanged) END;
  803. UpdateScrollbars;
  804. Release
  805. END SetScrollbars;
  806. PROCEDURE ScrollbarsChanged(sender, data : ANY);
  807. BEGIN
  808. IF ~IsCallFromSequencer() THEN sequencer.ScheduleEvent(SELF.ScrollbarsChanged, sender, data)
  809. ELSE
  810. IF sender = vScrollbar THEN firstLine.Set(vScrollbar.pos.Get())
  811. ELSIF sender = hScrollbar THEN leftShift.Set(hScrollbar.pos.Get())
  812. END
  813. END
  814. END ScrollbarsChanged;
  815. PROCEDURE UpdateScrollbars;
  816. BEGIN
  817. IF vScrollbar # NIL THEN
  818. vScrollbar.max.Set(layout.GetNofLines());
  819. vScrollbar.pos.Set(firstLineI);
  820. END;
  821. IF hScrollbar # NIL THEN
  822. IF (wrapModeI # NoWrap) THEN
  823. hScrollbar.visible.Set(FALSE);
  824. ELSE
  825. hScrollbar.visible.Set(TRUE);
  826. (* hScrollbar.visible.Set(layout.textWidth > bounds.GetWidth()); *)
  827. hScrollbar.max.Set(layout.textWidth);
  828. hScrollbar.pageSize.Set(bounds.GetWidth());
  829. hScrollbar.pos.Set(leftShiftI);
  830. END;
  831. END;
  832. END UpdateScrollbars;
  833. PROCEDURE BordersChanged;
  834. VAR vScroll : LONGINT;
  835. BEGIN
  836. ASSERT(IsCallFromSequencer());
  837. IF (vScrollbar # NIL) & (vScrollbar.visible.Get()) THEN vScroll := vScrollbar.bounds.GetWidth() ELSE vScroll := 0 END;
  838. borderClip := WMRectangles.MakeRect(bordersI.l, bordersI.t, bounds.GetWidth() - bordersI.r, bounds.GetHeight() - bordersI.b);
  839. layout.paperWidth := bounds.GetWidth() - (bordersI.l + bordersI.r) - vScroll;
  840. layout.FullLayout(FALSE); CheckNumberOfLines;
  841. END BordersChanged;
  842. PROCEDURE WrapModeChanged;
  843. BEGIN
  844. ASSERT(IsCallFromSequencer());
  845. wrapModeI := wrapMode.Get();
  846. IF (wrapModeI # NoWrap) THEN
  847. leftShift.Set(0); leftShiftI := 0; (* no scrollbars -> don't shift *)
  848. END;
  849. optimize := TRUE;
  850. layout.FullLayout(optimize);
  851. optimize := FALSE;
  852. UpdateScrollbars;
  853. (*Invalidate;*)
  854. END WrapModeChanged;
  855. PROCEDURE PropertyChanged*(sender, property : ANY);
  856. VAR
  857. highlighter : SyntaxHighlighter.Highlighter;
  858. oldBorders : WMRectangles.Rectangle;
  859. string : Strings.String;
  860. BEGIN
  861. IF property = defaultTextColor THEN
  862. defaultTextColorI := defaultTextColor.Get(); Invalidate;
  863. ELSIF property = defaultTextBgColor THEN
  864. defaultTextBgColorI := defaultTextBgColor.Get(); Invalidate;
  865. ELSIF property = isMultiLine THEN
  866. isMultiLineI := isMultiLine.Get(); Invalidate;
  867. ELSIF property = wrapMode THEN
  868. wrapModeI := wrapMode.Get(); WrapModeChanged; Invalidate;
  869. ELSIF property = firstLine THEN
  870. firstLineI := firstLine.Get(); UpdateScrollbars; Invalidate;
  871. ELSIF property = leftShift THEN
  872. leftShiftI := leftShift.Get(); UpdateScrollbars; Invalidate;
  873. ELSIF property = showBorder THEN
  874. showBorderI := showBorder.Get(); Invalidate;
  875. ELSIF property = borders THEN
  876. oldBorders := bordersI; bordersI := borders.Get(); BordersChanged; Invalidate;
  877. ELSIF property = alwaysShowCursor THEN
  878. alwaysShowCursorI := alwaysShowCursor.Get();
  879. IF (alwaysShowCursorI = TRUE) THEN cursor.SetVisible(TRUE);
  880. ELSIF ~hasFocus THEN cursor.SetVisible(FALSE);
  881. END;
  882. Invalidate;
  883. ELSIF property = mouseWheelScrollSpeed THEN
  884. mouseWheelScrollSpeedI := mouseWheelScrollSpeed.Get();
  885. ELSIF property = isPassword THEN
  886. isPasswordI := isPassword.Get(); Invalidate;
  887. ELSIF (property = highlighting) THEN
  888. string := highlighting.Get();
  889. IF (string # NIL) THEN
  890. highlighter := SyntaxHighlighter.GetHighlighter(string^);
  891. ELSE
  892. highlighter := NIL;
  893. END;
  894. SetSyntaxHighlighter(highlighter);
  895. ELSIF (property = showLineNumbers) THEN
  896. showLineNumbersI := showLineNumbers.Get();
  897. ShowLineNumbers(showLineNumbersI);
  898. Invalidate;
  899. ELSIF (property = indicateTabs) THEN
  900. indicateTabsI := indicateTabs.Get(); Invalidate;
  901. ELSIF (property = clBgCurrentLine) THEN
  902. clBgCurrentLineI := clBgCurrentLine.Get(); Invalidate;
  903. ELSIF (property = textAlignV) THEN
  904. Invalidate;
  905. ELSIF (property = lineNumberColor) OR (property = lineNumberBgColor) THEN
  906. lineNumberColorI := lineNumberColor.Get();
  907. lineNumberBgColorI := lineNumberBgColor.Get();
  908. Invalidate;
  909. ELSE
  910. PropertyChanged^(sender, property)
  911. END
  912. END PropertyChanged;
  913. PROCEDURE Resized*;
  914. VAR prevWidth: LONGINT;
  915. BEGIN
  916. ASSERT(IsCallFromSequencer());
  917. Resized^; (*? here, an implicit Invalidate() is triggered - this is probably redundant *)
  918. prevWidth := layout.paperWidth;
  919. layout.paperWidth := bounds.GetWidth() - (bordersI.l + bordersI.r);
  920. borderClip.r := bounds.GetWidth() - bordersI.r; borderClip.b := bounds.GetHeight() - bordersI.b;
  921. IF (prevWidth # layout.paperWidth) & (wrapMode.Get()#NoWrap) THEN
  922. layout.FullLayout(optimize);
  923. END;
  924. CheckNumberOfLines;
  925. END Resized;
  926. (** Replace the text *)
  927. PROCEDURE SetText*(text : Texts.Text);
  928. VAR i : LONGINT;
  929. BEGIN
  930. ASSERT(text # NIL);
  931. Acquire;
  932. IF SELF.text # NIL THEN SELF.text.onTextChanged.Remove(TextChanged) END; (* unregister the TextChanged listener from the old text *)
  933. SELF.text := text;
  934. text.onTextChanged.Add(TextChanged); (* register the TextChanged listener with the new text*)
  935. NEW(utilreader, text);
  936. (* update all highlights *)
  937. FOR i := 0 TO nofHighlights - 1 DO highlights[i].SetText(text) END;
  938. FOR i := 0 TO nofPositionMarkers - 1 DO
  939. positionMarkers[i].SetText(text);
  940. (* Let the cursor know about the local position-translation procedures *)
  941. IF text.isUTF THEN
  942. positionMarkers[i].pos.SetInternalPositionTranslator(GetInternalPos);
  943. positionMarkers[i].pos.SetDisplayPositionTranslator(GetDisplayPos);
  944. END;
  945. END;
  946. text.AcquireRead; (* also protect SELF.highlighter and SELF.state here *)
  947. IF (highlighter # NIL) THEN
  948. ASSERT(state # NIL);
  949. highlighter.RebuildRegions(utilreader, state);
  950. END;
  951. layout.SetText(text);
  952. layout.FullLayout(TRUE);
  953. CheckNumberOfLines;
  954. ASSERT(((highlighter = NIL) & (state = NIL)) OR ((highlighter # NIL) & (state # NIL)));
  955. text.ReleaseRead;
  956. (*Invalidate;(*! Redundant ?*)*)
  957. Release;
  958. END SetText;
  959. PROCEDURE SetSyntaxHighlighter*(highlighter : SyntaxHighlighter.Highlighter);
  960. BEGIN
  961. ASSERT(text # NIL);
  962. Acquire;
  963. IF (SELF.highlighter # highlighter) & ((SELF.highlighter # NIL) OR (highlighter # NIL)) THEN
  964. text.AcquireRead; (* also protect SELF.highlighter and SELF.state here *)
  965. SELF.highlighter := highlighter;
  966. IF (highlighter # NIL) THEN
  967. IF (state = NIL) THEN
  968. state := highlighter.GetState();
  969. ASSERT(state # NIL);
  970. END;
  971. highlighter.RebuildRegions(utilreader, state);
  972. ELSE
  973. state := NIL;
  974. END;
  975. layout.FullLayout(TRUE);
  976. CheckNumberOfLines;
  977. ASSERT(((highlighter = NIL) & (state = NIL)) OR ((highlighter # NIL) & (state # NIL)));
  978. text.ReleaseRead;
  979. Invalidate;
  980. END;
  981. Release;
  982. END SetSyntaxHighlighter;
  983. PROCEDURE ShowLineNumbers(enabled : BOOLEAN);
  984. VAR font : WMGraphics.Font;
  985. BEGIN
  986. font := GetFont( );
  987. IF enabled THEN
  988. x0 := 55;
  989. lineNumberFont := WMGraphics.GetFont(font.name, font.size, {});
  990. lineNumberFont10 := WMGraphics.GetFont(font.name, font.size, {WMGraphics.FontBold});
  991. ELSE
  992. x0 := 0;
  993. lineNumberFont := NIL;
  994. lineNumberFont10 := NIL;
  995. END;
  996. END ShowLineNumbers;
  997. PROCEDURE SetTabStops*(ts : TabStops);
  998. BEGIN
  999. Acquire;
  1000. defaultTabStops := ts;
  1001. layout.FullLayout(TRUE);
  1002. CheckNumberOfLines;
  1003. Release;
  1004. END SetTabStops;
  1005. (* BEGIN highlighting *)
  1006. PROCEDURE AddHighlight(highlight : Highlight);
  1007. VAR newHighlights : HighlightArray; i : LONGINT;
  1008. BEGIN
  1009. INC(nofHighlights);
  1010. IF nofHighlights > LEN(highlights) THEN
  1011. NEW(newHighlights, LEN(highlights) * 2);
  1012. FOR i := 0 TO LEN(highlights) - 1 DO newHighlights[i] := highlights[i] END;
  1013. highlights := newHighlights;
  1014. END;
  1015. highlights[nofHighlights - 1] := highlight;
  1016. HighlightChanged(highlight, NIL);
  1017. END AddHighlight;
  1018. PROCEDURE CreateHighlight*() : Highlight;
  1019. VAR h : Highlight;
  1020. BEGIN
  1021. Acquire;
  1022. NEW(h); h.SetText(text);
  1023. h.onChanged := HighlightChanged;
  1024. AddHighlight(h);
  1025. Release;
  1026. RETURN h
  1027. END CreateHighlight;
  1028. PROCEDURE RemoveHighlight*(x : Highlight);
  1029. VAR i : LONGINT;
  1030. BEGIN
  1031. Acquire;
  1032. i := 0; WHILE (i < nofHighlights) & (highlights[i] # x) DO INC(i) END;
  1033. IF i < nofHighlights THEN
  1034. WHILE (i < nofHighlights - 1) DO highlights[i] := highlights[i+1]; INC(i) END;
  1035. DEC(nofHighlights);
  1036. highlights[nofHighlights] := NIL
  1037. END;
  1038. HighlightChanged(NIL, NIL);
  1039. Release
  1040. END RemoveHighlight;
  1041. PROCEDURE InvalidateRange(a, b : LONGINT);
  1042. VAR
  1043. t, l0, l1 : LONGINT;
  1044. x0, y0, x1, y1, d : LONGINT;
  1045. ia, ib : LONGINT;
  1046. BEGIN
  1047. ia := GetDisplayPos(a);
  1048. ib := GetDisplayPos(b);
  1049. (* Sort the display positions, not the internal positions so as not to get weird results! *)
  1050. IF ia > ib THEN t := ia; ia := ib; ib := t END;
  1051. l0 := layout.FindLineNrByPos(ia);
  1052. l1 := layout.FindLineNrByPos(ib);
  1053. IF l0 = l1 THEN (* only one line... optimize *)
  1054. LineYPos(l0, y0, y1);
  1055. (* if text is UTF-formatted (and thus might content RTL-text) the whole line is invalidated.
  1056. this might - in some rare cases - be a bit slower than invalidating the minimum rectangle
  1057. but is guaranteed to always be correct. *)
  1058. IF text.isUTF OR (~(FindScreenPos(ia, x0, d) & FindScreenPos(ib, x1, d))) THEN
  1059. x0 := 0; x1 := bounds.GetWidth();
  1060. END;
  1061. InvalidateRect(WMRectangles.MakeRect(x0, y0, x1, y1));
  1062. ELSE
  1063. LineYPos(l0, y0, d); LineYPos(l1, d, y1);
  1064. InvalidateRect(WMRectangles.MakeRect(0, y0, bounds.GetWidth(), y1));
  1065. END;
  1066. IF TraceInvalidate IN Trace THEN KernelLog.String("ir ") END;
  1067. END InvalidateRange;
  1068. PROCEDURE HighlightChanged(sender, data : ANY);
  1069. VAR hl : Highlight; min, max : LONGINT;
  1070. BEGIN
  1071. IF ~initialized THEN RETURN END;
  1072. IF ~IsCallFromSequencer() THEN sequencer.ScheduleEvent(SELF.HighlightChanged, sender, data)
  1073. ELSE
  1074. text.AcquireRead;
  1075. IF (sender # NIL) & (sender IS Highlight) THEN
  1076. hl := sender(Highlight);
  1077. IF ((hl.oldFrom # hl.from.GetPosition()) & (hl.oldTo # hl.to.GetPosition())) OR (hl.oldColor # hl.color) THEN (* both changed *)
  1078. min := Strings.Min(
  1079. Strings.Min(hl.oldFrom, hl.from.GetPosition()),
  1080. Strings.Min(hl.oldTo, hl.to.GetPosition()));
  1081. max := Strings.Max(
  1082. Strings.Max(hl.oldFrom, hl.from.GetPosition()),
  1083. Strings.Max(hl.oldTo, hl.to.GetPosition()));
  1084. InvalidateRange(min, max)
  1085. ELSIF hl.oldTo # hl.to.GetPosition() THEN (* to changed *)
  1086. InvalidateRange(hl.oldTo, hl.to.GetPosition())
  1087. ELSIF hl.oldFrom # hl.from.GetPosition() THEN (* from changed *)
  1088. InvalidateRange(hl.oldFrom, hl.from.GetPosition())
  1089. ELSE (* position noch changed... probably color, style or visibility changed, invalidate range *)
  1090. InvalidateRange(hl.from.GetPosition(),hl.to.GetPosition())
  1091. END
  1092. ELSE
  1093. IF TraceInvalidate IN Trace THEN KernelLog.String("H") END;
  1094. Invalidate
  1095. END;
  1096. text.ReleaseRead
  1097. END
  1098. END HighlightChanged;
  1099. (* END highlighting *)
  1100. (* BEGIN PositionMarkers *)
  1101. PROCEDURE AddPositionMarker(pm : PositionMarker);
  1102. VAR newPositionMarkers : PositionMarkerArray; i : LONGINT;
  1103. BEGIN
  1104. INC(nofPositionMarkers);
  1105. IF nofPositionMarkers > LEN(positionMarkers) THEN
  1106. NEW(newPositionMarkers, LEN(positionMarkers) * 2);
  1107. FOR i := 0 TO LEN(positionMarkers) - 1 DO newPositionMarkers[i] := positionMarkers[i] END;
  1108. positionMarkers := newPositionMarkers
  1109. END;
  1110. positionMarkers[nofPositionMarkers - 1] := pm
  1111. END AddPositionMarker;
  1112. PROCEDURE CreatePositionMarker*() : PositionMarker;
  1113. VAR p : PositionMarker;
  1114. BEGIN
  1115. Acquire;
  1116. NEW(p); p.SetText(text);
  1117. p.onChanged := PositionMarkerChanged;
  1118. AddPositionMarker(p);
  1119. Release;
  1120. RETURN p
  1121. END CreatePositionMarker;
  1122. PROCEDURE CreateCursor*() : Cursor;
  1123. VAR p : Cursor;
  1124. BEGIN
  1125. Acquire;
  1126. NEW(p); p.SetText(text);
  1127. p.onChanged := PositionMarkerChanged;
  1128. AddPositionMarker(p);
  1129. Release;
  1130. RETURN p
  1131. END CreateCursor;
  1132. PROCEDURE RemovePositionMarker*(x : PositionMarker);
  1133. VAR i, xp, yp, l, ascent : LONGINT; newRect : WMRectangles.Rectangle;
  1134. BEGIN
  1135. Acquire;
  1136. i := 0; WHILE (i < nofPositionMarkers) & (positionMarkers[i] # x) DO INC(i) END;
  1137. IF i < nofPositionMarkers THEN
  1138. WHILE (i < nofPositionMarkers - 1) DO positionMarkers[i] := positionMarkers[i+1]; INC(i) END;
  1139. DEC(nofPositionMarkers);
  1140. positionMarkers[nofPositionMarkers] := NIL
  1141. END;
  1142. IF FindScreenPos(x.pos.GetPosition(), xp, yp) THEN
  1143. l := layout.FindLineNrByPos(x.pos.GetPosition());
  1144. IF (l < LEN(layout.lines^)) & (l >= 0) THEN
  1145. ascent := layout.lines[l].ascent;
  1146. (* IF ascent = 0 THEN ascent := layout.lines[l].height END;
  1147. IF ascent = 0 THEN ascent := 10 END; *)
  1148. newRect := x.GetArea(xp, yp, ascent);
  1149. InvalidateRect(newRect)
  1150. END
  1151. END;
  1152. Release
  1153. END RemovePositionMarker;
  1154. PROCEDURE PositionMarkerChanged(sender, data : ANY);
  1155. VAR newRect, combinedRect : WMRectangles.Rectangle; x, y, l, ascent : LONGINT;
  1156. BEGIN
  1157. IF ~IsCallFromSequencer() THEN sequencer.ScheduleEvent(SELF.PositionMarkerChanged, sender, data)
  1158. ELSE
  1159. data := sender;
  1160. IF (data # NIL) & (data IS PositionMarker) THEN
  1161. text.AcquireRead;
  1162. IF data = cursor THEN CheckCursor; END;
  1163. IF (data = cursor) & (clBgCurrentLineI # 0) THEN
  1164. Invalidate; (* HACK to handle clBgCurrentLine correcty. Should be replaced by a more efficient solution *)
  1165. ELSE
  1166. IF FindScreenPos(data(PositionMarker).pos.GetPosition(), x, y) THEN
  1167. l := layout.FindLineNrByPos(data(PositionMarker).pos.GetPosition());
  1168. IF (l < LEN(layout.lines^)) & (l >= 0) THEN
  1169. ascent := layout.lines[l].ascent;
  1170. (* IF ascent = 0 THEN ascent := layout.lines[l].height END;
  1171. IF ascent = 0 THEN ascent := 10 END;*)
  1172. newRect := data(PositionMarker).GetArea(x, y, ascent)
  1173. END
  1174. END;
  1175. combinedRect := data(PositionMarker).currentArea;
  1176. IF WMRectangles.RectEmpty(combinedRect) THEN combinedRect := newRect
  1177. ELSE WMRectangles.ExtendRect(combinedRect, newRect)
  1178. END;
  1179. IF ~WMRectangles.RectEmpty(combinedRect) THEN
  1180. IF (WMRectangles.Area(data(PositionMarker).currentArea) + WMRectangles.Area(newRect)) * 5 < WMRectangles.Area(combinedRect) THEN
  1181. InvalidateRect(data(PositionMarker).currentArea);
  1182. InvalidateRect(newRect)
  1183. ELSE
  1184. InvalidateRect(combinedRect)
  1185. END
  1186. END;
  1187. END;
  1188. text.ReleaseRead;
  1189. ELSE
  1190. Invalidate;
  1191. END;
  1192. END
  1193. END PositionMarkerChanged;
  1194. (* END PositionMarkers *)
  1195. PROCEDURE CheckNumberOfLines;
  1196. BEGIN
  1197. UpdateScrollbars;
  1198. firstLine.SetBounds(0, layout.GetNofLines() - 1)
  1199. END CheckNumberOfLines;
  1200. PROCEDURE CheckCursor;
  1201. VAR
  1202. cp, l, i : LONGINT;
  1203. ty : LONGINT;
  1204. lineStartPosition, lineLength: LONGINT;
  1205. li: LineInfo;
  1206. dummyCh : Char32;
  1207. x, dummyY, xend, paperWidth, newShift: LONGINT;
  1208. dummyBool : BOOLEAN;
  1209. BEGIN
  1210. ASSERT(IsCallFromSequencer() & text.HasReadLock());
  1211. (* Scroll up, down to make cursor visible *)
  1212. cp := cursor.GetPosition();
  1213. IF cp = lastCursorPos THEN
  1214. RETURN
  1215. ELSE
  1216. lastCursorPos := cp
  1217. END;
  1218. IF (cp < 0) THEN
  1219. cursor.SetPosition(GetDisplayPos(0));
  1220. ELSIF (cp > text.GetLength()) THEN
  1221. cursor.SetPosition(text.GetLength());
  1222. END;
  1223. l := layout.FindLineNrByPos(cursor.GetPosition());
  1224. IF (l < firstLineI) THEN
  1225. (* move the cursor down by 3 lines to get more context *)
  1226. l := Strings.Max(0, l - 3);
  1227. firstLine.Set(l);
  1228. ELSIF (l < layout.GetNofLines()) THEN
  1229. ty := bordersI.t; i := firstLineI;
  1230. WHILE i < l DO
  1231. ty := ty + layout.lines[i].height;
  1232. CheckParagraphBegin(i, ty);
  1233. CheckParagraphEnd(i, ty);
  1234. INC(i);
  1235. END;
  1236. ty := ty + layout.lines[i].height;
  1237. IF ty >= bounds.GetHeight() - bordersI.b THEN
  1238. l := Strings.Max(0, l - 3);
  1239. firstLine.Set(l)
  1240. END
  1241. END;
  1242. (* fof071127: Scroll left right to make cursor visible *)
  1243. lineStartPosition := layout.GetLineStartPos(l);
  1244. lineLength := layout.GetLineLength(l);
  1245. (* compute x position of the cursor on the line *)
  1246. IF optimize OR ~text.isUTF THEN
  1247. LayoutLine(lineStartPosition,dummyCh,li,layout.paperWidth,cp,-1);
  1248. x := li.width + GetLineLeftIndent(l);
  1249. ELSE
  1250. dummyBool := FindScreenPos(cp,x,dummyY);
  1251. IF x < 0 THEN
  1252. x := 0;
  1253. END;
  1254. INC(x,GetLineLeftIndent(l));
  1255. END;
  1256. (* compute x position of the end of the cursor's line *)
  1257. lineStartPosition := layout.GetLineStartPos(l);
  1258. lineLength := layout.GetLineLength(l);
  1259. LayoutLine(lineStartPosition, dummyCh, li, layout.paperWidth, lineStartPosition+lineLength-1, -1);
  1260. xend := li.width + GetLineLeftIndent(l);
  1261. newShift := leftShiftI;
  1262. (* align shift such that the cursor is visible *)
  1263. paperWidth := layout.paperWidth - bordersI.l - x0;
  1264. IF paperWidth > 0 THEN
  1265. IF x-leftShiftI > paperWidth THEN (* cursor right of displayed area *)
  1266. newShift := x-paperWidth; (* move content such that cursor is barely visible to the right *)
  1267. ELSIF x-leftShiftI < 0 THEN (* cursor is left of displayed area *)
  1268. newShift := x; (* move content such that cursor is barely visible to the left *)
  1269. END;
  1270. (* now check some possibly more optimal ways of displaying *)
  1271. IF xend-newShift < paperWidth THEN
  1272. (* line can be shown more fully to the left, we don't want to waste space to the right *)
  1273. newShift := xend-paperWidth;
  1274. IF newShift < 0 THEN newShift := 0 END;
  1275. END;
  1276. (* do the shift *)
  1277. IF newShift # leftShiftI THEN
  1278. leftShift.Set(newShift);
  1279. END;
  1280. END;
  1281. END CheckCursor;
  1282. PROCEDURE CheckParagraphBegin(lineNr : LONGINT; VAR height: LONGINT);
  1283. BEGIN
  1284. IF layout.lines[lineNr].firstInParagraph THEN height := height + layout.lines[lineNr].spaceBefore END
  1285. END CheckParagraphBegin;
  1286. PROCEDURE CheckParagraphEnd(lineNr : LONGINT; VAR height: LONGINT);
  1287. BEGIN
  1288. IF layout.lines[lineNr].lastInParagraph THEN height := height + layout.lines[lineNr].spaceAfter; END;
  1289. END CheckParagraphEnd;
  1290. PROCEDURE TextChanged(sender, data : ANY);
  1291. VAR
  1292. f, l, t, b, i, p, pa, pb, h: LONGINT; linesChanged, fullLayout : BOOLEAN;
  1293. info : Texts.TextChangeInfo;
  1294. BEGIN
  1295. IF ~initialized THEN RETURN END;
  1296. IF ~IsCallFromSequencer() THEN sequencer.ScheduleEvent(SELF.TextChanged, sender, data)
  1297. ELSE
  1298. IF (data # NIL) & (data IS Texts.TextChangeInfo) & (data(Texts.TextChangeInfo).op # Texts.OpMulti) THEN
  1299. text.AcquireRead;
  1300. info := data(Texts.TextChangeInfo);
  1301. IF text.GetTimestamp() = info.timestamp THEN
  1302. info := data(Texts.TextChangeInfo);
  1303. IF (highlighter # NIL) THEN
  1304. ASSERT(state # NIL);
  1305. fullLayout := FALSE;
  1306. IF ((info.op = Texts.OpInsert) OR (info.op = Texts.OpDelete)) THEN
  1307. highlighter.PatchRegions(info, utilreader, state, fullLayout);
  1308. ELSIF (info.op = Texts.OpAttributes) THEN
  1309. (* do nothing here *)
  1310. ELSE
  1311. highlighter.RebuildRegions(utilreader, state);
  1312. fullLayout := TRUE;
  1313. END;
  1314. IF fullLayout THEN
  1315. layout.FullLayout(TRUE);
  1316. lastTimeStamp := text.GetTimestamp();
  1317. CheckCursor;
  1318. CheckNumberOfLines;
  1319. text.ReleaseRead;
  1320. InvalidateRect(GetClientRect());
  1321. cursorBlinker.Show(cursor);
  1322. RETURN;
  1323. END;
  1324. END;
  1325. (* Upon an insertion or deletion in the text, parts of the text may need reformatting *)
  1326. IF info.op = Texts.OpInsert THEN
  1327. (* If necessary, reformat the affected text *)
  1328. IF layout.initialized & text.isUTF & (layout.bidiFormatter # NIL) THEN
  1329. layout.bidiFormatter.ReformatTextFrom(info.pos,info.len);
  1330. END;
  1331. layout.FixLayoutFrom(info.pos, info.len, f, l, linesChanged);
  1332. ELSE
  1333. (* If necessary, reformat the affected text *)
  1334. IF layout.initialized & text.isUTF & (layout.bidiFormatter # NIL) THEN
  1335. layout.bidiFormatter.ReformatTextFrom(info.pos,-info.len)
  1336. END;
  1337. layout.FixLayoutFrom(info.pos, -info.len, f, l, linesChanged);
  1338. END;
  1339. t := bordersI.t;
  1340. FOR i := firstLineI TO f - 1 DO
  1341. t := t + (layout.lines[i].height);
  1342. CheckParagraphBegin(i, t);
  1343. CheckParagraphEnd(i, t);
  1344. END;
  1345. h := bounds.GetHeight();
  1346. IF linesChanged THEN b := h ELSE
  1347. b := t; i := f;
  1348. WHILE (i <= l) & (b < h) DO
  1349. b := b + (layout.lines[i].height);
  1350. CheckParagraphBegin(i, b);
  1351. CheckParagraphEnd(i, b);
  1352. INC(i);
  1353. END
  1354. END;
  1355. pa := layout.lines[f].pos;
  1356. IF l + 1 < layout.nofLines THEN pb := layout.lines[l + 1].pos ELSE pb := text.GetLength() END;
  1357. FOR i := 0 TO nofPositionMarkers - 1 DO
  1358. p := positionMarkers[i].pos.GetPosition();
  1359. IF (p >= pa) & (p < pb) THEN
  1360. (* very conservative *)
  1361. h := positionMarkers[i].currentArea.b - positionMarkers[i].currentArea.t;
  1362. t := t - h;
  1363. b := b + h
  1364. END
  1365. END;
  1366. CheckCursor;
  1367. UpdateScrollbars;
  1368. InvalidateRect(WMRectangles.MakeRect(0, t, bounds.GetWidth(), b));
  1369. ELSIF (lastTimeStamp - info.timestamp) > 0 THEN
  1370. (* Don't update lastTimeStamp since we didn't update the layout *)
  1371. ELSE
  1372. IF (highlighter # NIL) THEN
  1373. ASSERT(state # NIL);
  1374. highlighter.RebuildRegions(utilreader, state);
  1375. END;
  1376. layout.FullLayout(TRUE);
  1377. lastTimeStamp := text.GetTimestamp();
  1378. CheckCursor;
  1379. InvalidateRect(GetClientRect())
  1380. END;
  1381. CheckNumberOfLines;
  1382. text.ReleaseRead
  1383. ELSE
  1384. text.AcquireRead;
  1385. IF (highlighter # NIL) THEN
  1386. ASSERT(state # NIL);
  1387. highlighter.RebuildRegions(utilreader, state);
  1388. END;
  1389. layout.FullLayout(TRUE);
  1390. lastTimeStamp := text.GetTimestamp();
  1391. CheckCursor;
  1392. CheckNumberOfLines;
  1393. text.ReleaseRead;
  1394. InvalidateRect(GetClientRect())
  1395. END;
  1396. cursorBlinker.Show(cursor);
  1397. END;
  1398. END TextChanged;
  1399. (* BEGIN view dependant layout functions *)
  1400. (** Return the left indent of a line - depending on alignment *)
  1401. (* returns left border, in case of errors *)
  1402. PROCEDURE GetLineLeftIndent(linenr : LONGINT): LONGINT;
  1403. VAR indent : LONGINT;
  1404. BEGIN
  1405. IF (linenr < 0) OR (linenr >= layout.nofLines) THEN RETURN 0 END;
  1406. IF layout.lines[linenr].firstInParagraph THEN indent := layout.lines[linenr].firstIndent ELSE indent := layout.lines[linenr].leftIndent END;
  1407. CASE layout.lines[linenr].align OF
  1408. AlignLeft : RETURN indent;
  1409. |AlignCenter : RETURN ((layout.paperWidth - (layout.lines[linenr].width)) DIV 2 - indent DIV 2);
  1410. |AlignRight : RETURN (layout.paperWidth - layout.lines[linenr].width - layout.lines[linenr].rightIndent);
  1411. ELSE
  1412. RETURN 0;
  1413. END;
  1414. END GetLineLeftIndent;
  1415. (** Find the line number that currently contains the y value (y relative to 0 in component)*)
  1416. PROCEDURE FindLineByY*(firstLine, y : LONGINT) : LONGINT;
  1417. VAR i : LONGINT; ypos : LONGINT;
  1418. BEGIN
  1419. ASSERT(text.HasReadLock());
  1420. ypos := bordersI.t; i := firstLine;
  1421. IF y < 0 THEN RETURN 0 END;
  1422. WHILE (i < layout.nofLines) & (ypos <= y) DO
  1423. ypos := ypos + layout.lines[i].height;
  1424. CheckParagraphBegin(i, ypos);
  1425. CheckParagraphEnd(i, ypos);
  1426. INC(i);
  1427. END;
  1428. RETURN Strings.Max(i -1, 0)
  1429. END FindLineByY;
  1430. PROCEDURE ViewToTextPos*(x, y: LONGINT; VAR pos : LONGINT);
  1431. VAR
  1432. l : LONGINT;
  1433. dummy : LineInfo;
  1434. dummyCh : Char32;
  1435. indent : LONGINT;
  1436. BEGIN
  1437. text.AcquireRead;
  1438. pos := -1;
  1439. x := Strings.Max(0, Strings.Min(x, bounds.GetWidth()));
  1440. y := Strings.Max(0, Strings.Min(y, bounds.GetHeight()));
  1441. l := FindLineByY(firstLineI, Strings.Min(Strings.Max(y, bordersI.t), bounds.GetHeight() - bordersI.b));
  1442. x := x - bordersI.l - x0 + leftShiftI;
  1443. IF x < 0 THEN x := 0 END;
  1444. IF l >= 0 THEN
  1445. dummy := layout.lines[l]; (* this line belongs in here! *)
  1446. pos := layout.GetLineStartPos(l);
  1447. IF dummy.firstInParagraph THEN indent := dummy.firstIndent
  1448. ELSE indent := dummy.leftIndent END;
  1449. IF dummy.align = 0 THEN (* Left *)
  1450. LayoutLine(pos, dummyCh, dummy, layout.paperWidth, -1, x-indent)
  1451. ELSIF dummy.align = 1 THEN (* Center *)
  1452. LayoutLine(pos, dummyCh, dummy, layout.paperWidth, -1, x-((layout.paperWidth - dummy.width - indent) DIV 2))
  1453. ELSIF dummy.align = 2 THEN (* Right *)
  1454. LayoutLine(pos, dummyCh, dummy, layout.paperWidth, -1, x-(layout.paperWidth - dummy.width - dummy.rightIndent))
  1455. END;
  1456. (* Adjust the position if necessary *)
  1457. IF IsRightToLeft(pos) THEN
  1458. DEC(pos);
  1459. END;
  1460. END;
  1461. text.ReleaseRead
  1462. END ViewToTextPos;
  1463. (* Returns the height for the given width *)
  1464. PROCEDURE GetHeight*(width: LONGINT): LONGINT;
  1465. VAR oldWidth, height : LONGINT;
  1466. BEGIN
  1467. oldWidth := layout.paperWidth;
  1468. layout.paperWidth := width;
  1469. layout.FullLayout(FALSE);
  1470. height := layout.textHeight;
  1471. (* reset old state *)
  1472. layout.paperWidth := oldWidth;
  1473. layout.FullLayout(FALSE);
  1474. RETURN height
  1475. END GetHeight;
  1476. (* Returns the size of the largest word and line in pixels *)
  1477. PROCEDURE GetMinMaxWidth*(VAR word, line : LONGINT);
  1478. VAR dx, pos : LONGINT;
  1479. cws, cls : LONGINT;
  1480. f,cf : WMGraphics.Font;
  1481. ch : Char32;
  1482. tabstring : ARRAY 256 OF CHAR; tabs : CustomTabStops; tp : TabPositions;
  1483. sr : Streams.StringReader; tabCounter, tabPos : LONGINT; token : ARRAY 16 OF CHAR;
  1484. pStyle : Texts.ParagraphStyle;
  1485. cStyle : Texts.CharacterStyle;
  1486. PROCEDURE GetWidth(ch : Char32; VAR dx : LONGINT);
  1487. VAR gs : WMGraphics.GlyphSpacings; vc : WMComponents.VisualComponent;
  1488. BEGIN
  1489. IF ch = Texts.ObjectChar THEN
  1490. IF (utilreader.object # NIL) & (utilreader.object IS WMGraphics.Image) THEN
  1491. dx := utilreader.object(WMGraphics.Image).width
  1492. ELSIF (utilreader.object # NIL) & (utilreader.object IS WMComponents.VisualComponent) THEN
  1493. vc := utilreader.object(WMComponents.VisualComponent);
  1494. dx := vc.bounds.GetWidth();
  1495. END
  1496. ELSIF ch = Texts.TabChar THEN
  1497. IF tabs # NIL THEN dx := tabs.GetNextTabStop(cls) - cls
  1498. ELSE dx := defaultTabStops.GetNextTabStop(cls) - cls
  1499. END;
  1500. ELSE
  1501. IF isPasswordI THEN ch := passwordChar.Get() END;
  1502. IF f.HasChar(ch) THEN
  1503. f.GetGlyphSpacings(ch, gs);
  1504. ELSE
  1505. WMGraphics.FBGetGlyphSpacings(ch, gs);
  1506. END;
  1507. dx := gs.bearing.l + gs.width + gs.bearing.r
  1508. END
  1509. END GetWidth;
  1510. BEGIN
  1511. cf := GetFont(); (* set the default component font *)
  1512. f := cf;
  1513. pos := 0; cws := 0; cls := 0; word := 0; line := 0;
  1514. text.AcquireRead;
  1515. utilreader.SetDirection(1); utilreader.SetPosition(pos);
  1516. REPEAT
  1517. utilreader.ReadCh(ch);
  1518. (* Get the Paragraph Style *)
  1519. IF utilreader.pstyle # NIL THEN
  1520. pStyle := utilreader.pstyle;
  1521. (* parse tabstops *)
  1522. COPY(pStyle.tabStops, tabstring);
  1523. IF (tabstring # "default") & (tabstring # "0") & (tabstring # "") THEN
  1524. NEW(sr, LEN(tabstring)); sr.Set(tabstring); tabCounter := 0;
  1525. WHILE (sr.res = Streams.Ok) DO
  1526. sr.SkipWhitespace; sr.String(token);
  1527. INC(tabCounter);
  1528. END;
  1529. NEW(tp, tabCounter);
  1530. sr.Reset; tabCounter := 0;
  1531. WHILE (sr.res = Streams.Ok) DO
  1532. sr.SkipWhitespace; sr.String(token);
  1533. Strings.StrToInt(token, tabPos);
  1534. tp[tabCounter] := tabPos;
  1535. INC(tabCounter);
  1536. END;
  1537. NEW(tabs, tp)
  1538. END
  1539. END;
  1540. (* Get the Character Styles / Attributes *)
  1541. IF utilreader.cstyle # NIL THEN
  1542. cStyle := utilreader.cstyle;
  1543. IF (cStyle.fontcache #NIL) & (cStyle.fontcache IS WMGraphics.Font) THEN
  1544. f := cStyle.fontcache(WMGraphics.Font);
  1545. ELSE
  1546. f := WMGraphics.GetFont(cStyle.family, ENTIER(FP1616.FixpToFloat(cStyle.size)), cStyle.style);
  1547. utilreader.cstyle.fontcache := f
  1548. END;
  1549. ELSIF utilreader.pstyle # NIL THEN
  1550. IF pStyle.charStyle # NIL THEN
  1551. cStyle := pStyle.charStyle;
  1552. IF (cStyle.fontcache #NIL) &
  1553. (cStyle.fontcache IS WMGraphics.Font) THEN
  1554. f := cStyle.fontcache(WMGraphics.Font);
  1555. ELSE
  1556. f := WMGraphics.GetFont(cStyle.family, ENTIER(FP1616.FixpToFloat(cStyle.size)), cStyle.style);
  1557. utilreader.pstyle.charStyle.fontcache := f
  1558. END
  1559. END;
  1560. ELSIF utilreader.attributes # NIL THEN
  1561. IF utilreader.attributes.fontInfo # NIL THEN
  1562. IF (utilreader.attributes.fontInfo.fontcache # NIL)
  1563. & (utilreader.attributes.fontInfo.fontcache IS WMGraphics.Font) THEN
  1564. f := utilreader.attributes.fontInfo.fontcache(WMGraphics.Font);
  1565. ELSE
  1566. f := GetFontFromAttr(utilreader.attributes.fontInfo);
  1567. utilreader.attributes.fontInfo.fontcache := f
  1568. END
  1569. ELSE f := cf
  1570. END
  1571. ELSE f := cf;
  1572. END;
  1573. INC(pos);
  1574. GetWidth(ch, dx);
  1575. IF (ch = Texts.ObjectChar) THEN
  1576. word := Strings.Max(word, dx);
  1577. cls := cls + dx;
  1578. cws := 0
  1579. ELSIF (ch = Texts.NewLineChar) THEN
  1580. line := Strings.Max(line, cls);
  1581. cls := 0
  1582. ELSIF (ch = 32) THEN
  1583. word := Strings.Max(word, cws);
  1584. cws := 0
  1585. ELSE
  1586. cws := cws + dx;
  1587. cls := cls + dx;
  1588. END;
  1589. UNTIL utilreader.eot;
  1590. line := Strings.Max(line, cls);
  1591. word := Strings.Max(word, cws);
  1592. text.ReleaseRead;
  1593. END GetMinMaxWidth;
  1594. (* END view dependant layout functions *)
  1595. PROCEDURE LineYPos(lineNr : LONGINT; VAR y0, y1 : LONGINT);
  1596. VAR i : LONGINT;
  1597. BEGIN
  1598. IF (lineNr >= firstLineI) & (lineNr < layout.GetNofLines()) THEN
  1599. y0 := bordersI.t; i := firstLineI;
  1600. WHILE i < lineNr DO
  1601. y0 := y0 + layout.lines[i].height;
  1602. CheckParagraphBegin(i, y0);
  1603. CheckParagraphEnd(i, y0);
  1604. INC(i);
  1605. END;
  1606. y1 := y0 + layout.lines[i].height;
  1607. CheckParagraphBegin(i, y1);
  1608. ELSE y0 := 0; y1 := 0
  1609. END
  1610. END LineYPos;
  1611. PROCEDURE FindScreenPos*(pos : LONGINT; VAR x, y : LONGINT) : BOOLEAN;
  1612. VAR
  1613. l, i, startPos, intPos: LONGINT;
  1614. ty : LONGINT;
  1615. li : LineInfo;
  1616. thisCh, lastCh : Char32;
  1617. lastLine : BOOLEAN;
  1618. f : WMGraphics.Font;
  1619. gs: WMGraphics.GlyphSpacings;
  1620. BEGIN
  1621. text.AcquireRead;
  1622. lastLine := FALSE;
  1623. IF (pos = text.GetLength()) THEN
  1624. utilreader.SetDirection(1); utilreader.SetPosition(text.GetLength() - 1);
  1625. utilreader.ReadCh(thisCh);
  1626. IF thisCh = Texts.NewLineChar THEN lastLine := TRUE END
  1627. END;
  1628. IF lastLine THEN
  1629. ty := bordersI.t; i := firstLineI;
  1630. WHILE i < layout.nofLines DO
  1631. ty := ty + layout.lines[i].height;
  1632. CheckParagraphBegin(i, ty);
  1633. CheckParagraphEnd(i, ty);
  1634. INC(i);
  1635. END;
  1636. IF i > 0 THEN
  1637. y := (ty + layout.lines[i - 1].ascent)
  1638. ELSE
  1639. f := GetFont();
  1640. y := (ty + f.GetAscent());
  1641. END;
  1642. x := bordersI.l + x0 - leftShiftI;
  1643. text.ReleaseRead;
  1644. RETURN TRUE
  1645. ELSIF (pos = 0) & (firstLineI = 0) THEN
  1646. ty := bordersI.t;
  1647. IF layout.GetNofLines() > 0 THEN
  1648. y := (ty + layout.lines[0].ascent);
  1649. ELSE
  1650. f := GetFont();
  1651. y := ty+f.GetAscent();
  1652. END;
  1653. CheckParagraphBegin(0, y);
  1654. x := bordersI.l + x0 - leftShiftI;
  1655. text.ReleaseRead;
  1656. RETURN TRUE
  1657. ELSE
  1658. l := layout.FindLineNrByPos(pos);
  1659. IF (l >= firstLineI) & (l < layout.GetNofLines()) THEN
  1660. ty := bordersI.t; i := firstLineI;
  1661. WHILE i < l DO
  1662. ty := ty + layout.lines[i].height;
  1663. CheckParagraphBegin(i, ty);
  1664. CheckParagraphEnd(i, ty);
  1665. INC(i);
  1666. END;
  1667. y := (ty + layout.lines[i].ascent);
  1668. CheckParagraphBegin(i, y);
  1669. startPos := layout.GetLineStartPos(i);
  1670. f := GetFont();
  1671. intPos := GetInternalPos(pos);
  1672. utilreader.SetPosition(intPos-1);
  1673. utilreader.ReadCh(lastCh);
  1674. utilreader.ReadCh(thisCh);
  1675. (* if this character is rtl and its predecessor is ltr, move the position to the right of the previous character *)
  1676. IF (intPos # 0) & (IsRightToLeft(intPos) & ~IsRightToLeft(intPos-1) & (intPos # startPos)) OR
  1677. ((~IsRightToLeft(intPos) OR (thisCh = 0AH)) & ~IsRightToLeft(intPos-1) & ODD(GetParagraphEmbeddingLevel(pos))) THEN
  1678. LayoutLine(startPos, lastCh, li, layout.paperWidth, GetDisplayPos(intPos-1), -1);
  1679. IF f.HasChar(lastCh) THEN
  1680. f.GetGlyphSpacings(lastCh, gs);
  1681. ELSE
  1682. WMGraphics.FBGetGlyphSpacings(lastCh, gs);
  1683. END;
  1684. x := li.width + GetLineLeftIndent(l) + bordersI.l + x0 - leftShiftI + gs.bearing.l + gs.width + gs.bearing.r;
  1685. ELSIF (intPos # 0) & ((thisCh = 0AH) OR (thisCh = 0H)) & IsRightToLeft(intPos-1) THEN
  1686. LayoutLine(startPos, thisCh, li, layout.paperWidth, GetDisplayPos(intPos-1), -1);
  1687. x := (li.width + GetLineLeftIndent(l) + bordersI.l + x0 - leftShiftI);
  1688. (* if this and its predecessor are rtl, move the position to the right of this character *)
  1689. ELSIF IsRightToLeft(intPos) THEN
  1690. LayoutLine(startPos, thisCh, li, layout.paperWidth, pos, -1);
  1691. IF f.HasChar(thisCh) THEN
  1692. f.GetGlyphSpacings(thisCh, gs);
  1693. ELSE
  1694. WMGraphics.FBGetGlyphSpacings(thisCh, gs);
  1695. END;
  1696. x := li.width + GetLineLeftIndent(l) + bordersI.l + x0 - leftShiftI + gs.bearing.l + gs.width + gs.bearing.r;
  1697. (* if this character is ltr and its predecessor is rtl move the position to the left of the predecessor *)
  1698. ELSIF (intPos # 0) & (~IsRightToLeft(intPos) OR (thisCh = 0AH)) & IsRightToLeft(intPos-1) THEN
  1699. LayoutLine(startPos, thisCh, li, layout.paperWidth, GetDisplayPos(intPos-1), -1);
  1700. x := (li.width + GetLineLeftIndent(l) + bordersI.l + x0 - leftShiftI);
  1701. (* if this and the previous character are ltr, leave the position at the left of this character *)
  1702. ELSE
  1703. LayoutLine(startPos, thisCh, li, layout.paperWidth, pos, -1);
  1704. x := (li.width + GetLineLeftIndent(l) + bordersI.l + x0 - leftShiftI);
  1705. END;
  1706. text.ReleaseRead;
  1707. RETURN TRUE
  1708. ELSE
  1709. text.ReleaseRead;
  1710. RETURN FALSE
  1711. END
  1712. END
  1713. END FindScreenPos;
  1714. (* Get the internal position for a given display position. *)
  1715. PROCEDURE GetInternalPos*(pos : LONGINT) : LONGINT;
  1716. VAR
  1717. lineNr, startPos, lineLength : LONGINT;
  1718. dummyTextReader : Texts.TextReader;
  1719. BEGIN
  1720. (* if the text is non-utf formatted, the internal position and the display position are the same *)
  1721. IF ~text.isUTF OR (layout.bidiFormatter = NIL) THEN
  1722. RETURN pos;
  1723. END;
  1724. text.AcquireRead;
  1725. lineNr := layout.FindLineNrByPos(pos);
  1726. startPos := layout.GetLineStartPos(lineNr);
  1727. lineLength := layout.GetLineLength(lineNr);
  1728. dummyTextReader := layout.bidiFormatter.ReorderLine(startPos,lineLength);
  1729. text.ReleaseRead;
  1730. RETURN layout.bidiFormatter.GetInternalPosition(pos,startPos);
  1731. END GetInternalPos;
  1732. (* Get the display position for a given display position. *)
  1733. PROCEDURE GetDisplayPos*(pos : LONGINT) : LONGINT;
  1734. VAR
  1735. lineNr, startPos, lineLength : LONGINT;
  1736. dummyTextReader : Texts.TextReader;
  1737. BEGIN
  1738. (* if the text is non-utf formatted, the internal position and the display position are the same *)
  1739. IF ~text.isUTF OR (layout.bidiFormatter = NIL) THEN
  1740. RETURN pos;
  1741. END;
  1742. lineNr := layout.FindLineNrByPos(pos);
  1743. startPos := layout.GetLineStartPos(lineNr);
  1744. lineLength := layout.GetLineLength(lineNr);
  1745. dummyTextReader := layout.bidiFormatter.ReorderLine(startPos,lineLength);
  1746. RETURN layout.bidiFormatter.GetDisplayPosition(pos,startPos);
  1747. END GetDisplayPos;
  1748. (* Checks if the current position is in an rtl context *)
  1749. PROCEDURE IsRightToLeft*(pos : LONGINT) : BOOLEAN;
  1750. VAR
  1751. lineNr, startPos, lineLength : LONGINT;
  1752. dummyTextReader : Texts.TextReader;
  1753. BEGIN
  1754. IF ~text.isUTF OR (layout.bidiFormatter = NIL) THEN
  1755. RETURN FALSE;
  1756. END;
  1757. lineNr := layout.FindLineNrByPos(pos);
  1758. startPos := layout.GetLineStartPos(lineNr);
  1759. lineLength := layout.GetLineLength(lineNr);
  1760. IF layout.initialized THEN
  1761. dummyTextReader := layout.bidiFormatter.ReorderLine(startPos,lineLength);
  1762. END;
  1763. RETURN ODD(layout.bidiFormatter.GetImplicitLevel(pos));
  1764. END IsRightToLeft;
  1765. (* Gets the paragraph embedding level of the current position's line *)
  1766. PROCEDURE GetParagraphEmbeddingLevel*(pos : LONGINT) : LONGINT;
  1767. BEGIN
  1768. IF ~text.isUTF OR (layout.bidiFormatter = NIL) THEN
  1769. RETURN 0;
  1770. END;
  1771. RETURN layout.bidiFormatter.GetParagraphEmbeddingLevel(pos);
  1772. END GetParagraphEmbeddingLevel;
  1773. PROCEDURE LayoutLine(VAR pos : LONGINT; VAR ch : Char32; VAR l : LineInfo; wrapwidth, stopPos, stopXPos : LONGINT);
  1774. VAR
  1775. i, wrapPos : LONGINT;
  1776. eol, first : BOOLEAN;
  1777. ascent, descent, leading, ld, a, d, dx, x : LONGINT;
  1778. align, firstIndent, leftIndent, rightIndent, spaceBefore, spaceAfter : LONGINT;
  1779. tabstring : ARRAY 256 OF CHAR; tabs : CustomTabStops; tp : TabPositions;
  1780. sr : Streams.StringReader; tabCounter, tabPos : LONGINT; token : ARRAY 16 OF CHAR;
  1781. pStyle : Texts.ParagraphStyle;
  1782. start, stop, isFirst : BOOLEAN;
  1783. bidiTextReader, localTextReader : Texts.TextReader;
  1784. regionStart, regionEnd,lastEnd : LONGINT;
  1785. readerPosition : LONGINT;
  1786. highlighterStyle, lastHighlighterStyle : SyntaxHighlighter.Style;
  1787. currentStyle, lastStyle : ANY;
  1788. cf: WMGraphics.Font;
  1789. style : RECORD
  1790. voff : LONGINT;
  1791. font : WMGraphics.Font;
  1792. END;
  1793. PROCEDURE GetExtents(ch : Char32; VAR dx, ascent, descent: LONGINT);
  1794. VAR gs : WMGraphics.GlyphSpacings; vc : WMComponents.VisualComponent; font : WMGraphics.Font;
  1795. BEGIN
  1796. IF ch = Texts.ObjectChar THEN
  1797. IF (localTextReader.object # NIL) & (localTextReader.object IS WMGraphics.Image) THEN
  1798. ascent := localTextReader.object(WMGraphics.Image).height - style.voff;
  1799. descent := style.voff;
  1800. dx := localTextReader.object(WMGraphics.Image).width
  1801. ELSIF (localTextReader.object # NIL) & (localTextReader.object IS WMComponents.VisualComponent) THEN
  1802. vc := localTextReader.object(WMComponents.VisualComponent);
  1803. dx := vc.bounds.GetWidth();
  1804. ascent := vc.bounds.GetHeight() - style.voff;
  1805. descent := style.voff;
  1806. (* Add a Sequencer to the object if none exists *)
  1807. IF (vc.sequencer = NIL) OR (vc.sequencer # sequencer) THEN
  1808. vc.SetSequencer(sequencer);
  1809. IF sequencer#NIL THEN vc.Reset(NIL, NIL); END;
  1810. END;
  1811. END
  1812. ELSIF ch = Texts.TabChar THEN
  1813. IF l.tabStops # NIL THEN dx := l.tabStops.GetNextTabStop(x) - x
  1814. ELSE dx := defaultTabStops.GetNextTabStop(x) - x
  1815. END;
  1816. ascent := style.font.GetAscent() - style.voff;
  1817. descent := style.font.GetDescent() + style.voff
  1818. ELSIF ch = Texts.LabelChar THEN
  1819. IF showLabels.Get() THEN
  1820. font := cf;
  1821. font.GetStringSize(localTextReader.object(Texts.LabelPiece).label^, dx, ascent);
  1822. INC(dx, 4);
  1823. ELSE
  1824. ascent := 0; descent := 0;
  1825. dx := 0;
  1826. END;
  1827. ELSE
  1828. IF isPasswordI THEN ch := passwordChar.Get() END;
  1829. IF style.font.HasChar(ch) THEN
  1830. style.font.GetGlyphSpacings(ch, gs);
  1831. ELSE
  1832. WMGraphics.FBGetGlyphSpacings(ch, gs);
  1833. END;
  1834. ascent := gs.ascent - style.voff;
  1835. descent := gs.descent + style.voff;
  1836. dx := gs.bearing.l + gs.width + gs.bearing.r
  1837. END
  1838. END GetExtents;
  1839. BEGIN
  1840. style.voff := 0;
  1841. cf := GetFont();
  1842. style.font := cf;
  1843. x := 0; l.pos := pos; l.height := style.font.GetHeight();
  1844. (* For layouting a reordered line, the reordered text is needed, to correctly measure
  1845. the extends of each character. *)
  1846. IF text.isUTF & (layout.bidiFormatter # NIL) THEN
  1847. isFirst := FALSE;
  1848. bidiTextReader := layout.bidiFormatter.ReadyTextReader(pos,isFirst);
  1849. END;
  1850. (* if a reformatted text is available initialize it correpsondingly *)
  1851. IF (bidiTextReader # NIL) THEN
  1852. (* if a reordered line is available, the contextual dependency rules are applied *)
  1853. bidiTextReader.CloneProperties(utilreader);
  1854. localTextReader := bidiTextReader;
  1855. localTextReader.text.AcquireRead;
  1856. localTextReader.SetPosition(0);
  1857. (* or initialize to default otherwise *)
  1858. ELSE
  1859. localTextReader := utilreader;
  1860. localTextReader.SetPosition(pos);
  1861. END;
  1862. localTextReader.SetDirection(1); first := TRUE;
  1863. (* the bidi formatter needs special treatment when finding out about the first line of the paragraph *)
  1864. start := FALSE; stop := FALSE;
  1865. IF (pos = 0) THEN start := TRUE;
  1866. ELSIF (bidiTextReader = NIL) THEN
  1867. localTextReader.SetPosition(pos-1);
  1868. localTextReader.ReadCh(ch);
  1869. IF (ch = Texts.NewLineChar) THEN start := TRUE;
  1870. ELSE start := FALSE;
  1871. END;
  1872. ELSE (* bidiTextReader # NIL *)
  1873. IF isFirst THEN
  1874. start := TRUE;
  1875. ELSE
  1876. start := FALSE;
  1877. END;
  1878. END;
  1879. i := 0; leading := 0; ascent := style.font.GetAscent(); descent := style.font.GetDescent();
  1880. align := AlignLeft; l.tabStops := NIL; COPY("", tabstring);
  1881. firstIndent := 0; leftIndent := 0; rightIndent := 0; spaceBefore := 0; spaceAfter := 0;
  1882. lastEnd := -1;
  1883. highlighterStyle := NIL; lastHighlighterStyle := NIL;
  1884. currentStyle := NIL; lastStyle := NIL;
  1885. eol := FALSE;
  1886. REPEAT
  1887. readerPosition := localTextReader.GetPosition();
  1888. localTextReader.ReadCh(ch);
  1889. IF (highlighter # NIL) THEN
  1890. ASSERT(state # NIL);
  1891. IF (lastEnd < readerPosition) THEN
  1892. highlighterStyle := highlighter.GetRegionStyle(readerPosition, state, regionStart, regionEnd);
  1893. IF (highlighterStyle # NIL) THEN
  1894. lastEnd := regionEnd;
  1895. ELSE
  1896. IF (ch > 32) THEN
  1897. highlighterStyle := highlighter.GetWordStyle(localTextReader, readerPosition, lastEnd);
  1898. END;
  1899. END;
  1900. localTextReader.SetPosition(readerPosition);
  1901. localTextReader.ReadCh(ch); (* restore text reader state *)
  1902. END;
  1903. IF (highlighterStyle = NIL) THEN
  1904. highlighterStyle := highlighter.GetDefaultStyle();
  1905. END;
  1906. END;
  1907. (* Get the Paragraph Style *)
  1908. IF localTextReader.pstyle # NIL THEN
  1909. pStyle := localTextReader.pstyle;
  1910. (* pStyle := Texts.GetParagraphStyleByName(pStyle.name); *)
  1911. spaceBefore := ENTIER(FP1616.FixpToFloat(pStyle.spaceBefore));
  1912. spaceAfter := ENTIER(FP1616.FixpToFloat(pStyle.spaceAfter));
  1913. firstIndent := ENTIER(FP1616.FixpToFloat(pStyle.firstIndent));
  1914. leftIndent := ENTIER(FP1616.FixpToFloat(pStyle.leftIndent));
  1915. rightIndent := ENTIER(FP1616.FixpToFloat(pStyle.rightIndent));
  1916. align := pStyle.alignment;
  1917. (* parse tabstops *)
  1918. COPY(pStyle.tabStops, tabstring);
  1919. IF (tabstring # "default") & (tabstring # "0") & (tabstring # "") THEN
  1920. NEW(sr, LEN(tabstring)); sr.Set(tabstring); tabCounter := 0;
  1921. WHILE (sr.res = Streams.Ok) DO
  1922. sr.SkipWhitespace; sr.String(token);
  1923. INC(tabCounter);
  1924. END;
  1925. NEW(tp, tabCounter);
  1926. sr.Reset; tabCounter := 0;
  1927. WHILE (sr.res = Streams.Ok) DO
  1928. sr.SkipWhitespace; sr.String(token);
  1929. Strings.StrToInt(token, tabPos);
  1930. tp[tabCounter] := tabPos;
  1931. INC(tabCounter);
  1932. END;
  1933. NEW(tabs, tp);
  1934. IF l.tabStops = NIL THEN l.tabStops := tabs END
  1935. END;
  1936. END;
  1937. IF (highlighterStyle = NIL) OR (highlighterStyle.defined * SyntaxHighlighter.DefineMask # SyntaxHighlighter.DefineMask) THEN
  1938. IF localTextReader.cstyle # NIL THEN
  1939. IF (currentStyle # localTextReader.cstyle) THEN
  1940. currentStyle := localTextReader.cstyle;
  1941. style.voff := ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.baselineShift));
  1942. ld := ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.leading));
  1943. IF (localTextReader.cstyle.fontcache #NIL) & (localTextReader.cstyle.fontcache IS WMGraphics.Font) THEN
  1944. style.font := localTextReader.cstyle.fontcache(WMGraphics.Font);
  1945. ELSE
  1946. style.font := WMGraphics.GetFont(localTextReader.cstyle.family, ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.size)), localTextReader.cstyle.style);
  1947. localTextReader.cstyle.fontcache := style.font;
  1948. END;
  1949. END;
  1950. ELSIF localTextReader.pstyle # NIL THEN
  1951. IF pStyle.charStyle # NIL THEN
  1952. style.voff := ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.baselineShift));
  1953. ld := ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.leading));
  1954. IF (localTextReader.cstyle.fontcache #NIL) & (localTextReader.cstyle.fontcache IS WMGraphics.Font) THEN
  1955. style.font := localTextReader.cstyle.fontcache(WMGraphics.Font);
  1956. ELSE
  1957. style.font := WMGraphics.GetFont(localTextReader.cstyle.family, ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.size)), localTextReader.cstyle.style);
  1958. localTextReader.pstyle.charStyle.fontcache := style.font
  1959. END
  1960. END;
  1961. ELSIF localTextReader.attributes # NIL THEN
  1962. IF (currentStyle # localTextReader.attributes) THEN
  1963. currentStyle := localTextReader.attributes;
  1964. style.voff := localTextReader.attributes.voff;
  1965. ld := 0;
  1966. IF localTextReader.attributes.fontInfo # NIL THEN
  1967. IF (localTextReader.attributes.fontInfo.fontcache # NIL) & (localTextReader.attributes.fontInfo.fontcache IS WMGraphics.Font) THEN
  1968. style.font := localTextReader.attributes.fontInfo.fontcache(WMGraphics.Font);
  1969. ELSE
  1970. style.font := GetFontFromAttr(localTextReader.attributes.fontInfo);
  1971. localTextReader.attributes.fontInfo.fontcache := style.font;
  1972. END
  1973. ELSE
  1974. style.font := cf
  1975. END
  1976. END;
  1977. ELSE
  1978. IF (currentStyle # DefaultStyle) THEN
  1979. currentStyle := DefaultStyle;
  1980. style.voff := 0;
  1981. style.font := cf;
  1982. ld := 0;
  1983. END;
  1984. END;
  1985. ASSERT(style.font # NIL);
  1986. END;
  1987. IF (highlighterStyle # NIL) THEN
  1988. IF (highlighterStyle # lastHighlighterStyle) OR (currentStyle # lastStyle) THEN
  1989. IF SyntaxHighlighter.Voff IN highlighterStyle.defined THEN style.voff := highlighterStyle.attributes.voff; END;
  1990. IF (SyntaxHighlighter.FontMask * highlighterStyle.defined # {}) THEN
  1991. CheckFont(highlighterStyle, style.font, fontCache);
  1992. style.font := highlighterStyle.attributes.fontInfo.fontcache (WMGraphics.Font);
  1993. END;
  1994. END;
  1995. currentStyle := NIL;
  1996. END;
  1997. lastStyle := currentStyle;
  1998. lastHighlighterStyle := highlighterStyle;
  1999. IF first THEN
  2000. IF (ch = Texts.NewLineChar) OR (ch = 0) THEN
  2001. ascent := style.font.GetAscent(); descent := style.font.GetDescent();
  2002. ELSE
  2003. descent := 0; ascent := 0;
  2004. END;
  2005. IF start THEN wrapwidth := wrapwidth - firstIndent - rightIndent;
  2006. ELSE wrapwidth := wrapwidth - leftIndent - rightIndent;
  2007. END;
  2008. first := FALSE;
  2009. END;
  2010. INC(pos);
  2011. IF (stopPos < 0) OR (pos <= stopPos) THEN
  2012. IF (ch # Texts.NewLineChar) & (ch # 0) THEN
  2013. GetExtents(ch, dx, a, d); ascent := Strings.Max(ascent, a); descent := Strings.Max(descent, d);
  2014. IF ld = 0 THEN ld := ascent + descent; ELSE ld := Strings.Max(ld, ascent + descent); END; leading := Strings.Max(leading, ld);
  2015. IF isMultiLineI & (wrapModeI # NoWrap) & (i > 0) & (x0 + x + dx > wrapwidth) THEN
  2016. eol := TRUE; DEC(pos); wrapPos := pos;
  2017. (* Go left for last space *)
  2018. IF wrapModeI = WrapWord THEN
  2019. pos := TextUtilities.FindPosWordLeft(localTextReader, pos);
  2020. IF pos <= l.pos THEN pos := wrapPos (* no word break found. wrap at latest possible pos *)
  2021. ELSE (* decrease width to actual size.. *)
  2022. (* localTextReader.SetPosition(pos);
  2023. WHILE pos < wrapPos DO
  2024. localTextReader.ReadCh(ch); GetExtents(ch, dx, a, d); x := x - dx; INC(pos)
  2025. END
  2026. *) END
  2027. END
  2028. ELSE
  2029. IF (stopXPos >= 0) & (x + dx DIV 2 > stopXPos) THEN
  2030. DEC(pos);
  2031. (* the bidi formatted text's lock needs to be released explicitly *)
  2032. IF (bidiTextReader # NIL) THEN
  2033. localTextReader.text.ReleaseRead;
  2034. END;
  2035. RETURN
  2036. END;
  2037. INC(x, dx)
  2038. END;
  2039. ELSE
  2040. eol := TRUE;
  2041. stop := TRUE;
  2042. IF (stopXPos >= 0) THEN DEC(pos) END;
  2043. END;
  2044. ELSE
  2045. eol := TRUE
  2046. END;
  2047. INC(i);
  2048. UNTIL eol OR localTextReader.eot;
  2049. l.width := x;
  2050. l.ascent := ascent; l.height := leading; (* ascent + descent; *)
  2051. l.align := align; l.leftIndent := leftIndent; l.rightIndent := rightIndent;
  2052. IF l.height = 0 THEN l.height := style.font.GetHeight() END;
  2053. IF start THEN l.firstInParagraph := TRUE; l.firstIndent := firstIndent; l.spaceBefore := spaceBefore;
  2054. ELSE l.firstInParagraph := FALSE; END;
  2055. IF stop THEN l.lastInParagraph := TRUE; l.spaceAfter := spaceAfter;
  2056. ELSE l.lastInParagraph := FALSE END;
  2057. (* the bidi formatted text's lock needs to be released explicitly *)
  2058. IF (bidiTextReader # NIL) THEN
  2059. localTextReader.text.ReleaseRead;
  2060. END;
  2061. END LayoutLine;
  2062. (* llen = -1 to render until the end of line > 0 to render llen elements in the line *)
  2063. PROCEDURE RenderLine*(canvas : WMGraphics.Canvas; VAR l : LineInfo; linenr, top, llen : LONGINT);
  2064. VAR sx, dx, dy, x, sp, i, j, k, t, tx, linelength, w, p : LONGINT; char : Char32; gs: WMGraphics.GlyphSpacings;
  2065. font : WMGraphics.Font;
  2066. vc : WMComponents.VisualComponent;
  2067. hc : BOOLEAN;
  2068. bidiTextReader, localTextReader : Texts.TextReader;
  2069. cursorPosition : LONGINT;
  2070. regionStart, regionEnd, lastEnd: LONGINT;
  2071. readerPosition : LONGINT;
  2072. lineNumberString : ARRAY 16 OF CHAR;
  2073. canvasState : WMGraphics.CanvasState;
  2074. cliprect, temp : WMRectangles.Rectangle;
  2075. highlighterStyle, lastHighlighterStyle : SyntaxHighlighter.Style;
  2076. currentStyle, lastStyle : ANY;
  2077. lastColor : WMGraphics.Color;
  2078. cf: WMGraphics.Font;
  2079. style : RECORD
  2080. color, bgColor : WMGraphics.Color;
  2081. voff : LONGINT;
  2082. font : WMGraphics.Font;
  2083. END;
  2084. BEGIN
  2085. IF TraceRenderOptimize IN Trace THEN
  2086. KernelLog.String("RenderLine : "); KernelLog.Int(linenr, 5); KernelLog.String(" from position : ");
  2087. KernelLog.Int(layout.GetLineStartPos(linenr), 5); KernelLog.Ln;
  2088. END;
  2089. sp := l.pos;
  2090. IF sp >= text.GetLength() THEN RETURN END;
  2091. style.color := defaultTextColorI;
  2092. canvas.SetColor(style.color); lastColor := style.color;
  2093. style.bgColor := defaultTextBgColorI;
  2094. style.voff := 0;
  2095. cf := GetFont();
  2096. style.font := cf;
  2097. IF llen < 0 THEN
  2098. linelength := layout.GetLineLength(linenr);
  2099. (* hack for the bidi formatter *)
  2100. IF linenr = layout.GetNofLines() - 1 THEN
  2101. DEC(linelength);
  2102. END;
  2103. ELSE
  2104. linelength := llen
  2105. END;
  2106. (* if there is a bidi formatter, reorder the current line *)
  2107. IF text.isUTF & (layout.bidiFormatter # NIL) THEN
  2108. bidiTextReader := layout.bidiFormatter.ReorderLine(sp,linelength);
  2109. END;
  2110. (* the bidi text reader needs special treatment for the initialization *)
  2111. IF (bidiTextReader # NIL) THEN
  2112. (* after reordering the line, contextual dependency rules are applied *)
  2113. bidiTextReader := ContextualDependency.AnalyzeLine(bidiTextReader,-1,-1);
  2114. layout.bidiFormatter.SetReadyTextReader(sp,bidiTextReader);
  2115. bidiTextReader.CloneProperties(utilreader);
  2116. localTextReader := bidiTextReader;
  2117. localTextReader.text.AcquireRead;
  2118. localTextReader.SetPosition(0);
  2119. ELSE
  2120. (* revert the hack for the bidi formatter *)
  2121. IF (llen < 0) & (linenr = layout.GetNofLines() - 1) THEN
  2122. INC(linelength);
  2123. END;
  2124. localTextReader := utilreader;
  2125. localTextReader.text.AcquireRead;
  2126. localTextReader.SetPosition(sp);
  2127. END;
  2128. i := 0;
  2129. x := GetLineLeftIndent(linenr);
  2130. sx := - leftShiftI + bordersI.l + x0;
  2131. IF TraceBaseLine IN Trace THEN
  2132. canvas.Line(0, top + (l.ascent), bounds.GetWidth(), top + (l.ascent), 01F0000FFH, WMGraphics.ModeCopy)
  2133. END;
  2134. selection.Sort;
  2135. IF (cursor.visible) & (selection.b - selection.a <= 0) & (clBgCurrentLineI # 0) THEN
  2136. cursorPosition := cursor.GetPosition();
  2137. IF (l.pos <= cursorPosition) & (cursorPosition < l.pos + linelength) THEN
  2138. canvas.Fill(WMRectangles.MakeRect(0, top, bounds.GetWidth() - bordersI.r, top + l.height), clBgCurrentLineI, WMGraphics.ModeSrcOverDst);
  2139. END;
  2140. END;
  2141. IF showLineNumbersI THEN
  2142. canvas.SaveState(canvasState);
  2143. Strings.IntToStr(linenr + 1, lineNumberString);
  2144. temp := WMRectangles.MakeRect(bordersI.l, top, x0 - 1, top + l.height);
  2145. IF (lineNumberBgColorI # 0) THEN
  2146. canvas.Fill(temp, lineNumberBgColorI, WMGraphics.ModeSrcOverDst);
  2147. END;
  2148. temp.r := temp.r - 4;
  2149. IF ((linenr + 1) MOD 10 = 0) THEN
  2150. canvas.SetFont(lineNumberFont10);
  2151. ELSE
  2152. canvas.SetFont(lineNumberFont);
  2153. END;
  2154. canvas.SetColor(lineNumberColorI);
  2155. WMGraphics.DrawStringInRect(canvas, temp, FALSE, WMGraphics.AlignRight, WMGraphics.AlignCenter, lineNumberString);
  2156. canvas.RestoreState(canvasState); (* restore font and font color *)
  2157. canvas.SaveState(canvasState);
  2158. canvas.GetClipRect(cliprect);
  2159. cliprect.l := x0;
  2160. canvas.SetClipRect(cliprect);
  2161. END;
  2162. w := bounds.GetWidth() - bordersI.r;
  2163. localTextReader.SetDirection(1);
  2164. lastEnd := -1;
  2165. highlighterStyle := NIL; lastHighlighterStyle := NIL;
  2166. currentStyle := DefaultStyle; lastStyle := NIL;
  2167. REPEAT
  2168. readerPosition := localTextReader.GetPosition();
  2169. localTextReader.ReadCh(char);
  2170. IF (highlighter # NIL) THEN
  2171. ASSERT(state # NIL);
  2172. IF (lastEnd < readerPosition) THEN
  2173. highlighterStyle := highlighter.GetRegionStyle(readerPosition, state, regionStart, regionEnd);
  2174. IF (highlighterStyle # NIL) THEN
  2175. lastEnd := regionEnd;
  2176. ELSE
  2177. IF (char > 32) THEN
  2178. highlighterStyle := highlighter.GetWordStyle(localTextReader, readerPosition, lastEnd);
  2179. END;
  2180. END;
  2181. localTextReader.SetPosition(readerPosition);
  2182. localTextReader.ReadCh(char); (* restore text reader state *)
  2183. END;
  2184. IF (highlighterStyle = NIL) THEN
  2185. highlighterStyle := highlighter.GetDefaultStyle();
  2186. END;
  2187. END;
  2188. IF (highlighterStyle = NIL) OR (highlighterStyle.defined * SyntaxHighlighter.DefineMask # SyntaxHighlighter.DefineMask) THEN
  2189. IF (localTextReader.cstyle # NIL) THEN
  2190. IF (currentStyle # localTextReader.cstyle) THEN
  2191. currentStyle := localTextReader.cstyle;
  2192. style.color := localTextReader.cstyle.color;
  2193. style.bgColor := localTextReader.cstyle.bgColor;
  2194. style.voff := localTextReader.cstyle.baselineShift;
  2195. IF (localTextReader.cstyle.fontcache # NIL) & (localTextReader.cstyle.fontcache IS WMGraphics.Font) THEN
  2196. style.font := localTextReader.cstyle.fontcache(WMGraphics.Font);
  2197. ELSE
  2198. style.font := WMGraphics.GetFont(localTextReader.cstyle.family, ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.size)), localTextReader.cstyle.style);
  2199. localTextReader.cstyle.fontcache := style.font;
  2200. END;
  2201. END;
  2202. ELSIF (localTextReader.attributes # NIL) THEN
  2203. IF (currentStyle # localTextReader.attributes) THEN
  2204. currentStyle := localTextReader.attributes;
  2205. style.color := localTextReader.attributes.color;
  2206. style.bgColor := localTextReader.attributes.bgcolor;
  2207. style.voff := localTextReader.attributes.voff;
  2208. IF (localTextReader.attributes.fontInfo # NIL) THEN
  2209. IF (localTextReader.attributes.fontInfo.fontcache # NIL) & (localTextReader.attributes.fontInfo.fontcache IS WMGraphics.Font) THEN
  2210. style.font := localTextReader.attributes.fontInfo.fontcache (WMGraphics.Font);
  2211. ELSE
  2212. style.font := GetFontFromAttr(localTextReader.attributes.fontInfo);
  2213. localTextReader.attributes.fontInfo.fontcache := style.font;
  2214. END;
  2215. ELSE
  2216. style.font := cf;
  2217. END;
  2218. END;
  2219. ELSE
  2220. IF (currentStyle # DefaultStyle) THEN
  2221. currentStyle := DefaultStyle;
  2222. style.color := defaultTextColorI;
  2223. style.bgColor := defaultTextBgColorI;
  2224. style.voff := 0;
  2225. style.font := cf;
  2226. END;
  2227. END;
  2228. ASSERT(style.font # NIL);
  2229. END;
  2230. IF (highlighterStyle # NIL) THEN
  2231. IF (highlighterStyle # lastHighlighterStyle) OR (currentStyle # lastStyle) THEN
  2232. IF SyntaxHighlighter.Voff IN highlighterStyle.defined THEN style.voff := highlighterStyle.attributes.voff; END;
  2233. IF SyntaxHighlighter.Color IN highlighterStyle.defined THEN style.color := highlighterStyle.attributes.color; END;
  2234. IF SyntaxHighlighter.BgColor IN highlighterStyle.defined THEN style.bgColor := highlighterStyle.attributes.bgcolor; END;
  2235. IF (SyntaxHighlighter.FontMask * highlighterStyle.defined # {}) THEN
  2236. CheckFont(highlighterStyle, style.font, fontCache);
  2237. style.font := highlighterStyle.attributes.fontInfo.fontcache (WMGraphics.Font);
  2238. END;
  2239. END;
  2240. currentStyle := NIL; (* force reevaluation of localTextReader style *)
  2241. END;
  2242. lastStyle := currentStyle;
  2243. lastHighlighterStyle := highlighterStyle;
  2244. IF (style.color # lastColor) THEN canvas.SetColor(style.color); lastColor := style.color; END;
  2245. IF char = Texts.ObjectChar THEN
  2246. IF (localTextReader.object # NIL) & (localTextReader.object IS WMGraphics.Image) THEN
  2247. canvas.DrawImage(x, top + (l.ascent) + style.voff - localTextReader.object(WMGraphics.Image).height, localTextReader.object(WMGraphics.Image),
  2248. WMGraphics.ModeSrcOverDst);
  2249. dx := localTextReader.object(WMGraphics.Image).width
  2250. ELSIF (localTextReader.object # NIL) & (localTextReader.object IS WMComponents.VisualComponent) THEN
  2251. vc := localTextReader.object(WMComponents.VisualComponent);
  2252. dx := vc.bounds.GetWidth();
  2253. dy := vc.bounds.GetHeight();
  2254. canvas.SaveState(clipState); (* save the current clip-state *)
  2255. canvas.SetClipRect(WMRectangles.MakeRect(x + sx, top + (l.ascent - dy), x + dx + sx, top + (l.height)));
  2256. canvas.ClipRectAsNewLimits(x + sx, top + (l.ascent - dy));
  2257. (* assuming the component will not delay --> otherwise a buffer is needed *)
  2258. vc.Acquire; vc.Draw(canvas); vc.Release;
  2259. canvas.RestoreState(clipState)
  2260. END
  2261. ELSIF char = 0 THEN (* EOT *)
  2262. ELSIF char = Texts.TabChar THEN
  2263. tx := x;
  2264. IF l.firstInParagraph THEN tx := tx - l.firstIndent
  2265. ELSE tx := tx - l.leftIndent END;
  2266. IF l.tabStops # NIL THEN dx := l.tabStops.GetNextTabStop(tx) - tx
  2267. ELSE dx := defaultTabStops.GetNextTabStop(tx) - tx
  2268. END;
  2269. IF style.bgColor # 0 THEN
  2270. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), style.bgColor, WMGraphics.ModeSrcOverDst)
  2271. END;
  2272. IF indicateTabsI THEN canvas.SetPixel(x + sx + ((dx + 1) DIV 2), top + ((l.ascent + 1) DIV 2), WMGraphics.Blue, WMGraphics.ModeCopy); END;
  2273. ELSIF char = Texts.LabelChar THEN
  2274. IF showLabels.Get() THEN
  2275. font := cf;
  2276. font.GetStringSize(localTextReader.object(Texts.LabelPiece).label^, dx, dy);
  2277. font.RenderString(canvas, x + sx+2, top + (l.ascent), localTextReader.object(Texts.LabelPiece).label^);
  2278. INC(dx, 4);
  2279. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), LONGINT(0FF880050H), WMGraphics.ModeSrcOverDst);
  2280. WMGraphicUtilities.RectGlassShade(canvas, WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), 1, FALSE)
  2281. ELSE dx := 0; END;
  2282. ELSE
  2283. IF char = Texts.NewLineChar THEN
  2284. localTextReader.text.ReleaseRead;
  2285. IF showLineNumbersI THEN canvas.RestoreState(canvasState); END;
  2286. RETURN
  2287. END;
  2288. IF isPasswordI THEN
  2289. char := passwordChar.Get()
  2290. END;
  2291. (* If the text is utf-formatted get the display version of the character.
  2292. Note, that only some special invisible characters differ from their actual representation. *)
  2293. IF text.isUTF THEN
  2294. UnicodeBidirectionality.GetDisplayCharacter(char);
  2295. END;
  2296. hc := style.font.HasChar(char);
  2297. IF hc THEN style.font.GetGlyphSpacings(char, gs)
  2298. ELSE WMGraphics.FBGetGlyphSpacings(char, gs)
  2299. END;
  2300. dx := gs.bearing.l + gs.width + gs.bearing.r;
  2301. IF style.bgColor MOD 256 # 0 THEN
  2302. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), style.bgColor, WMGraphics.ModeCopy)
  2303. END;
  2304. IF hc THEN style.font.RenderChar(canvas, x + sx, top + (l.ascent) + style.voff, char)
  2305. ELSE WMGraphics.FBRenderChar(canvas, x + sx, top + (l.ascent) + style.voff, char)
  2306. END
  2307. END;
  2308. (* link *)
  2309. IF localTextReader.link # NIL THEN
  2310. canvas.Line(x + sx, top + (l.ascent)+1, x + dx + sx, top + (l.ascent)+1, canvas.color, WMGraphics.ModeSrcOverDst);
  2311. END;
  2312. (* highlight - since highlights store the global text position, the line's starting position needs to be added,
  2313. when operating on the local, bidirectional text reader. *)
  2314. IF bidiTextReader # NIL THEN
  2315. p := GetInternalPos(localTextReader.GetPosition()+sp-1);
  2316. ELSE
  2317. p := localTextReader.GetPosition() - 1;
  2318. END;
  2319. FOR j := 0 TO nofHighlights - 1 DO
  2320. IF (p >= highlights[j].a) & (p < highlights[j].b) THEN
  2321. CASE highlights[j].kind OF
  2322. |HLOver: canvas.Fill(WMGraphics.MakeRectangle(x + sx, top, x + dx + sx, top + (l.height)), highlights[j].color, WMGraphics.ModeSrcOverDst)
  2323. |HLUnder: canvas.Line(x + sx, top + (l.ascent), x + dx + sx, top + (l.ascent), highlights[j].color, WMGraphics.ModeSrcOverDst);
  2324. |HLWave:
  2325. FOR k := 0 TO dx - 1 DO
  2326. t := 1 - ABS((x + k) MOD 4 - 2); (* because of compiler bug on intel *)
  2327. canvas.SetPixel(x + k + sx, top + l.ascent + t, highlights[j].color, WMGraphics.ModeSrcOverDst);
  2328. END;
  2329. ELSE
  2330. END
  2331. END
  2332. END;
  2333. x := x + dx;
  2334. INC(i)
  2335. UNTIL (i >= linelength) OR localTextReader.eot OR (x + sx > w);
  2336. localTextReader.text.ReleaseRead;
  2337. IF showLineNumbersI THEN canvas.RestoreState(canvasState); END;
  2338. END RenderLine;
  2339. PROCEDURE RenderAboveTextMarkers*(canvas : WMGraphics.Canvas);
  2340. VAR x, y, l, pos, i, ascent : LONGINT;
  2341. BEGIN
  2342. AssertLock;
  2343. IF text = NIL THEN RETURN END;
  2344. IF optimize THEN RETURN END;
  2345. text.AcquireRead;
  2346. FOR i := nofPositionMarkers - 1 TO 0 BY -1 DO
  2347. pos := positionMarkers[i].pos.GetPosition();
  2348. l := layout.FindLineNrByPos(pos);
  2349. IF FindScreenPos(pos, x, y) THEN
  2350. IF (l >= 0) & (l < layout.GetNofLines()) THEN
  2351. ascent := layout.lines[l].ascent;
  2352. (* IF ascent = 0 THEN ascent := layout.lines[l].height END;
  2353. IF ascent = 0 THEN ascent := 10 END; *)
  2354. ELSE ascent := 10 END;
  2355. positionMarkers[i].Draw(canvas, x, y, ascent)
  2356. END
  2357. END;
  2358. text.ReleaseRead;
  2359. END RenderAboveTextMarkers;
  2360. PROCEDURE DrawBackground*(canvas : WMGraphics.Canvas);
  2361. VAR la, lb, i, top, t, b : LONGINT; rect, clip : WMRectangles.Rectangle; cstate : WMGraphics.CanvasState;
  2362. BEGIN
  2363. ASSERT(layout # NIL);
  2364. canvas.GetClipRect(clip);
  2365. IF WMRectangles.RectEmpty(clip) THEN RETURN END;
  2366. rect := GetClientRect();
  2367. canvas.SaveState(cstate);
  2368. IF WMRectangles.Intersect(rect, clip) THEN
  2369. DrawBackground^(canvas);
  2370. IF showBorderI THEN
  2371. WMGraphicUtilities.DrawBevel(canvas, rect,
  2372. 1, TRUE, LONGINT(0808080FFH), WMGraphics.ModeCopy)
  2373. END;
  2374. END;
  2375. (* allow clean clipping in at inner border *)
  2376. WMRectangles.ClipRect(rect, borderClip);
  2377. WMRectangles.ClipRect(clip, borderClip);
  2378. canvas.SetClipRect(clip);
  2379. (* draw gutter *)
  2380. rect.r := x0 - 1;
  2381. IF showLineNumbersI & (lineNumberBgColorI # 0) & WMRectangles.Intersect(rect, clip) THEN
  2382. canvas.Fill(rect, lineNumberBgColorI, WMGraphics.ModeSrcOverDst);
  2383. END;
  2384. text.AcquireRead;
  2385. la := FindLineByY(firstLineI, clip.t);
  2386. lb := FindLineByY(firstLineI, clip.b);
  2387. (* prepare selections *)
  2388. FOR i := 0 TO nofHighlights - 1 DO
  2389. highlights[i].a := highlights[i].from.GetPosition();
  2390. highlights[i].b := highlights[i].to.GetPosition();
  2391. IF highlights[i].a > highlights[i].b THEN t := highlights[i].a; highlights[i].a := highlights[i].b; highlights[i].b := t END
  2392. END;
  2393. top := borderClip.t;
  2394. IF (la = lb) & (textAlignV.Get() = WMGraphics.AlignCenter) THEN
  2395. top := (borderClip.t+borderClip.b-layout.lines[la].height) DIV 2;
  2396. (* something is wrong with ascent and height here, does not comply with the notions in fonts *)
  2397. END;
  2398. FOR i := firstLineI TO la - 1 DO
  2399. top := top + (layout.lines[i].height);
  2400. CheckParagraphBegin(i, top);
  2401. CheckParagraphEnd(i, top);
  2402. END;
  2403. IF la >= 0 THEN
  2404. (* draw the lines that intersect the clipping rectangle *)
  2405. FOR i := la TO lb DO
  2406. CheckParagraphBegin(i, top);
  2407. RenderLine(canvas, layout.lines[i], i, top, -1);
  2408. top := top + (layout.lines[i].height);
  2409. CheckParagraphEnd(i, top);
  2410. END
  2411. END;
  2412. RenderAboveTextMarkers(canvas);
  2413. text.ReleaseRead;
  2414. canvas.RestoreState(cstate);
  2415. END DrawBackground;
  2416. PROCEDURE StoreLineEnter;
  2417. VAR pos, cl : LONGINT;
  2418. BEGIN
  2419. pos := cursor.GetPosition();
  2420. cl := layout.FindLineNrByPos(pos);
  2421. lineEnter := pos - layout.GetLineStartPos(cl)
  2422. END StoreLineEnter;
  2423. (* navigation *)
  2424. PROCEDURE WheelMove*(dz: LONGINT); (** PROTECTED *)
  2425. VAR ddz: DZ;
  2426. BEGIN
  2427. IF modifierFlags * Inputs.Ctrl # {} THEN (* CTRL pressed -> Resize Font*)
  2428. text.AcquireWrite;
  2429. IF dz > 0 THEN dz := 1 ELSIF dz<0 THEN dz := -1 END;
  2430. NEW(ddz, dz);
  2431. text.UpdateAttributes(0, text.GetLength(), ChangeAttribute, ddz);
  2432. text.ReleaseWrite;
  2433. ELSIF mouseWheelScrollSpeedI # 0 THEN
  2434. firstLine.Set(firstLine.Get() + mouseWheelScrollSpeedI * dz)
  2435. END;
  2436. END WheelMove;
  2437. (* abort a possible start of a command. Clear the command start indicator, if it was set *)
  2438. PROCEDURE AbortStart;
  2439. BEGIN
  2440. ASSERT(IsCallFromSequencer());
  2441. IF commandMarker # NIL THEN
  2442. RemoveHighlight(commandMarker);
  2443. commandMarker := NIL
  2444. END;
  2445. canStart := FALSE
  2446. END AbortStart;
  2447. (*
  2448. Handle double-click at text position <pos>.
  2449. Select the double-clicked word, whitespace or line.
  2450. Some explanations:
  2451. Why utilreader.GetPosition()+2 when searching to the left?
  2452. After we read the last character that should be included, the position of the reader is decremented.
  2453. When we now read the next character and see that it should not be included, the reader is decremented again.
  2454. -> The last character to be included was found at position utilreader.GetPosition()+2 (except when we reach EOT)
  2455. The same applies when search to the right. But to highlight the character at, for example, position 4, we need a highlight from 4-5.
  2456. That's why utilreader.GetPosition()-1 is used instead of utilreader.GetPosition()-2.
  2457. *)
  2458. PROCEDURE DoubleClickSelect(pos : LONGINT);
  2459. CONST
  2460. LineFeed = 0AH;
  2461. Underscore = 05FH;
  2462. VAR
  2463. char : Texts.Char32;
  2464. from, to : LONGINT;
  2465. BEGIN
  2466. ASSERT(text.HasReadLock());
  2467. utilreader.SetPosition(pos);
  2468. utilreader.SetDirection(1);
  2469. utilreader.ReadCh(char);
  2470. IF (char = LineFeed) OR utilreader.eot THEN (* select line *)
  2471. IF utilreader.eot THEN to := pos;
  2472. ELSE to := pos+1;
  2473. END;
  2474. from := TextUtilities.FindPosLineStart(utilreader, pos);
  2475. ELSIF TextUtilities.IsWhiteSpace(char,text.isUTF) THEN
  2476. WHILE ~utilreader.eot & TextUtilities.IsWhiteSpace(char,text.isUTF) & (char # LineFeed) DO utilreader.ReadCh(char); END;
  2477. IF utilreader.eot THEN to := utilreader.text.GetLength();
  2478. ELSE to := utilreader.GetPosition()-1;
  2479. END;
  2480. utilreader.SetPosition(pos);
  2481. utilreader.SetDirection(-1);
  2482. utilreader.ReadCh(char);
  2483. WHILE ~utilreader.eot & TextUtilities.IsWhiteSpace(char,text.isUTF) & (char # LineFeed) DO utilreader.ReadCh(char); END;
  2484. IF utilreader.eot THEN from := 0;
  2485. ELSE from := utilreader.GetPosition()+2;
  2486. END;
  2487. ELSIF TextUtilities.IsAlphaNum(char) OR (char = Underscore) THEN (* select word *)
  2488. WHILE ~utilreader.eot & (TextUtilities.IsAlphaNum(char) OR (char = Underscore)) DO utilreader.ReadCh(char); END;
  2489. IF utilreader.eot THEN to := utilreader.text.GetLength();
  2490. ELSE to := utilreader.GetPosition()-1;
  2491. END;
  2492. utilreader.SetPosition(pos);
  2493. utilreader.SetDirection(-1);
  2494. utilreader.ReadCh(char);
  2495. WHILE ~utilreader.eot & (TextUtilities.IsAlphaNum(char) OR (char = Underscore)) DO utilreader.ReadCh(char); END;
  2496. IF utilreader.eot THEN from := 0;
  2497. ELSE from := utilreader.GetPosition()+2;
  2498. END;
  2499. ELSE (* select the character at text position pos *)
  2500. from := pos; to := pos+1;
  2501. END;
  2502. selection.SetFromTo(from, to);
  2503. cursor.SetVisible(to - from > 0);
  2504. END DoubleClickSelect;
  2505. PROCEDURE SetInterclick(new : LONGINT);
  2506. VAR old : LONGINT;
  2507. BEGIN
  2508. old := interclick;
  2509. IF (old # new) THEN
  2510. interclick := new;
  2511. CASE new OF
  2512. | Interclick01: selection.SetColor(SelectionColorInterclick01);
  2513. | Interclick02: selection.SetColor(SelectionColorInterclick02);
  2514. ELSE
  2515. selection.SetColor(SelectionColor);
  2516. END;
  2517. END;
  2518. END SetInterclick;
  2519. PROCEDURE PointerDown*(x, y : LONGINT; keys : SET);
  2520. VAR pos, a, b, internalPos : LONGINT; oldInterclick : LONGINT;
  2521. BEGIN
  2522. ViewToTextPos(x,y,pos);
  2523. internalPos := GetInternalPos(pos);
  2524. oldInterclick := interclick;
  2525. IF (keys * {0, 1} = {0,1}) THEN SetInterclick(Interclick01);
  2526. ELSIF (keys * {0,2} = {0,2}) THEN SetInterclick(Interclick02);
  2527. ELSE SetInterclick(InterclickNone);
  2528. END;
  2529. (* Determine whether to cancel an interclick if any *)
  2530. IF (oldInterclick = InterclickCancelled) OR
  2531. ((oldInterclick # InterclickNone) & (interclick # InterclickNone)) THEN
  2532. SetInterclick(InterclickCancelled);
  2533. END;
  2534. IF allowCommandExecution.Get() & (keys * {0, 1, 2} = {1}) THEN
  2535. canStart := TRUE; openFile := FALSE;
  2536. IF commandMarker = NIL THEN
  2537. commandMarker := CreateHighlight();
  2538. commandMarker.SetKind(HLUnder);
  2539. commandMarker.SetColor(LONGINT(0FF0000FFH));
  2540. text.AcquireRead;
  2541. FindCommand(internalPos, a, b);
  2542. commandMarker.SetFromTo(a, b);
  2543. cursor.SetPosition(pos);
  2544. text.ReleaseRead
  2545. END;
  2546. END;
  2547. IF canStart & (2 IN keys) THEN openFile := TRUE; SetInterclick(InterclickCancelled); END;
  2548. IF keys * {0, 1, 2} = {0, 1, 2} THEN AbortStart END;
  2549. IF allowPiemenu.Get() & (keys * {0, 1, 2} = {2}) THEN
  2550. text.AcquireRead;
  2551. ViewToTextPos(x, y, pos);
  2552. cursor.SetPosition(pos);
  2553. text.ReleaseRead;
  2554. ShowContextMenu(x, y)
  2555. END;
  2556. IF allowTextSelection.Get() &
  2557. ( (keys * {0, 1, 2} = {0}) (* left mouse for select *)
  2558. OR (keys * {0, 1, 2} = {1}) & doubleclickedWord (* remove selection when double clicking *)
  2559. OR (keys * {0,1,2} = {2}) & (~allowPiemenu.Get())) (* right mouse for selection if pie menu is not enabled *)
  2560. THEN
  2561. AbortStart;
  2562. text.AcquireRead;
  2563. ViewToTextPos(x, y, pos);
  2564. dragPossible := FALSE; selectWords := FALSE;
  2565. IF internalPos >= 0 THEN
  2566. selection.Sort;
  2567. IF (internalPos >= selection.a) & (internalPos < selection.b) & (interclick = InterclickNone) THEN
  2568. dragPossible := TRUE; downX := x; downY := y
  2569. ELSIF (interclick = InterclickNone) THEN
  2570. (* clicking the same position twice --> Word Selection Mode *)
  2571. IF (internalPos = GetInternalPos(cursor.GetPosition())) OR ((internalPos - 1 = GetInternalPos(cursor.GetPosition())) & (internalPos - 1 = text.GetLength())) THEN
  2572. (* Workaround: The 2nd check is for the very last line of a text. LayoutLine gives pos = text.GetLength()+1 *)
  2573. selectWords := TRUE; wordSelOrdered := TRUE;
  2574. doubleclickedWord := TRUE;
  2575. DoubleClickSelect(internalPos);
  2576. ELSE
  2577. selection.SetFromTo(internalPos, internalPos); (* reset selection *)
  2578. cursor.SetVisible(TRUE);
  2579. END;
  2580. selecting := TRUE;
  2581. END
  2582. END;
  2583. cursor.SetPosition(pos);
  2584. text.ReleaseRead;
  2585. CursorChanged
  2586. END;
  2587. END PointerDown;
  2588. PROCEDURE PointerMove*(x, y : LONGINT; keys : SET);
  2589. VAR pos, a, b, internalPos : LONGINT;
  2590. BEGIN
  2591. IF ~canStart & dragPossible THEN
  2592. IF (ABS(x - downX) > DragDist) OR (ABS(y - downY) > DragDist) THEN dragPossible := FALSE; AutoStartDrag END
  2593. ELSE
  2594. IF (selecting OR canStart) & (interclick = InterclickNone) THEN
  2595. text.AcquireRead;
  2596. ViewToTextPos(x, y, pos);
  2597. internalPos := GetInternalPos(pos);
  2598. IF selecting & ~doubleclickedWord THEN
  2599. selection.Sort;
  2600. IF selectWords THEN
  2601. IF internalPos < selection.from.GetPosition() THEN
  2602. pos := TextUtilities.FindPosWordLeft(utilreader, internalPos - 1);
  2603. ELSE
  2604. pos := TextUtilities.FindPosWordRight(utilreader, internalPos + 1);
  2605. END;
  2606. selection.SetTo(internalPos)
  2607. ELSE
  2608. selection.SetTo(internalPos);
  2609. END;
  2610. selection.Sort;
  2611. cursor.SetVisible(selection.b - selection.a <= 0);
  2612. Texts.SetLastSelection(text, selection.from, selection.to);
  2613. cursor.SetPosition(pos);
  2614. StoreLineEnter;
  2615. ELSIF canStart THEN
  2616. IF commandMarker # NIL THEN
  2617. FindCommand(internalPos, a, b);
  2618. commandMarker.SetFromTo(a, b)
  2619. END
  2620. END;
  2621. IF doubleclickedWord THEN doubleclickedWord := FALSE; END; (* allow selecting again *)
  2622. text.ReleaseRead;
  2623. CursorChanged
  2624. END
  2625. END
  2626. END PointerMove;
  2627. PROCEDURE PointerUp*(x, y : LONGINT; keys : SET);
  2628. BEGIN
  2629. IF canStart & (commandMarker # NIL) THEN
  2630. commandMarker.Sort;
  2631. StartCommand((commandMarker.a + commandMarker.b) DIV 2, openFile);
  2632. AbortStart
  2633. END;
  2634. IF modifierFlags * Inputs.Ctrl # {} THEN
  2635. onCtrlClicked.Call(NIL)
  2636. END;
  2637. selecting := FALSE;
  2638. doubleclickedWord := FALSE;
  2639. IF (keys * {0,1,2} = {}) THEN
  2640. IF (interclick = Interclick02) THEN
  2641. DeleteSelection;
  2642. END;
  2643. SetInterclick(InterclickNone);
  2644. END;
  2645. IF dragPossible THEN selection.SetFromTo(0, 0); cursor.SetVisible(TRUE); Texts.ClearLastSelection (* reset selection *) END;
  2646. dragPossible := FALSE
  2647. END PointerUp;
  2648. (* Transforms the TextView Coordinates into TextObject obj Coordinates *)
  2649. PROCEDURE TransformCoordinates(VAR x, y : LONGINT; obj : WMComponents.VisualComponent);
  2650. VAR line, pos, x0, y0, y1 : LONGINT;
  2651. BEGIN
  2652. ViewToTextPos(x, y, pos);
  2653. IF FindScreenPos(pos, x0, y0) THEN
  2654. IF x0 > x THEN pos := pos - 1;
  2655. IF FindScreenPos(pos, x0, y0) THEN END;
  2656. END;
  2657. line := layout.FindLineNrByPos(GetInternalPos(pos));
  2658. LineYPos(line, y0, y1);
  2659. x := x - x0;
  2660. y := y - y0;
  2661. IF line >= 0 THEN y := y - (layout.lines[line].ascent - obj.bounds.GetHeight()); END
  2662. END
  2663. END TransformCoordinates;
  2664. (* Change the pointer according to the underlaying component *)
  2665. PROCEDURE ChangePointer(pointerInfo : WMWindowManager.PointerInfo);
  2666. BEGIN
  2667. IF GetPointerInfo() # pointerInfo THEN
  2668. SetPointerInfo(pointerInfo)
  2669. END
  2670. END ChangePointer;
  2671. (* Returns TRUE if an Object is Hit, FALSE otherwise *)
  2672. PROCEDURE HitObject(x, y : LONGINT; (* keys : SET;*) VAR pos : LONGINT; VAR obj : ANY): BOOLEAN;
  2673. VAR ch, tx, ty : LONGINT;
  2674. BEGIN
  2675. text.AcquireRead;
  2676. ViewToTextPos(x, y, pos);
  2677. IF FindScreenPos(pos, tx, ty) THEN
  2678. IF tx > x THEN pos := pos - 1 END
  2679. END;
  2680. utilreader.SetPosition(GetInternalPos(pos));
  2681. utilreader.ReadCh(ch);
  2682. text.ReleaseRead;
  2683. IF ch = Texts.ObjectChar THEN obj := utilreader.object;
  2684. RETURN TRUE
  2685. ELSE
  2686. RETURN FALSE
  2687. END
  2688. END HitObject;
  2689. (* Returns TRUE if a Link is Hit, FALSE otherwise *)
  2690. PROCEDURE HitLink(x, y : LONGINT; VAR pos : LONGINT; VAR link : Texts.Link): BOOLEAN;
  2691. VAR ch, tx, ty : LONGINT;
  2692. BEGIN
  2693. text.AcquireRead;
  2694. ViewToTextPos(x, y, pos);
  2695. IF FindScreenPos(pos, tx, ty) THEN
  2696. IF tx > x THEN pos := pos - 1 END
  2697. END;
  2698. utilreader.SetPosition(GetInternalPos(pos));
  2699. utilreader.ReadCh(ch);
  2700. text.ReleaseRead;
  2701. IF utilreader.link # NIL THEN
  2702. link := utilreader.link;
  2703. RETURN TRUE
  2704. ELSE
  2705. RETURN FALSE
  2706. END
  2707. END HitLink;
  2708. PROCEDURE LinkClick(link : Texts.Link);
  2709. VAR w : LinkWrapper;
  2710. BEGIN
  2711. NEW(w); w.link := link;
  2712. onLinkClicked.Call(w)
  2713. END LinkClick;
  2714. (* builtin behaviour *)
  2715. PROCEDURE LinkClicked*(sender, data : ANY);
  2716. VAR tempLink : ARRAY 2048 OF CHAR;
  2717. tempLabel : ARRAY 256 OF CHAR;
  2718. pos, i : LONGINT;
  2719. BEGIN
  2720. IF data IS LinkWrapper THEN
  2721. COPY(data(LinkWrapper).link^, tempLink);
  2722. IF tempLink[0] = "#" THEN (* internal link *)
  2723. i := 0;
  2724. WHILE tempLink[i] # 0X DO
  2725. tempLabel[i] := tempLink[i+1];
  2726. INC(i);
  2727. END;
  2728. tempLink[i] := 0X;
  2729. (* find label in tv *)
  2730. IF FindLabel(tempLabel, pos) THEN
  2731. i := layout.nofLines-1;
  2732. WHILE (i >= 0) DO
  2733. IF layout.GetLineStartPos(i) < pos THEN firstLine.Set(i); RETURN END;
  2734. DEC(i);
  2735. END;
  2736. END;
  2737. ELSE (* other links *)
  2738. END
  2739. END
  2740. END LinkClicked;
  2741. (* Returns the position of the label in text *)
  2742. PROCEDURE FindLabel*(CONST label : ARRAY OF CHAR; VAR pos : LONGINT): BOOLEAN;
  2743. VAR ch : LONGINT;
  2744. found : BOOLEAN;
  2745. BEGIN
  2746. found := FALSE; pos := 0;
  2747. text.AcquireRead;
  2748. utilreader.SetDirection(1); utilreader.SetPosition(pos);
  2749. REPEAT
  2750. utilreader.ReadCh(ch);
  2751. IF ch = Texts.LabelChar THEN
  2752. IF utilreader.object(Texts.LabelPiece).label^ = label THEN
  2753. found := TRUE;
  2754. END;
  2755. END;
  2756. INC(pos);
  2757. UNTIL utilreader.eot OR found;
  2758. text.ReleaseRead;
  2759. RETURN found;
  2760. END FindLabel;
  2761. (* Drag away operations *)
  2762. PROCEDURE AutoStartDrag*;
  2763. VAR img : WMGraphics.Image;
  2764. c : WMGraphics.BufferCanvas;
  2765. w, h, i, la, lb, top : LONGINT;
  2766. l : LineInfo;
  2767. BEGIN
  2768. text.AcquireRead;
  2769. selection.Sort;
  2770. NEW(dragSelA, text);NEW(dragSelB, text);
  2771. dragSelA.SetPosition(selection.a); dragSelB.SetPosition(selection.b);
  2772. la := Limit(layout.FindLineNrByPos(selection.a), 0, layout.GetNofLines() - 1);
  2773. lb := Limit(layout.FindLineNrByPos(selection.b), 0, layout.GetNofLines() - 1);
  2774. (* estimate the size of the selection *)
  2775. h := 0; w := 0;
  2776. FOR i := la TO lb DO
  2777. h := h + (layout.lines[i].height);
  2778. w := Strings.Max(w, layout.lines[i].width);
  2779. END;
  2780. h := Limit(h, 20, 200);
  2781. w := Limit(w, 20, 400);
  2782. (* render to bitmap *)
  2783. NEW(img); Raster.Create(img, w, h, Raster.BGRA8888);
  2784. NEW(c, img);
  2785. top := 0;
  2786. (* hack the startpos of the first line *)
  2787. l := layout.lines[la]; l.pos := selection.a;
  2788. IF la = lb THEN RenderLine(c, l, la, top, selection.b - selection.a)
  2789. ELSE
  2790. RenderLine(c, l, la, top, -1);
  2791. top := top + l.height
  2792. END;
  2793. FOR i := la + 1 TO lb DO
  2794. IF i = lb THEN
  2795. RenderLine(c, layout.lines[i], i, top, selection.b - layout.lines[i].pos)
  2796. ELSE
  2797. RenderLine(c, layout.lines[i], i, top, -1);
  2798. top := top + (l.height)
  2799. END
  2800. END;
  2801. text.ReleaseRead;
  2802. IF StartDrag(NIL, img, 0,0,DragWasAccepted, NIL) THEN
  2803. ELSE KernelLog.String("WMTextView : Drag could not be started")
  2804. END;
  2805. END AutoStartDrag;
  2806. PROCEDURE DragWasAccepted(sender, data : ANY);
  2807. VAR di : WMWindowManager.DragInfo;
  2808. dt : WMDropTarget.DropTarget;
  2809. itf : WMDropTarget.DropInterface;
  2810. targetText, temp : Texts.Text;
  2811. string : Strings.String;
  2812. pos, a, b: LONGINT; res: WORD;
  2813. BEGIN
  2814. IF (dragSelA = NIL) OR (dragSelB = NIL) THEN RETURN END;
  2815. IF (data # NIL) & (data IS WMWindowManager.DragInfo) THEN
  2816. di := data(WMWindowManager.DragInfo);
  2817. IF (di.data # NIL) & (di.data IS WMDropTarget.DropTarget) THEN
  2818. dt := di.data(WMDropTarget.DropTarget)
  2819. ELSE RETURN
  2820. END
  2821. ELSE RETURN
  2822. END;
  2823. itf := dt.GetInterface(WMDropTarget.TypeText);
  2824. IF itf # NIL THEN
  2825. targetText := itf(WMDropTarget.DropText).text;
  2826. IF targetText # NIL THEN
  2827. targetText.AcquireWrite;
  2828. IF ~dragCopy THEN
  2829. IF TraceCopy IN Trace THEN KernelLog.String("WMTextView: Not copy"); KernelLog.Ln; END;
  2830. text.AcquireWrite;
  2831. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2832. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2833. IF (targetText # text) OR (pos < a) OR (pos > b) THEN
  2834. NEW(temp); temp.AcquireWrite; temp.CopyFromText(text, a, b-a, 0); temp.ReleaseWrite;
  2835. text.Delete(a, b- a);
  2836. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2837. temp.AcquireRead;
  2838. targetText.CopyFromText(temp, 0, temp.GetLength(), pos);
  2839. temp.ReleaseRead;
  2840. END;
  2841. text.ReleaseWrite
  2842. ELSE
  2843. IF TraceCopy IN Trace THEN KernelLog.String("WMTextView: Copy"); KernelLog.Ln; END;
  2844. text.AcquireRead;
  2845. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2846. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2847. targetText.CopyFromText(text, a, b-a, pos);
  2848. text.ReleaseRead;
  2849. END;
  2850. targetText.ReleaseWrite
  2851. END;
  2852. RETURN
  2853. END;
  2854. itf := dt.GetInterface(WMDropTarget.TypeString);
  2855. IF (itf # NIL) THEN
  2856. IF ~dragCopy THEN
  2857. text.AcquireWrite;
  2858. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2859. NEW(temp);
  2860. temp.AcquireWrite;
  2861. temp.CopyFromText(text, a, b-a, 0);
  2862. IF (temp.GetLength() > 0) THEN NEW(string, temp.GetLength() * 5); ELSE NEW(string, 1); string[0] := 0X; END;
  2863. temp.ReleaseWrite;
  2864. text.ReleaseWrite;
  2865. TextUtilities.TextToStr(temp, string^);
  2866. itf(WMDropTarget.DropString).Set(string^, res);
  2867. IF res = 0 THEN
  2868. text.AcquireWrite;
  2869. text.Delete(a, b- a);
  2870. text.ReleaseWrite;
  2871. END;
  2872. ELSE
  2873. text.AcquireRead;
  2874. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2875. NEW(temp);
  2876. temp.AcquireWrite;
  2877. temp.CopyFromText(text, a, b-a, 0);
  2878. IF (temp.GetLength() > 0) THEN NEW(string, temp.GetLength() * 5); ELSE NEW(string, 1); string[0] := 0X; END;
  2879. temp.ReleaseWrite;
  2880. text.ReleaseRead;
  2881. TextUtilities.TextToStr(temp, string^);
  2882. itf(WMDropTarget.DropString).Set(string^, res);
  2883. END;
  2884. END;
  2885. END DragWasAccepted;
  2886. (* Drag onto operations *)
  2887. PROCEDURE DragOver*(x, y : LONGINT; dragInfo : WMWindowManager.DragInfo);
  2888. VAR pos : LONGINT;
  2889. BEGIN
  2890. IF takesFocus.Get() THEN
  2891. text.AcquireRead;
  2892. ViewToTextPos(x, y, pos);
  2893. cursor.SetVisible(TRUE);
  2894. cursor.SetPosition(pos);
  2895. StoreLineEnter;
  2896. text.ReleaseRead
  2897. END;
  2898. END DragOver;
  2899. PROCEDURE ConfirmDrag*(accept: BOOLEAN; dragInfo: WMWindowManager.DragInfo);
  2900. BEGIN
  2901. IF dragInfo.onAccept # NIL THEN
  2902. dragInfo.onAccept(SELF, dragInfo)
  2903. END;
  2904. END ConfirmDrag;
  2905. PROCEDURE DragDropped*(x, y : LONGINT; dragInfo : WMWindowManager.DragInfo);
  2906. VAR dropTarget : TextDropTarget;
  2907. pos, internalPos : LONGINT;
  2908. p : Texts.TextPosition;
  2909. BEGIN
  2910. IF takesFocus.Get() THEN
  2911. text.AcquireRead;
  2912. ViewToTextPos(x, y, pos) ;
  2913. (* prevent a selection from being dropped behind the paragraph separator *)
  2914. internalPos := GetInternalPos(pos);
  2915. IF text.isUTF & (layout.bidiFormatter # NIL) THEN
  2916. IF layout.bidiFormatter.IsLastCharacterInLine(internalPos) THEN
  2917. DEC(internalPos);
  2918. END;
  2919. END;
  2920. NEW(p, text); p.SetPosition(internalPos);
  2921. NEW(dropTarget, text, p);
  2922. text.ReleaseRead;
  2923. IF ~hasFocus & ~alwaysShowCursorI THEN cursor.SetVisible(FALSE) END;
  2924. dragInfo.data := dropTarget;
  2925. ConfirmDrag(TRUE, dragInfo);
  2926. ELSE
  2927. ConfirmDrag(FALSE, dragInfo);
  2928. END;
  2929. END DragDropped;
  2930. PROCEDURE CopySelection*;
  2931. BEGIN
  2932. IF isPassword.Get() THEN RETURN END;
  2933. text.AcquireRead;
  2934. Texts.clipboard.AcquireWrite;
  2935. selection.Sort;
  2936. IF selection.b - selection.a > 0 THEN
  2937. (* clear the clipboard *)
  2938. IF Texts.clipboard.GetLength() > 0 THEN Texts.clipboard.Delete(0, Texts.clipboard.GetLength()) END;
  2939. Texts.clipboard.CopyFromText(text, selection.a, selection.b - selection.a, 0);
  2940. END;
  2941. Texts.clipboard.ReleaseWrite;
  2942. text.ReleaseRead
  2943. END CopySelection;
  2944. PROCEDURE DeleteSelection*;
  2945. BEGIN
  2946. Acquire; (* protect cursor *)
  2947. text.AcquireWrite;
  2948. selection.Sort;
  2949. text.Delete(selection.a, selection.b - selection.a);
  2950. cursor.SetVisible(TRUE);
  2951. text.ReleaseWrite;
  2952. Release;
  2953. END DeleteSelection;
  2954. PROCEDURE Paste*;
  2955. BEGIN
  2956. text.AcquireWrite;
  2957. Texts.clipboard.AcquireRead;
  2958. IF Texts.clipboard.GetLength() > 0 THEN
  2959. IF selection.b - selection.a # 0 THEN DeleteSelection() END;
  2960. text.CopyFromText(Texts.clipboard, 0, Texts.clipboard.GetLength(), cursor.GetPosition())
  2961. END;
  2962. Texts.clipboard.ReleaseRead;
  2963. text.ReleaseWrite
  2964. END Paste;
  2965. PROCEDURE SelectAll*;
  2966. BEGIN
  2967. Acquire; (* protect cursor *)
  2968. text.AcquireRead;
  2969. selection.SetFromTo(0, text.GetLength());
  2970. cursor.SetVisible(text.GetLength() <= 0);
  2971. Texts.SetLastSelection(text, selection.from, selection.to);
  2972. text.ReleaseRead;
  2973. Release;
  2974. END SelectAll;
  2975. (* Prepare to start the selection by keyboard. Clear the selection, if it is not contigous *)
  2976. PROCEDURE KeyStartSelection(pos : LONGINT);
  2977. BEGIN
  2978. IF selection.to.GetPosition() # pos THEN selection.SetFromTo(pos, pos); cursor.SetVisible(TRUE); Texts.ClearLastSelection END;
  2979. END KeyStartSelection;
  2980. (* update the keyboard selection with the new position, redraw from the last StartSelection *)
  2981. PROCEDURE KeyUpdateSelection(pos : LONGINT);
  2982. BEGIN
  2983. selection.SetTo(pos);
  2984. selection.Sort;
  2985. cursor.SetVisible(selection.b - selection.a <= 0);
  2986. Texts.SetLastSelection(text, selection.from, selection.to)
  2987. END KeyUpdateSelection;
  2988. PROCEDURE CursorChanged;
  2989. BEGIN
  2990. cursorBlinker.Show(cursor);
  2991. IF (onCursorChanged # NIL) THEN onCursorChanged END
  2992. END CursorChanged;
  2993. PROCEDURE CursorUp*(select : BOOLEAN);
  2994. VAR
  2995. pos, cPos, cl, lineStart : LONGINT;
  2996. BEGIN
  2997. Acquire;
  2998. text.AcquireRead;
  2999. pos := GetInternalPos(cursor.GetPosition());
  3000. IF select THEN
  3001. KeyStartSelection(pos)
  3002. ELSE
  3003. selection.SetFromTo(pos, pos);
  3004. cursor.SetVisible(TRUE);
  3005. Texts.ClearLastSelection
  3006. END;
  3007. cl := layout.FindLineNrByPos(pos);
  3008. IF cl > 0 THEN
  3009. DEC(cl);
  3010. lineStart := layout.GetLineStartPos(cl);
  3011. cPos := lineStart + Strings.Min(layout.GetLineLength(cl) - 1, lineEnter);
  3012. cursor.SetPosition(cPos);
  3013. IF cl < firstLineI THEN firstLine.Set(cl) END
  3014. END;
  3015. IF select THEN
  3016. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()));
  3017. END;
  3018. text.ReleaseRead;
  3019. Release;
  3020. CursorChanged
  3021. END CursorUp;
  3022. PROCEDURE CursorDown*(select : BOOLEAN);
  3023. VAR pos, cPos, cl, lineStart : LONGINT;
  3024. BEGIN
  3025. Acquire;
  3026. text.AcquireRead;
  3027. pos := GetInternalPos(cursor.GetPosition());
  3028. IF select THEN
  3029. KeyStartSelection(pos)
  3030. ELSE
  3031. selection.SetFromTo(pos, pos);
  3032. cursor.SetVisible(TRUE);
  3033. Texts.ClearLastSelection
  3034. END;
  3035. cl := layout.FindLineNrByPos(pos);
  3036. IF cl < layout.GetNofLines() - 1 THEN
  3037. INC(cl);
  3038. lineStart := layout.GetLineStartPos(cl);
  3039. cPos := lineStart + Strings.Min(layout.GetLineLength(cl) - 1, lineEnter);
  3040. cursor.SetPosition(cPos);
  3041. IF cl > FindLineByY(firstLineI, bounds.GetHeight() - bordersI.b) THEN firstLine.Set(firstLineI + 1 ) END
  3042. END;
  3043. IF select THEN
  3044. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3045. END;
  3046. text.ReleaseRead;
  3047. Release;
  3048. CursorChanged
  3049. END CursorDown;
  3050. (* Move the cursor one character/word to the left *)
  3051. PROCEDURE CursorLeft*(word, select : BOOLEAN);
  3052. VAR
  3053. pos, cPos, wPos : LONGINT;
  3054. BEGIN
  3055. Acquire;
  3056. text.AcquireRead;
  3057. PositionDebugging.SetPos(GetInternalPos(cursor.GetPosition()),cursor.GetPosition());
  3058. pos := GetInternalPos(cursor.GetPosition());
  3059. IF select THEN
  3060. KeyStartSelection(pos)
  3061. ELSE
  3062. selection.SetFromTo(pos, pos);
  3063. cursor.SetVisible(TRUE);
  3064. Texts.ClearLastSelection
  3065. END;
  3066. cPos := GetInternalPos(cursor.GetPosition()) - 1;
  3067. IF ~word THEN
  3068. cursor.SetPosition(GetDisplayPos(cPos));
  3069. ELSE
  3070. wPos := TextUtilities.FindPosWordLeft(utilreader, cPos);
  3071. cursor.SetPosition(GetDisplayPos(wPos));
  3072. END;
  3073. IF select THEN
  3074. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3075. END;
  3076. StoreLineEnter;
  3077. text.ReleaseRead;
  3078. Release;
  3079. CursorChanged
  3080. END CursorLeft;
  3081. (* Move the cursor one character/word to the right *)
  3082. PROCEDURE CursorRight*(word, select : BOOLEAN);
  3083. VAR
  3084. pos, cPos, wPos : LONGINT;
  3085. BEGIN
  3086. Acquire;
  3087. text.AcquireRead;
  3088. PositionDebugging.SetPos(GetInternalPos(cursor.GetPosition()),cursor.GetPosition());
  3089. pos := GetInternalPos(cursor.GetPosition());
  3090. IF select THEN
  3091. KeyStartSelection(pos)
  3092. ELSE
  3093. selection.SetFromTo(pos, pos);
  3094. cursor.SetVisible(TRUE);
  3095. Texts.ClearLastSelection
  3096. END;
  3097. cPos := GetInternalPos(cursor.GetPosition()) + 1;
  3098. IF ~word THEN
  3099. cursor.SetPosition(GetDisplayPos(cPos));
  3100. ELSE
  3101. wPos := TextUtilities.FindPosWordRight(utilreader, cPos);
  3102. cursor.SetPosition(GetDisplayPos(wPos));
  3103. END;
  3104. IF select THEN
  3105. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3106. END;
  3107. StoreLineEnter;
  3108. text.ReleaseRead;
  3109. Release;
  3110. CursorChanged
  3111. END CursorRight;
  3112. PROCEDURE PageDown*(select : BOOLEAN);
  3113. VAR dy : LONGINT; i, pos, iPos : LONGINT;
  3114. cx, cy : LONGINT;
  3115. BEGIN
  3116. Acquire;
  3117. text.AcquireRead;
  3118. iPos := GetInternalPos(cursor.GetPosition());
  3119. IF select THEN
  3120. KeyStartSelection(iPos)
  3121. ELSE
  3122. selection.SetFromTo(iPos, iPos);
  3123. cursor.SetVisible(TRUE);
  3124. Texts.ClearLastSelection
  3125. END;
  3126. IF firstLineI = layout.GetNofLines() - 1 THEN
  3127. cursor.SetPosition(text.GetLength());
  3128. ELSE
  3129. (* save cursor screen pos for repositioning *)
  3130. IF ~FindScreenPos(cursor.GetPosition(), cx, cy) THEN cx := 0; cy := 0 END;
  3131. i := firstLineI; dy := 0;
  3132. WHILE (i < layout.GetNofLines() - 1) & (dy < bounds.GetHeight() - bordersI.t - bordersI.b) DO
  3133. INC(i); dy := dy + (layout.lines[i].height)
  3134. END;
  3135. firstLine.Set(i);
  3136. (* set cursor to nearest pos on new page *)
  3137. ViewToTextPos(cx, cy, pos);
  3138. IF pos >= 0 THEN
  3139. cursor.SetPosition(pos);
  3140. END;
  3141. END;
  3142. IF select THEN
  3143. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3144. END;
  3145. text.ReleaseRead;
  3146. Release;
  3147. CursorChanged
  3148. END PageDown;
  3149. PROCEDURE PageUp*(select : BOOLEAN);
  3150. VAR dy : LONGINT; i, pos, iPos : LONGINT;
  3151. cx, cy : LONGINT;
  3152. BEGIN
  3153. Acquire;
  3154. text.AcquireRead;
  3155. iPos := GetInternalPos(cursor.GetPosition());
  3156. IF select THEN
  3157. KeyStartSelection(iPos)
  3158. ELSE
  3159. selection.SetFromTo(iPos, iPos);
  3160. cursor.SetVisible(TRUE);
  3161. Texts.ClearLastSelection
  3162. END;
  3163. IF firstLineI = 0 THEN
  3164. cursor.SetPosition(0);
  3165. ELSE
  3166. (* save cursor screen pos for repositioning *)
  3167. IF ~FindScreenPos(cursor.GetPosition(), cx, cy) THEN cx := 0; cy := 0 END;
  3168. (* go up one page but at least one page *)
  3169. i := firstLineI; dy := 0;
  3170. WHILE (i > 0) & (dy < bounds.GetHeight() - bordersI.t - bordersI.b) DO
  3171. DEC(i); dy := dy + (layout.lines[i].height)
  3172. END;
  3173. IF (i > 0) & (i = firstLineI) THEN DEC(i) END;
  3174. firstLine.Set(i);
  3175. (* set cursor to nearest pos on new page *)
  3176. ViewToTextPos(cx, cy, pos);
  3177. IF pos >= 0 THEN
  3178. cursor.SetPosition(pos);
  3179. END
  3180. END;
  3181. IF select THEN
  3182. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3183. END;
  3184. text.ReleaseRead;
  3185. Release;
  3186. CursorChanged
  3187. END PageUp;
  3188. PROCEDURE Home*(ctrl, select : BOOLEAN);
  3189. VAR
  3190. lineStart, cl, pos : LONGINT;
  3191. BEGIN
  3192. Acquire;
  3193. text.AcquireRead;
  3194. pos := GetInternalPos(cursor.GetPosition());
  3195. IF select THEN
  3196. KeyStartSelection(pos)
  3197. ELSE
  3198. selection.SetFromTo(pos, pos);
  3199. cursor.SetVisible(TRUE);
  3200. Texts.ClearLastSelection
  3201. END;
  3202. IF ctrl THEN
  3203. cursor.SetPosition(GetDisplayPos(0));
  3204. firstLine.Set(0)
  3205. ELSE
  3206. cl := layout.FindLineNrByPos(cursor.GetPosition());
  3207. lineStart := layout.GetLineStartPos(cl);
  3208. cursor.SetPosition(GetDisplayPos(lineStart));
  3209. END;
  3210. StoreLineEnter;
  3211. IF select THEN
  3212. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3213. END;
  3214. text.ReleaseRead;
  3215. Release;
  3216. CursorChanged
  3217. END Home;
  3218. PROCEDURE End*(ctrl, select : BOOLEAN);
  3219. VAR lineEnd, textLength, cl, pos, dispPos: LONGINT;
  3220. BEGIN
  3221. Acquire;
  3222. text.AcquireRead;
  3223. pos := GetInternalPos(cursor.GetPosition());
  3224. IF select THEN
  3225. KeyStartSelection(pos)
  3226. ELSE
  3227. selection.SetFromTo(pos, pos);
  3228. cursor.SetVisible(TRUE);
  3229. Texts.ClearLastSelection
  3230. END;
  3231. IF ctrl THEN
  3232. textLength := text.GetLength();
  3233. cursor.SetPosition(GetDisplayPos(textLength));
  3234. firstLine.Set(layout.FindLineNrByPos(text.GetLength()))
  3235. ELSE
  3236. cl := layout.FindLineNrByPos(cursor.GetPosition());
  3237. lineEnd := layout.GetLineStartPos(cl) + layout.GetLineLength(cl) - 1;
  3238. dispPos := GetDisplayPos(lineEnd);
  3239. cursor.SetPosition(dispPos);
  3240. END;
  3241. StoreLineEnter;
  3242. IF select THEN
  3243. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3244. END;
  3245. text.ReleaseRead;
  3246. Release;
  3247. CursorChanged
  3248. END End;
  3249. PROCEDURE KeyEvent*(ucs :LONGINT; flags : SET; VAR keysym : LONGINT);
  3250. BEGIN
  3251. modifierFlags := flags;
  3252. IF Inputs.Release IN flags THEN RETURN END;
  3253. dragCopy := modifierFlags * Inputs.Ctrl # {};
  3254. IF keysym = 01H THEN (* Ctrl-A *)
  3255. SelectAll
  3256. ELSIF keysym = 03H THEN (* Ctrl-C *)
  3257. CopySelection
  3258. ELSIF (keysym = 0FF63H) & (flags * Inputs.Ctrl # {}) THEN (*Ctrl Insert *)
  3259. CopySelection
  3260. ELSIF keysym = 12H THEN (* Ctrl-R *)
  3261. layout.FullLayout(TRUE); Invalidate;CheckNumberOfLines;
  3262. KernelLog.String("Refreshed"); KernelLog.Ln;
  3263. ELSIF keysym = 0FF51H THEN (* Cursor Left *)
  3264. CursorLeft(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3265. ELSIF keysym = 0FF53H THEN (* Cursor Right *)
  3266. CursorRight(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3267. ELSIF keysym = 0FF54H THEN (* Cursor Down *)
  3268. CursorDown(flags * Inputs.Shift # {})
  3269. ELSIF keysym = 0FF52H THEN (* Cursor Up *)
  3270. CursorUp(flags * Inputs.Shift # {})
  3271. ELSIF keysym = 0FF56H THEN (* Page Down *)
  3272. PageDown(flags * Inputs.Shift # {})
  3273. ELSIF keysym = 0FF55H THEN (* Page Up *)
  3274. PageUp(flags * Inputs.Shift # {})
  3275. ELSIF keysym = 0FF50H THEN (* Cursor Home *)
  3276. Home(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3277. ELSIF keysym = 0FF57H THEN (* Cursor End *)
  3278. End(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3279. END
  3280. END KeyEvent;
  3281. (* called by users that override the KeyEvents to allow copy drag drop *)
  3282. PROCEDURE SetFlags*(flags : SET);
  3283. BEGIN
  3284. modifierFlags := flags;
  3285. dragCopy := modifierFlags * Inputs.Ctrl # {};
  3286. END SetFlags;
  3287. PROCEDURE FindCommandRange*(pos: LONGINT; VAR start, end, nofLastSelections : LONGINT);
  3288. VAR ch : LONGINT; string : ARRAY 23 OF CHAR; i : LONGINT; sDoCommands, lastWasTilde : BOOLEAN;
  3289. escapeString: ARRAY 32 OF LONGINT; escapePos: LONGINT; escape: BOOLEAN;
  3290. (* note: this simple algorithm can be emplyed if the substring to be implicitly searched for does not contain its first character *)
  3291. PROCEDURE String(escape: BOOLEAN; CONST escapeString: ARRAY OF LONGINT);
  3292. VAR done: BOOLEAN; escapePos: LONGINT;
  3293. BEGIN
  3294. done := FALSE; escapePos := -1;
  3295. REPEAT
  3296. utilreader.ReadCh(ch);
  3297. IF ch = ORD('"') THEN
  3298. IF escape THEN
  3299. escapePos := 0;
  3300. ELSE
  3301. done := TRUE
  3302. END;
  3303. ELSIF escapePos >= 0 THEN
  3304. IF escapeString[escapePos] = 0 THEN
  3305. IF ch =ORD("\") THEN done := TRUE
  3306. ELSE escapePos := -1
  3307. END;
  3308. ELSIF escapeString[escapePos] # ch THEN
  3309. escapePos := -1;
  3310. ELSE
  3311. INC(escapePos);
  3312. END;
  3313. END;
  3314. UNTIL done OR utilreader.eot;
  3315. END String;
  3316. BEGIN
  3317. nofLastSelections := 0;
  3318. text.AcquireRead;
  3319. utilreader.SetDirection(-1); utilreader.SetPosition(pos);
  3320. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3321. start := utilreader.GetPosition() + 2;
  3322. IF utilreader.eot THEN DEC(start, 2) END;
  3323. (* search ~ *)
  3324. i := 0; sDoCommands := FALSE; lastWasTilde := FALSE;
  3325. utilreader.SetDirection(1); utilreader.SetPosition(start);
  3326. REPEAT
  3327. utilreader.ReadCh(ch);
  3328. IF ch = ORD('"') THEN
  3329. escapeString[escapePos] := 0;
  3330. String(escape, escapeString);
  3331. ELSIF ch =ORD("\") THEN
  3332. escape := TRUE;
  3333. escapePos := 0;
  3334. ELSIF escape THEN
  3335. IF TextUtilities.IsWhiteSpace(ch,text.isUTF) THEN escape := FALSE
  3336. ELSE escapeString[escapePos] := ch; INC(escapePos);
  3337. END;
  3338. END;
  3339. (* check whether the command is System.DoCommands *)
  3340. IF (i < 17) THEN
  3341. string[i] := CHR(ch);
  3342. INC(i);
  3343. IF (i = 17) THEN
  3344. string[17] := 0X;
  3345. IF (string = "System.DoCommands") OR Strings.StartsWith2("PreliminaryCommands",string) THEN
  3346. sDoCommands := TRUE;
  3347. END;
  3348. END;
  3349. END;
  3350. IF (CHR(ch) = "^") THEN
  3351. INC(nofLastSelections);
  3352. END;
  3353. (* We do a special treatment of the command System.DoCommands since we don't want a single
  3354. tilde character to delimit the parameter string for the particular command - but two tilde characters *)
  3355. IF sDoCommands THEN
  3356. IF (ch = ORD("~")) THEN
  3357. IF ~lastWasTilde THEN
  3358. lastWasTilde := TRUE;
  3359. utilreader.ReadCh(ch);
  3360. ELSE
  3361. (* Two tilde characters only separated with whitespace means this is the
  3362. end of the System.DoCommands parameter string *)
  3363. END;
  3364. ELSIF lastWasTilde & ~TextUtilities.IsWhiteSpace(ch,text.isUTF) THEN
  3365. lastWasTilde := FALSE;
  3366. END;
  3367. END;
  3368. UNTIL (ch = ORD("~")) OR (utilreader.eot);
  3369. end := utilreader.GetPosition() - 1;
  3370. IF utilreader.eot THEN INC(end) END;
  3371. text.ReleaseRead
  3372. END FindCommandRange;
  3373. PROCEDURE FindCommand*(pos: LONGINT; VAR start, end : LONGINT);
  3374. VAR ch : LONGINT;
  3375. BEGIN
  3376. text.AcquireRead;
  3377. utilreader.SetDirection(-1); utilreader.SetPosition(pos);
  3378. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3379. start := utilreader.GetPosition() + 2;
  3380. IF utilreader.eot THEN DEC(start, 2) END;
  3381. utilreader.SetDirection(1); utilreader.SetPosition(pos);
  3382. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3383. end := utilreader.GetPosition() - 1;
  3384. IF utilreader.eot THEN INC(end) END;
  3385. text.ReleaseRead;
  3386. END FindCommand;
  3387. (** Start the command in the text, starting on pos (or wordboundary before),
  3388. caller should hold lock on text to make the pos stable *)
  3389. PROCEDURE StartCommand*(pos : LONGINT; openFile : BOOLEAN);
  3390. VAR
  3391. start, end, bufSize : LONGINT;
  3392. context : Commands.Context;
  3393. arg : Streams.StringReader;
  3394. command : ARRAY MaxCommandLength OF CHAR;
  3395. parameters : POINTER TO ARRAY OF CHAR;
  3396. s : Strings.String;
  3397. msg : ARRAY 128 OF CHAR;
  3398. ignore : Modules.Name;
  3399. paramSize, nofLastSelections, i, j, a, b: LONGINT; res: WORD;
  3400. selectionText : Texts.Text;
  3401. selectionOk : BOOLEAN;
  3402. from, to: Texts.TextPosition;
  3403. commandCaller:OBJECT;
  3404. commandWriter, errorWriter: Streams.Writer;
  3405. BEGIN
  3406. Acquire;
  3407. text.AcquireRead;
  3408. IF openFile THEN FindCommand(pos, start, end)
  3409. ELSE FindCommandRange(pos, start, end, nofLastSelections)
  3410. END;
  3411. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), MaxCallParameterBuf), 1);
  3412. NEW(s, bufSize);
  3413. paramSize := 0;
  3414. TextUtilities.SubTextToStrAt(text, start, end - start, paramSize, s^);
  3415. INC(paramSize);
  3416. text.ReleaseRead;
  3417. Release;
  3418. IF Inputs.Shift * modifierFlags # {} THEN
  3419. (*
  3420. Command / open will not see the caller => called as if no calling context was specified.
  3421. => Opening a text while holding a shift key down will usually result in a new viewer being opened.
  3422. *)
  3423. commandCaller := NIL
  3424. ELSE
  3425. commandCaller := SELF.commandCaller;
  3426. END;
  3427. IF openFile THEN
  3428. FileHandlers.OpenFile(s^, NIL, commandCaller)
  3429. ELSE
  3430. command := "";
  3431. i := 0;
  3432. WHILE (i < MaxCommandLength) & (s[i] # 0X) & (s[i] # ";") & (s[i] # " ") & (s[i] # 09X) & (s[i] # 0DX) & (s[i] # 0AX) DO
  3433. command[i] := s[i]; INC(i);
  3434. END;
  3435. IF i < MaxCommandLength THEN
  3436. command[i] := 0X;
  3437. INC(i);
  3438. Commands.Split(command, ignore, ignore, res, msg);
  3439. IF res # Commands.Ok THEN
  3440. KernelLog.String("WMTextView: Command parsing error, res: "); KernelLog.Int(res, 0);
  3441. KernelLog.String(" ("); KernelLog.String(msg); KernelLog.String(")"); KernelLog.Ln;
  3442. RETURN;
  3443. END;
  3444. ELSE
  3445. KernelLog.String("WMTextView: Command execution error: Command too long"); KernelLog.Ln;
  3446. RETURN;
  3447. END;
  3448. IF (Inputs.Alt * modifierFlags # {}) THEN
  3449. (* execute AltMMCommand with actual command and its parameters as parameter *)
  3450. COPY(AltMMCommand, command);
  3451. commandWriter := NIL; errorWriter := NIL;
  3452. i := 0;
  3453. ELSE
  3454. commandWriter := SELF.commandWriter;
  3455. errorWriter := SELF.errorWriter;
  3456. END;
  3457. IF (i < LEN(s)) THEN (* copy parameter string *)
  3458. selectionOk := FALSE;
  3459. IF (nofLastSelections > 0) THEN
  3460. IF Texts.GetLastSelection(selectionText, from, to) THEN
  3461. selectionOk := TRUE;
  3462. selectionText.AcquireRead;
  3463. a := Strings.Min(from.GetPosition(), to.GetPosition());
  3464. b := Strings.Max(from.GetPosition(), to.GetPosition());
  3465. INC(paramSize, b - a + 1);
  3466. END;
  3467. END;
  3468. NEW(parameters, paramSize);
  3469. j := 0;
  3470. WHILE (i < LEN(s)) & (j < LEN(parameters)-1) DO
  3471. IF (s[i] = "^") & selectionOk THEN
  3472. TextUtilities.SubTextToStrAt(selectionText, a, b - a, j, parameters^);
  3473. ELSE
  3474. parameters[j] := s[i]; INC(j);
  3475. END;
  3476. INC(i);
  3477. END;
  3478. parameters[j] := 0X;
  3479. IF selectionOk THEN
  3480. selectionText.ReleaseRead;
  3481. END;
  3482. ELSE
  3483. NEW(parameters, 1); parameters[0] := 0X;
  3484. END;
  3485. NEW(arg, LEN(parameters)); arg.SetRaw(parameters^, 0, LEN(parameters));
  3486. NEW(context, NIL, arg, commandWriter, errorWriter, commandCaller);
  3487. IF TraceCommands IN Trace THEN
  3488. KernelLog.String("WMTextView: Executing command: '"); KernelLog.String(command); KernelLog.String("'");
  3489. KernelLog.String(", parameters: ");
  3490. IF (parameters[0] = 0X) THEN KernelLog.String("None"); ELSE KernelLog.String("'"); KernelLog.String(parameters^); KernelLog.String("'"); END;
  3491. KernelLog.Ln;
  3492. END;
  3493. Commands.Activate(command, context, {}, res, msg);
  3494. IF (res # Commands.Ok) THEN
  3495. IF commandWriter # NIL THEN
  3496. commandWriter.String("WMTextView: Command execution error, res: "); commandWriter.Int(res, 0);
  3497. commandWriter.String(" ("); commandWriter.String(msg); commandWriter.String(")"); commandWriter.Ln;
  3498. commandWriter.Update;
  3499. ELSE
  3500. KernelLog.String("WMTextView: Command execution error, res: "); KernelLog.Int(res, 0);
  3501. KernelLog.String(" ("); KernelLog.String(msg); KernelLog.String(")"); KernelLog.Ln;
  3502. END;
  3503. END;
  3504. END;
  3505. END StartCommand;
  3506. PROCEDURE Start(sender, data: ANY);
  3507. VAR msg: ARRAY 512 OF CHAR; res: WORD;
  3508. BEGIN
  3509. IF (data # NIL) & (data IS ClickInfo) THEN
  3510. IF data(ClickInfo).cmdPar # NIL THEN
  3511. Commands.Call(data(ClickInfo).cmdPar^, {}, res, msg);
  3512. IF res # 0 THEN KernelLog.String("WMTextView: "); KernelLog.String(msg); KernelLog.Ln END;
  3513. END
  3514. END
  3515. END Start;
  3516. PROCEDURE Open(sender, data: ANY);
  3517. BEGIN
  3518. IF (data # NIL) & (data IS ClickInfo) THEN
  3519. IF data(ClickInfo).cmd # NIL THEN
  3520. FileHandlers.OpenFile(data(ClickInfo).cmd^, NIL, commandCaller)
  3521. END
  3522. END
  3523. END Open;
  3524. PROCEDURE PieMenuStart(sender, data: ANY);
  3525. BEGIN
  3526. Start(piemenu, piemenu.userData)
  3527. END PieMenuStart;
  3528. PROCEDURE PieMenuOpen(sender, data: ANY);
  3529. BEGIN
  3530. Open(piemenu, piemenu.userData)
  3531. END PieMenuOpen;
  3532. PROCEDURE PieMenuCopy(sender, data: ANY);
  3533. BEGIN
  3534. CopySelection;
  3535. END PieMenuCopy;
  3536. PROCEDURE PieMenuPaste(sender, data: ANY);
  3537. BEGIN
  3538. Paste;
  3539. END PieMenuPaste;
  3540. PROCEDURE ShowContextMenu*(x, y: LONGINT);
  3541. VAR
  3542. popup : WMPopups.Popup;
  3543. start, end, bufSize : LONGINT;
  3544. command, s : Strings.String;
  3545. clickInfo : ClickInfo;
  3546. str : ARRAY 256 OF CHAR;
  3547. window : WMWindowManager.Window;
  3548. nofLastSelections : LONGINT;
  3549. BEGIN
  3550. ASSERT(IsCallFromSequencer());
  3551. text.AcquireRead;
  3552. FindCommand(cursor.GetPosition(), start, end);
  3553. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), 4096), 1);
  3554. NEW(command, bufSize);
  3555. TextUtilities.SubTextToStr(text, start, end - start, command^);
  3556. FindCommandRange(cursor.GetPosition(), start, end, nofLastSelections);
  3557. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), MaxCallParameterBuf), 1);
  3558. NEW(s, bufSize);
  3559. TextUtilities.SubTextToStr(text, start, end - start, s^);
  3560. text.ReleaseRead;
  3561. NEW(clickInfo);
  3562. clickInfo.cmd := command;
  3563. clickInfo.cmdPar := s;
  3564. IF UsePieMenu THEN
  3565. NEW(piemenu); piemenu.SetEnabled({0, 1, 2, 3});
  3566. piemenu.SetText(1, Strings.NewString("Open"));
  3567. piemenu.SetText(3, Strings.NewString("Start"));
  3568. piemenu.SetText(2, Strings.NewString("Copy"));
  3569. piemenu.SetText(0, Strings.NewString("Paste"));
  3570. piemenu.userData := clickInfo;
  3571. piemenu.on1.Add(PieMenuOpen);
  3572. piemenu.on2.Add(PieMenuCopy);
  3573. piemenu.on3.Add(PieMenuStart);
  3574. piemenu.on0.Add(PieMenuPaste);
  3575. manager := WMWindowManager.GetDefaultManager();
  3576. window := manager.GetPositionOwner(x, y);
  3577. IF window = NIL THEN RETURN END;
  3578. Acquire; ToWMCoordinates(x, y, x, y); Release;
  3579. piemenu.Show(window, x, y, FALSE);
  3580. (* TODO: Can't set := NIL, since its used by the button handlers *)
  3581. ELSE
  3582. NEW(popup);
  3583. str := "Start "; Strings.Append(str, command^); popup.AddParButton(str, Start, clickInfo);
  3584. str := "Open "; Strings.Append(str, command^); popup.AddParButton(str, Open, clickInfo);
  3585. Acquire; ToWMCoordinates(x, y, x, y); Release;
  3586. popup.Popup(x, y);
  3587. END
  3588. END ShowContextMenu;
  3589. PROCEDURE HandleInternal*(VAR x: WMMessages.Message);
  3590. VAR pos : LONGINT; obj : ANY; link : Texts.Link;
  3591. BEGIN
  3592. ASSERT(IsCallFromSequencer());
  3593. IF (x.msgType = WMMessages.MsgKey) & objHasFocus THEN (* forward KeyMsg *)
  3594. WITH focusObject : WMComponents.VisualComponent DO
  3595. focusObject.Handle(x);
  3596. InvalidateRange(focusPos, focusPos+1)
  3597. END
  3598. ELSIF (x.msgType # WMMessages.MsgKey) & HitObject(x.x, x.y, pos, obj) THEN (* forward Msg *)
  3599. SetFocus; cursor.SetVisible(FALSE);
  3600. IF obj IS WMComponents.VisualComponent THEN
  3601. WITH obj : WMComponents.VisualComponent DO
  3602. (* remove oldObject first *)
  3603. IF (oldObject # NIL) & (oldObject # obj) THEN
  3604. oldObject(WMComponents.VisualComponent).Handle(x);
  3605. InvalidateRange(oldPos, oldPos+1);
  3606. END;
  3607. TransformCoordinates(x.x, x.y, obj); (* transform to obj coords *)
  3608. obj.Handle(x); (* call obj Handle *)
  3609. ChangePointer(obj.GetPointerInfo()); (* change the pointer Image *)
  3610. InvalidateRange(pos, pos+1); (* redraw obj *)
  3611. oldObject := obj; oldPos := pos; (* store last object *)
  3612. (* transfer focus to Object *)
  3613. IF (x.msgType = WMMessages.MsgPointer) & (x.flags * {0, 1, 2} = {0}) THEN
  3614. (* remove old focus first *)
  3615. IF (focusObject # NIL) & (focusObject # obj) THEN
  3616. focusObject(WMComponents.VisualComponent).FocusLost;
  3617. InvalidateRange(focusPos, focusPos+1)
  3618. END;
  3619. objHasFocus := TRUE;
  3620. focusObject := obj; focusPos := pos;
  3621. (* FocusLost *)
  3622. END
  3623. END
  3624. END
  3625. ELSIF (x.msgType = WMMessages.MsgPointer) & HitLink(x.x, x.y, pos, link) THEN (* Link *)
  3626. ChangePointer(manager.pointerLink);
  3627. IF (x.msgSubType = 2) &(oldFlags / x.flags = {CallURLPointer}) THEN LinkClick(link); END;
  3628. oldFlags := x.flags;
  3629. ELSE
  3630. ChangePointer(manager.pointerText); (* change Pointer back *)
  3631. (* transfer focus back to TextView *)
  3632. IF (focusObject # NIL) & (x.msgType = WMMessages.MsgPointer) & (x.flags * {0, 1, 2} = {0}) THEN
  3633. focusObject(WMComponents.VisualComponent).FocusLost;
  3634. objHasFocus := FALSE;
  3635. InvalidateRange(focusPos, focusPos+1);
  3636. FocusReceived;
  3637. focusObject := NIL
  3638. END;
  3639. (* update last Object *)
  3640. IF (oldObject # NIL) & (x.msgType = WMMessages.MsgPointer) THEN
  3641. oldObject(WMComponents.VisualComponent).Handle(x);
  3642. InvalidateRange(oldPos, oldPos+1);
  3643. oldObject := NIL
  3644. END;
  3645. IF (x.msgType = WMMessages.MsgExt) & (x.ext # NIL) & (x.ext IS Texts.StyleChangedMsg) THEN
  3646. layout.FullLayout(TRUE); Invalidate; CheckNumberOfLines;
  3647. ELSE
  3648. HandleInternal^(x);
  3649. END;
  3650. END
  3651. END HandleInternal;
  3652. END TextView;
  3653. TYPE
  3654. FontEntry = OBJECT
  3655. VAR
  3656. name : ARRAY 256 OF CHAR;
  3657. attributes : FontAttributes;
  3658. next : FontEntry;
  3659. PROCEDURE &Init(CONST name : ARRAY OF CHAR);
  3660. BEGIN
  3661. COPY(name, SELF.name);
  3662. attributes := NIL;
  3663. next := NIL;
  3664. END Init;
  3665. END FontEntry;
  3666. FontAttributes = OBJECT
  3667. VAR
  3668. font : WMGraphics.Font; (* { font # {} *)
  3669. size : LONGINT;
  3670. style : SET;
  3671. next : FontAttributes;
  3672. PROCEDURE &Init(size : LONGINT; style : SET);
  3673. BEGIN
  3674. font := NIL;
  3675. SELF.size := size;
  3676. SELF.style := style;
  3677. next := NIL;
  3678. END Init;
  3679. END FontAttributes;
  3680. (* not thread-safe! not global to avoid locking and keep size smaller *)
  3681. FontCache = OBJECT
  3682. VAR
  3683. entries : FontEntry;
  3684. defaultFont : WMGraphics.Font;
  3685. PROCEDURE &Init;
  3686. BEGIN
  3687. NEW(entries, "head"); (* head of list *)
  3688. defaultFont := WMGraphics.GetDefaultFont();
  3689. END Init;
  3690. PROCEDURE Find(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3691. VAR font : WMGraphics.Font; e : FontEntry; a : FontAttributes;
  3692. BEGIN
  3693. font := NIL;
  3694. e := entries.next;
  3695. WHILE (e # NIL ) & (e.name < name) DO e := e.next; END;
  3696. IF (e # NIL) & (e.name = name) THEN
  3697. a := e.attributes;
  3698. WHILE (a # NIL) & (a.size < size) DO a := a.next; END;
  3699. WHILE (a # NIL) & (a.size = size) & (a.style # style) DO a := a.next; END;
  3700. IF (a # NIL) & (a.size = size) THEN
  3701. ASSERT(a.font # NIL);
  3702. font := a.font;
  3703. END;
  3704. END;
  3705. RETURN font;
  3706. END Find;
  3707. PROCEDURE Add(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3708. VAR entry, e : FontEntry; attribute, a : FontAttributes;
  3709. BEGIN
  3710. e := entries;
  3711. WHILE (e.next # NIL) & (e.next.name < name) DO e := e.next; END;
  3712. IF (e.next # NIL) & (e.next.name = name) THEN
  3713. entry := e.next;
  3714. ELSE
  3715. NEW(entry, name);
  3716. entry.next := e.next;
  3717. e.next := entry;
  3718. END;
  3719. ASSERT(entry # NIL);
  3720. NEW(attribute, size, style);
  3721. attribute.font := WMGraphics.GetFont(name, size, style);
  3722. IF (entry.attributes = NIL) THEN
  3723. entry.attributes := attribute;
  3724. ELSIF (entry.attributes.size >= attribute.size) THEN
  3725. attribute.next := entry.attributes;
  3726. entry.attributes := attribute;
  3727. ELSE
  3728. a := entry.attributes;
  3729. WHILE (a.next # NIL) & (a.next.size < attribute.size) DO a := a.next; END;
  3730. attribute.next := a.next;
  3731. a.next := attribute;
  3732. END;
  3733. ASSERT(attribute.font # NIL);
  3734. RETURN attribute.font;
  3735. END Add;
  3736. (* Get specified font. If not available, the system default font is returned *)
  3737. PROCEDURE GetFont(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3738. VAR font : WMGraphics.Font;
  3739. BEGIN
  3740. font := Find(name, size, style);
  3741. IF (font = NIL) THEN
  3742. font := Add(name, size, style);
  3743. END;
  3744. ASSERT(font # NIL);
  3745. RETURN font;
  3746. END GetFont;
  3747. END FontCache;
  3748. VAR
  3749. manager : WMWindowManager.WindowManager;
  3750. cursorBlinker- : CursorBlinker;
  3751. PTVIsMultiLine, PTVIsPassword, PTVShowBorder, PTValwaysShowCursor, PTVShowLabels : WMProperties.BooleanProperty;
  3752. PTVAllowCommandExecution, PTVAllowTextSelection, PTVAllowPiemenu : WMProperties.BooleanProperty;
  3753. PTVWrapMode, PTVMouseWheelScrollSpeed, PVTtextAlignV : WMProperties.Int32Property;
  3754. PTVfirstLine, PTVleftShift, PTVPasswordChar : WMProperties.Int32Property;
  3755. PTVdefaultTextColor, PTVdefaultTextBgColor : WMProperties.ColorProperty;
  3756. PTVborders : WMProperties.RectangleProperty;
  3757. PTVonLinkClick, PTVonLinkClickInfo : Strings.String;
  3758. PTVonCtrlLinkClick, PTVonCtrlLinkClickInfo : Strings.String;
  3759. PTVShowLineNumbers, PTVIndicateTabs : WMProperties.BooleanProperty;
  3760. PTVHighlighting : WMProperties.StringProperty;
  3761. PTVLineNumberColor, PTVLineNumberBgColor, PTVclBgCurrentLine : WMProperties.ColorProperty;
  3762. currentTextView : TextView;
  3763. StrTextView : Strings.String;
  3764. DefaultStyle : POINTER TO RECORD END;
  3765. PROCEDURE Limit(x, min, max : LONGINT) : LONGINT;
  3766. BEGIN
  3767. IF x < min THEN x := min END;
  3768. IF x > max THEN x := max END;
  3769. RETURN x
  3770. END Limit;
  3771. (* Actually, this is a hack... but for now, do it. *)
  3772. PROCEDURE GetNewSize(CONST fontname : ARRAY OF CHAR; value, currentSize : LONGINT; VAR newSize : LONGINT);
  3773. BEGIN
  3774. IF (fontname = "Oberon") THEN
  3775. IF (value >0) THEN
  3776. IF (currentSize <= 8) THEN newSize := 10;
  3777. ELSIF (currentSize <= 10) THEN newSize := 12;
  3778. ELSIF (currentSize <= 12) THEN newSize := 14;
  3779. ELSIF (currentSize <= 14) THEN newSize := 16;
  3780. ELSIF (currentSize <= 16) THEN newSize := 20;
  3781. ELSIF (currentSize <= 20) THEN newSize := 24;
  3782. ELSE (* go to default *)
  3783. newSize := 24; (* max. size of Oberon font *)
  3784. END;
  3785. ELSE
  3786. IF (currentSize >= 24) THEN newSize := 20;
  3787. ELSIF (currentSize >= 20) THEN newSize := 16;
  3788. ELSIF (currentSize >= 16) THEN newSize := 14;
  3789. ELSIF (currentSize >= 14) THEN newSize := 12;
  3790. ELSIF (currentSize >= 12) THEN newSize := 10;
  3791. ELSE
  3792. newSize := 8;
  3793. END;
  3794. END;
  3795. ELSIF (fontname = "Courier") THEN
  3796. IF (value > 0) THEN
  3797. IF (currentSize <= 8) THEN newSize := 10;
  3798. ELSE
  3799. newSize := 12;
  3800. END;
  3801. ELSE
  3802. IF (currentSize >= 12) THEN newSize := 10;
  3803. ELSE
  3804. newSize := 8;
  3805. END;
  3806. END;
  3807. ELSE
  3808. newSize := currentSize + value * currentSize DIV 4;
  3809. END;
  3810. IF (newSize < 8) THEN newSize := 8; END;
  3811. END GetNewSize;
  3812. TYPE
  3813. DZ = OBJECT (Texts.Attributes);
  3814. VAR value: LONGINT;
  3815. PROCEDURE &Init(v: LONGINT);
  3816. BEGIN
  3817. value := v;
  3818. END Init;
  3819. END DZ;
  3820. PROCEDURE EnsureAttribute(VAR attr : Texts.Attributes);
  3821. BEGIN
  3822. IF (attr = NIL) THEN
  3823. NEW(attr); NEW(attr.fontInfo);
  3824. attr.fontInfo.name := "Vera";
  3825. attr.fontInfo.size := 16;
  3826. attr.fontInfo.style := {};
  3827. attr.color := 0000000FFH;
  3828. attr.bgcolor := 000000000H;
  3829. END
  3830. END EnsureAttribute;
  3831. PROCEDURE ChangeAttribute(VAR attr : Texts.Attributes; userData : ANY);
  3832. VAR dz: DZ;
  3833. BEGIN
  3834. IF (userData # NIL) & (userData IS DZ) THEN
  3835. EnsureAttribute(attr);
  3836. dz := userData(DZ);
  3837. GetNewSize(attr.fontInfo.name,-dz.value, attr.fontInfo.size, attr.fontInfo.size);
  3838. attr.fontInfo.fontcache := NIL;
  3839. END;
  3840. END ChangeAttribute;
  3841. PROCEDURE GetFontFromAttr(info : Texts.FontInfo) : WMGraphics.Font;
  3842. BEGIN
  3843. RETURN WMGraphics.GetFont(info.name, info.size, info.style);
  3844. END GetFontFromAttr;
  3845. PROCEDURE IsSameFont(f1, f2 : WMGraphics.Font) : BOOLEAN;
  3846. BEGIN
  3847. RETURN (f1 = f2) OR ((f1 # NIL) & (f2 # NIL) & (f1.size = f2.size) & (f1.style = f2.style) & (f1.name = f2.name));
  3848. END IsSameFont;
  3849. PROCEDURE CheckFont(style : SyntaxHighlighter.Style; font : WMGraphics.Font; VAR fontCache : FontCache);
  3850. VAR fontname : ARRAY 256 OF CHAR; fontsize : LONGINT; fontstyle : SET;
  3851. BEGIN
  3852. ASSERT(style # NIL);
  3853. IF (fontCache = NIL) THEN NEW(fontCache); END;
  3854. IF (style.defined * SyntaxHighlighter.FontMask = SyntaxHighlighter.FontMask) OR (font = NIL) THEN
  3855. COPY(style.attributes.fontInfo.name, fontname);
  3856. fontsize := style.attributes.fontInfo.size;
  3857. fontstyle := style.attributes.fontInfo.style;
  3858. ELSIF (font # NIL) THEN
  3859. IF (SyntaxHighlighter.FontName IN style.defined) THEN COPY(style.attributes.fontInfo.name, fontname); ELSE COPY(font.name, fontname); END;
  3860. IF (SyntaxHighlighter.FontSize IN style.defined) THEN fontsize := style.attributes.fontInfo.size; ELSE fontsize := font.size; END;
  3861. IF (SyntaxHighlighter.FontStyle IN style.defined) THEN fontstyle := style.attributes.fontInfo.style; ELSE fontstyle := font.style; END;
  3862. END;
  3863. IF (style.attributes.fontInfo.fontcache = NIL) OR ~IsSameFont(style.attributes.fontInfo.fontcache (WMGraphics.Font), font) THEN
  3864. style.attributes.fontInfo.fontcache := fontCache.GetFont(fontname, fontsize, fontstyle);
  3865. END;
  3866. ASSERT(style.attributes.fontInfo.fontcache # NIL);
  3867. END CheckFont;
  3868. PROCEDURE InitStrings;
  3869. BEGIN
  3870. StrTextView := Strings.NewString("TextView");
  3871. PTVonLinkClick := Strings.NewString("Link Click Event");
  3872. PTVonLinkClickInfo := Strings.NewString("fired when a link is pressed");
  3873. PTVonCtrlLinkClick := Strings.NewString("Ctrl Click Event");
  3874. PTVonCtrlLinkClickInfo := Strings.NewString("fired when Ctrl pressend and clicked");
  3875. END InitStrings;
  3876. PROCEDURE InitPrototypes;
  3877. BEGIN
  3878. NEW(PTVIsMultiLine, NIL, Strings.NewString("multiLine"), Strings.NewString("defines if more than one line is visible"));
  3879. PTVIsMultiLine.Set(TRUE);
  3880. NEW(PTVShowBorder, NIL, Strings.NewString("ShowBorder"), Strings.NewString("show border"));
  3881. PTVShowBorder.Set(FALSE);
  3882. NEW(PTVIsPassword, NIL, Strings.NewString("password"),
  3883. Strings.NewString("defines if the view is a password text. Characters are replaced by passwordChar"));
  3884. NEW(PTVPasswordChar, NIL, Strings.NewString("passwordChar"),
  3885. Strings.NewString("character that is the placeholder for a character in a password"));
  3886. PTVPasswordChar.Set(43);
  3887. NEW(PTValwaysShowCursor, NIL, Strings.NewString("alwaysShowCursor"),
  3888. Strings.NewString("set to true, if the cursor should not be hidden when focus is lost"));
  3889. PTValwaysShowCursor.Set(FALSE);
  3890. NEW(PTVShowLabels, NIL, Strings.NewString("ShowLabels"),
  3891. Strings.NewString("set to true, if the labels should be shown in the text"));
  3892. PTVShowLabels.Set(FALSE);
  3893. NEW(PTVMouseWheelScrollSpeed, NIL, Strings.NewString("MouseWheelScrollSpeed"),
  3894. Strings.NewString("Multiplier for mouse wheel, 0 to disable mouse wheel scrolling"));
  3895. PTVMouseWheelScrollSpeed.Set(3);
  3896. NEW(PTVAllowCommandExecution, NIL, Strings.NewString("allowCommandExecution"),
  3897. Strings.NewString("if set to true, middle-clicked words are executed as command"));
  3898. PTVAllowCommandExecution.Set(TRUE);
  3899. NEW(PTVAllowTextSelection, NIL, Strings.NewString("allowTextSelection"),
  3900. Strings.NewString("is the user allowed to select text using the mouse?"));
  3901. PTVAllowTextSelection.Set(TRUE);
  3902. NEW(PTVAllowPiemenu, NIL, Strings.NewString("allowPiemenu"),
  3903. Strings.NewString("if set to true, a mouse right-click opens the pie menu"));
  3904. PTVAllowPiemenu.Set(TRUE);
  3905. NEW(PTVWrapMode, NIL, Strings.NewString("wrapMode"), Strings.NewString("Set text wrapping mode"));
  3906. PTVWrapMode.Set(WrapWord);
  3907. NEW(PTVfirstLine, NIL, Strings.NewString("firstLine"),
  3908. Strings.NewString("the first visible line of text in the view"));
  3909. PTVfirstLine.Set(0);
  3910. NEW(PTVleftShift, NIL, Strings.NewString("leftShift"),
  3911. Strings.NewString("how many pixels the text in the view is shifted to the left"));
  3912. PTVleftShift.Set(0);
  3913. NEW(PTVdefaultTextColor, NIL, Strings.NewString("defaultTextColor"),
  3914. Strings.NewString("the color of a text that does not explicitly specify a color"));
  3915. PTVdefaultTextColor.Set(0FFH);
  3916. NEW(PTVdefaultTextBgColor, NIL, Strings.NewString("defaultTextBgColor"),
  3917. Strings.NewString("The color of a text background if not specified otherwise in the text"));
  3918. PTVdefaultTextBgColor.Set(0);
  3919. NEW(PTVborders, NIL, Strings.NewString("borders"),
  3920. Strings.NewString("spaces from bounds of the component to the text"));
  3921. PTVborders.Set(WMRectangles.MakeRect(5, 5, 5, 5));
  3922. NEW(PTVIndicateTabs, NIL, Strings.NewString("IndicateTabs"), Strings.NewString("Indicate tabs?"));
  3923. PTVIndicateTabs.Set(FALSE);
  3924. NEW(PTVShowLineNumbers, NIL, Strings.NewString("ShowLineNumbers"), Strings.NewString("Show line numbers?"));
  3925. PTVShowLineNumbers.Set(FALSE);
  3926. NEW(PTVLineNumberColor, NIL, Strings.NewString("LineNumberColor"), Strings.NewString("Color of line numbers"));
  3927. PTVLineNumberColor.Set(WMGraphics.Black);
  3928. NEW(PTVLineNumberBgColor, NIL, Strings.NewString("LineNumberBgColor"), Strings.NewString("Background color of line numbers"));
  3929. PTVLineNumberBgColor.Set(0CCCCCCFFH);
  3930. NEW(PTVHighlighting, NIL, Strings.NewString("Highlighting"), Strings.NewString("Name of highlighting to be applied"));
  3931. PTVHighlighting.Set(NIL);
  3932. NEW(PTVclBgCurrentLine, NIL, Strings.NewString("ClBgCurrentLine"), Strings.NewString("Background color of currently edited line"));
  3933. PTVclBgCurrentLine.Set(0);
  3934. NEW(PVTtextAlignV, NIL, Strings.NewString("TextAlignV"), Strings.NewString("vertical Text Alignment"));
  3935. PVTtextAlignV.Set(WMGraphics.AlignTop);
  3936. END InitPrototypes;
  3937. PROCEDURE EnablePiemenu*;
  3938. BEGIN
  3939. PTVAllowPiemenu.Set( TRUE );
  3940. KernelLog.String( "Piemenu enabled" ); KernelLog.Ln
  3941. END EnablePiemenu;
  3942. PROCEDURE DisablePiemenu*;
  3943. BEGIN
  3944. PTVAllowPiemenu.Set( FALSE );
  3945. KernelLog.String( "Piemenu disabled" ); KernelLog.Ln
  3946. END DisablePiemenu;
  3947. PROCEDURE TextViewFactory*() : XML.Element;
  3948. VAR e : TextView;
  3949. BEGIN
  3950. NEW(e); RETURN e
  3951. END TextViewFactory;
  3952. (* Inserts a ocharacter from the outside into the current textView's text at its current position *)
  3953. PROCEDURE InsertChar*(newChar : Char32) : INTEGER;
  3954. BEGIN
  3955. IF currentTextView # NIL THEN
  3956. RETURN currentTextView.InsertChar(newChar);
  3957. ELSE
  3958. RETURN -3;
  3959. END;
  3960. END InsertChar;
  3961. PROCEDURE Refresh*;
  3962. BEGIN
  3963. IF currentTextView # NIL THEN
  3964. currentTextView.layout.FullLayout(TRUE);
  3965. currentTextView.Invalidate;
  3966. currentTextView.CheckNumberOfLines;
  3967. END;
  3968. END Refresh;
  3969. PROCEDURE Cleanup;
  3970. BEGIN
  3971. cursorBlinker.Finalize;
  3972. END Cleanup;
  3973. PROCEDURE GenTextView*(): XML.Element;
  3974. VAR e : TextView;
  3975. BEGIN
  3976. NEW(e); RETURN e
  3977. END GenTextView;
  3978. BEGIN
  3979. NEW(cursorBlinker);
  3980. NEW(DefaultStyle);
  3981. Modules.InstallTermHandler(Cleanup);
  3982. InitStrings;
  3983. InitPrototypes;
  3984. manager := WMWindowManager.GetDefaultManager();
  3985. END WMTextView.