WMTextView.Mod 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415
  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 : LONGINT;
  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 : LONGINT;
  578. lineNumberFont, lineNumberFont10 : WMGraphics.Font;
  579. indicateTabs- : WMProperties.BooleanProperty;
  580. indicateTabsI : BOOLEAN;
  581. clBgCurrentLine- : WMProperties.ColorProperty;
  582. clBgCurrentLineI : LONGINT;
  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 : LONGINT;
  2078. cf: WMGraphics.Font;
  2079. style : RECORD
  2080. color, bgColor, voff : LONGINT;
  2081. font : WMGraphics.Font;
  2082. END;
  2083. BEGIN
  2084. IF TraceRenderOptimize IN Trace THEN
  2085. KernelLog.String("RenderLine : "); KernelLog.Int(linenr, 5); KernelLog.String(" from position : ");
  2086. KernelLog.Int(layout.GetLineStartPos(linenr), 5); KernelLog.Ln;
  2087. END;
  2088. sp := l.pos;
  2089. IF sp >= text.GetLength() THEN RETURN END;
  2090. style.color := defaultTextColorI;
  2091. canvas.SetColor(style.color); lastColor := style.color;
  2092. style.bgColor := defaultTextBgColorI;
  2093. style.voff := 0;
  2094. cf := GetFont();
  2095. style.font := cf;
  2096. IF llen < 0 THEN
  2097. linelength := layout.GetLineLength(linenr);
  2098. (* hack for the bidi formatter *)
  2099. IF linenr = layout.GetNofLines() - 1 THEN
  2100. DEC(linelength);
  2101. END;
  2102. ELSE
  2103. linelength := llen
  2104. END;
  2105. (* if there is a bidi formatter, reorder the current line *)
  2106. IF text.isUTF & (layout.bidiFormatter # NIL) THEN
  2107. bidiTextReader := layout.bidiFormatter.ReorderLine(sp,linelength);
  2108. END;
  2109. (* the bidi text reader needs special treatment for the initialization *)
  2110. IF (bidiTextReader # NIL) THEN
  2111. (* after reordering the line, contextual dependency rules are applied *)
  2112. bidiTextReader := ContextualDependency.AnalyzeLine(bidiTextReader,-1,-1);
  2113. layout.bidiFormatter.SetReadyTextReader(sp,bidiTextReader);
  2114. bidiTextReader.CloneProperties(utilreader);
  2115. localTextReader := bidiTextReader;
  2116. localTextReader.text.AcquireRead;
  2117. localTextReader.SetPosition(0);
  2118. ELSE
  2119. (* revert the hack for the bidi formatter *)
  2120. IF (llen < 0) & (linenr = layout.GetNofLines() - 1) THEN
  2121. INC(linelength);
  2122. END;
  2123. localTextReader := utilreader;
  2124. localTextReader.text.AcquireRead;
  2125. localTextReader.SetPosition(sp);
  2126. END;
  2127. i := 0;
  2128. x := GetLineLeftIndent(linenr);
  2129. sx := - leftShiftI + bordersI.l + x0;
  2130. IF TraceBaseLine IN Trace THEN
  2131. canvas.Line(0, top + (l.ascent), bounds.GetWidth(), top + (l.ascent), 01F0000FFH, WMGraphics.ModeCopy)
  2132. END;
  2133. selection.Sort;
  2134. IF (cursor.visible) & (selection.b - selection.a <= 0) & (clBgCurrentLineI # 0) THEN
  2135. cursorPosition := cursor.GetPosition();
  2136. IF (l.pos <= cursorPosition) & (cursorPosition < l.pos + linelength) THEN
  2137. canvas.Fill(WMRectangles.MakeRect(0, top, bounds.GetWidth() - bordersI.r, top + l.height), clBgCurrentLineI, WMGraphics.ModeSrcOverDst);
  2138. END;
  2139. END;
  2140. IF showLineNumbersI THEN
  2141. canvas.SaveState(canvasState);
  2142. Strings.IntToStr(linenr + 1, lineNumberString);
  2143. temp := WMRectangles.MakeRect(bordersI.l, top, x0 - 1, top + l.height);
  2144. IF (lineNumberBgColorI # 0) THEN
  2145. canvas.Fill(temp, lineNumberBgColorI, WMGraphics.ModeSrcOverDst);
  2146. END;
  2147. temp.r := temp.r - 4;
  2148. IF ((linenr + 1) MOD 10 = 0) THEN
  2149. canvas.SetFont(lineNumberFont10);
  2150. ELSE
  2151. canvas.SetFont(lineNumberFont);
  2152. END;
  2153. canvas.SetColor(lineNumberColorI);
  2154. WMGraphics.DrawStringInRect(canvas, temp, FALSE, WMGraphics.AlignRight, WMGraphics.AlignCenter, lineNumberString);
  2155. canvas.RestoreState(canvasState); (* restore font and font color *)
  2156. canvas.SaveState(canvasState);
  2157. canvas.GetClipRect(cliprect);
  2158. cliprect.l := x0;
  2159. canvas.SetClipRect(cliprect);
  2160. END;
  2161. w := bounds.GetWidth() - bordersI.r;
  2162. localTextReader.SetDirection(1);
  2163. lastEnd := -1;
  2164. highlighterStyle := NIL; lastHighlighterStyle := NIL;
  2165. currentStyle := DefaultStyle; lastStyle := NIL;
  2166. REPEAT
  2167. readerPosition := localTextReader.GetPosition();
  2168. localTextReader.ReadCh(char);
  2169. IF (highlighter # NIL) THEN
  2170. ASSERT(state # NIL);
  2171. IF (lastEnd < readerPosition) THEN
  2172. highlighterStyle := highlighter.GetRegionStyle(readerPosition, state, regionStart, regionEnd);
  2173. IF (highlighterStyle # NIL) THEN
  2174. lastEnd := regionEnd;
  2175. ELSE
  2176. IF (char > 32) THEN
  2177. highlighterStyle := highlighter.GetWordStyle(localTextReader, readerPosition, lastEnd);
  2178. END;
  2179. END;
  2180. localTextReader.SetPosition(readerPosition);
  2181. localTextReader.ReadCh(char); (* restore text reader state *)
  2182. END;
  2183. IF (highlighterStyle = NIL) THEN
  2184. highlighterStyle := highlighter.GetDefaultStyle();
  2185. END;
  2186. END;
  2187. IF (highlighterStyle = NIL) OR (highlighterStyle.defined * SyntaxHighlighter.DefineMask # SyntaxHighlighter.DefineMask) THEN
  2188. IF (localTextReader.cstyle # NIL) THEN
  2189. IF (currentStyle # localTextReader.cstyle) THEN
  2190. currentStyle := localTextReader.cstyle;
  2191. style.color := localTextReader.cstyle.color;
  2192. style.bgColor := localTextReader.cstyle.bgColor;
  2193. style.voff := localTextReader.cstyle.baselineShift;
  2194. IF (localTextReader.cstyle.fontcache # NIL) & (localTextReader.cstyle.fontcache IS WMGraphics.Font) THEN
  2195. style.font := localTextReader.cstyle.fontcache(WMGraphics.Font);
  2196. ELSE
  2197. style.font := WMGraphics.GetFont(localTextReader.cstyle.family, ENTIER(FP1616.FixpToFloat(localTextReader.cstyle.size)), localTextReader.cstyle.style);
  2198. localTextReader.cstyle.fontcache := style.font;
  2199. END;
  2200. END;
  2201. ELSIF (localTextReader.attributes # NIL) THEN
  2202. IF (currentStyle # localTextReader.attributes) THEN
  2203. currentStyle := localTextReader.attributes;
  2204. style.color := localTextReader.attributes.color;
  2205. style.bgColor := localTextReader.attributes.bgcolor;
  2206. style.voff := localTextReader.attributes.voff;
  2207. IF (localTextReader.attributes.fontInfo # NIL) THEN
  2208. IF (localTextReader.attributes.fontInfo.fontcache # NIL) & (localTextReader.attributes.fontInfo.fontcache IS WMGraphics.Font) THEN
  2209. style.font := localTextReader.attributes.fontInfo.fontcache (WMGraphics.Font);
  2210. ELSE
  2211. style.font := GetFontFromAttr(localTextReader.attributes.fontInfo);
  2212. localTextReader.attributes.fontInfo.fontcache := style.font;
  2213. END;
  2214. ELSE
  2215. style.font := cf;
  2216. END;
  2217. END;
  2218. ELSE
  2219. IF (currentStyle # DefaultStyle) THEN
  2220. currentStyle := DefaultStyle;
  2221. style.color := defaultTextColorI;
  2222. style.bgColor := defaultTextBgColorI;
  2223. style.voff := 0;
  2224. style.font := cf;
  2225. END;
  2226. END;
  2227. ASSERT(style.font # NIL);
  2228. END;
  2229. IF (highlighterStyle # NIL) THEN
  2230. IF (highlighterStyle # lastHighlighterStyle) OR (currentStyle # lastStyle) THEN
  2231. IF SyntaxHighlighter.Voff IN highlighterStyle.defined THEN style.voff := highlighterStyle.attributes.voff; END;
  2232. IF SyntaxHighlighter.Color IN highlighterStyle.defined THEN style.color := highlighterStyle.attributes.color; END;
  2233. IF SyntaxHighlighter.BgColor IN highlighterStyle.defined THEN style.bgColor := highlighterStyle.attributes.bgcolor; END;
  2234. IF (SyntaxHighlighter.FontMask * highlighterStyle.defined # {}) THEN
  2235. CheckFont(highlighterStyle, style.font, fontCache);
  2236. style.font := highlighterStyle.attributes.fontInfo.fontcache (WMGraphics.Font);
  2237. END;
  2238. END;
  2239. currentStyle := NIL; (* force reevaluation of localTextReader style *)
  2240. END;
  2241. lastStyle := currentStyle;
  2242. lastHighlighterStyle := highlighterStyle;
  2243. IF (style.color # lastColor) THEN canvas.SetColor(style.color); lastColor := style.color; END;
  2244. IF char = Texts.ObjectChar THEN
  2245. IF (localTextReader.object # NIL) & (localTextReader.object IS WMGraphics.Image) THEN
  2246. canvas.DrawImage(x, top + (l.ascent) + style.voff - localTextReader.object(WMGraphics.Image).height, localTextReader.object(WMGraphics.Image),
  2247. WMGraphics.ModeSrcOverDst);
  2248. dx := localTextReader.object(WMGraphics.Image).width
  2249. ELSIF (localTextReader.object # NIL) & (localTextReader.object IS WMComponents.VisualComponent) THEN
  2250. vc := localTextReader.object(WMComponents.VisualComponent);
  2251. dx := vc.bounds.GetWidth();
  2252. dy := vc.bounds.GetHeight();
  2253. canvas.SaveState(clipState); (* save the current clip-state *)
  2254. canvas.SetClipRect(WMRectangles.MakeRect(x + sx, top + (l.ascent - dy), x + dx + sx, top + (l.height)));
  2255. canvas.ClipRectAsNewLimits(x + sx, top + (l.ascent - dy));
  2256. (* assuming the component will not delay --> otherwise a buffer is needed *)
  2257. vc.Acquire; vc.Draw(canvas); vc.Release;
  2258. canvas.RestoreState(clipState)
  2259. END
  2260. ELSIF char = 0 THEN (* EOT *)
  2261. ELSIF char = Texts.TabChar THEN
  2262. tx := x;
  2263. IF l.firstInParagraph THEN tx := tx - l.firstIndent
  2264. ELSE tx := tx - l.leftIndent END;
  2265. IF l.tabStops # NIL THEN dx := l.tabStops.GetNextTabStop(tx) - tx
  2266. ELSE dx := defaultTabStops.GetNextTabStop(tx) - tx
  2267. END;
  2268. IF style.bgColor # 0 THEN
  2269. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), style.bgColor, WMGraphics.ModeSrcOverDst)
  2270. END;
  2271. IF indicateTabsI THEN canvas.SetPixel(x + sx + ((dx + 1) DIV 2), top + ((l.ascent + 1) DIV 2), WMGraphics.Blue, WMGraphics.ModeCopy); END;
  2272. ELSIF char = Texts.LabelChar THEN
  2273. IF showLabels.Get() THEN
  2274. font := cf;
  2275. font.GetStringSize(localTextReader.object(Texts.LabelPiece).label^, dx, dy);
  2276. font.RenderString(canvas, x + sx+2, top + (l.ascent), localTextReader.object(Texts.LabelPiece).label^);
  2277. INC(dx, 4);
  2278. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), LONGINT(0FF880050H), WMGraphics.ModeSrcOverDst);
  2279. WMGraphicUtilities.RectGlassShade(canvas, WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), 1, FALSE)
  2280. ELSE dx := 0; END;
  2281. ELSE
  2282. IF char = Texts.NewLineChar THEN
  2283. localTextReader.text.ReleaseRead;
  2284. IF showLineNumbersI THEN canvas.RestoreState(canvasState); END;
  2285. RETURN
  2286. END;
  2287. IF isPasswordI THEN
  2288. char := passwordChar.Get()
  2289. END;
  2290. (* If the text is utf-formatted get the display version of the character.
  2291. Note, that only some special invisible characters differ from their actual representation. *)
  2292. IF text.isUTF THEN
  2293. UnicodeBidirectionality.GetDisplayCharacter(char);
  2294. END;
  2295. hc := style.font.HasChar(char);
  2296. IF hc THEN style.font.GetGlyphSpacings(char, gs)
  2297. ELSE WMGraphics.FBGetGlyphSpacings(char, gs)
  2298. END;
  2299. dx := gs.bearing.l + gs.width + gs.bearing.r;
  2300. IF style.bgColor MOD 256 # 0 THEN
  2301. canvas.Fill(WMRectangles.MakeRect(x + sx, top, x + dx + sx, top + (l.height)), style.bgColor, WMGraphics.ModeCopy)
  2302. END;
  2303. IF hc THEN style.font.RenderChar(canvas, x + sx, top + (l.ascent) + style.voff, char)
  2304. ELSE WMGraphics.FBRenderChar(canvas, x + sx, top + (l.ascent) + style.voff, char)
  2305. END
  2306. END;
  2307. (* link *)
  2308. IF localTextReader.link # NIL THEN
  2309. canvas.Line(x + sx, top + (l.ascent)+1, x + dx + sx, top + (l.ascent)+1, canvas.color, WMGraphics.ModeSrcOverDst);
  2310. END;
  2311. (* highlight - since highlights store the global text position, the line's starting position needs to be added,
  2312. when operating on the local, bidirectional text reader. *)
  2313. IF bidiTextReader # NIL THEN
  2314. p := GetInternalPos(localTextReader.GetPosition()+sp-1);
  2315. ELSE
  2316. p := localTextReader.GetPosition() - 1;
  2317. END;
  2318. FOR j := 0 TO nofHighlights - 1 DO
  2319. IF (p >= highlights[j].a) & (p < highlights[j].b) THEN
  2320. CASE highlights[j].kind OF
  2321. |HLOver: canvas.Fill(WMGraphics.MakeRectangle(x + sx, top, x + dx + sx, top + (l.height)), highlights[j].color, WMGraphics.ModeSrcOverDst)
  2322. |HLUnder: canvas.Line(x + sx, top + (l.ascent), x + dx + sx, top + (l.ascent), highlights[j].color, WMGraphics.ModeSrcOverDst);
  2323. |HLWave:
  2324. FOR k := 0 TO dx - 1 DO
  2325. t := 1 - ABS((x + k) MOD 4 - 2); (* because of compiler bug on intel *)
  2326. canvas.SetPixel(x + k + sx, top + l.ascent + t, highlights[j].color, WMGraphics.ModeSrcOverDst);
  2327. END;
  2328. ELSE
  2329. END
  2330. END
  2331. END;
  2332. x := x + dx;
  2333. INC(i)
  2334. UNTIL (i >= linelength) OR localTextReader.eot OR (x + sx > w);
  2335. localTextReader.text.ReleaseRead;
  2336. IF showLineNumbersI THEN canvas.RestoreState(canvasState); END;
  2337. END RenderLine;
  2338. PROCEDURE RenderAboveTextMarkers*(canvas : WMGraphics.Canvas);
  2339. VAR x, y, l, pos, i, ascent : LONGINT;
  2340. BEGIN
  2341. AssertLock;
  2342. IF text = NIL THEN RETURN END;
  2343. IF optimize THEN RETURN END;
  2344. text.AcquireRead;
  2345. FOR i := nofPositionMarkers - 1 TO 0 BY -1 DO
  2346. pos := positionMarkers[i].pos.GetPosition();
  2347. l := layout.FindLineNrByPos(pos);
  2348. IF FindScreenPos(pos, x, y) THEN
  2349. IF (l >= 0) & (l < layout.GetNofLines()) THEN
  2350. ascent := layout.lines[l].ascent;
  2351. (* IF ascent = 0 THEN ascent := layout.lines[l].height END;
  2352. IF ascent = 0 THEN ascent := 10 END; *)
  2353. ELSE ascent := 10 END;
  2354. positionMarkers[i].Draw(canvas, x, y, ascent)
  2355. END
  2356. END;
  2357. text.ReleaseRead;
  2358. END RenderAboveTextMarkers;
  2359. PROCEDURE DrawBackground*(canvas : WMGraphics.Canvas);
  2360. VAR la, lb, i, top, t, b : LONGINT; rect, clip : WMRectangles.Rectangle; cstate : WMGraphics.CanvasState;
  2361. BEGIN
  2362. ASSERT(layout # NIL);
  2363. canvas.GetClipRect(clip);
  2364. IF WMRectangles.RectEmpty(clip) THEN RETURN END;
  2365. rect := GetClientRect();
  2366. canvas.SaveState(cstate);
  2367. IF WMRectangles.Intersect(rect, clip) THEN
  2368. DrawBackground^(canvas);
  2369. IF showBorderI THEN
  2370. WMGraphicUtilities.DrawBevel(canvas, rect,
  2371. 1, TRUE, LONGINT(0808080FFH), WMGraphics.ModeCopy)
  2372. END;
  2373. END;
  2374. (* allow clean clipping in at inner border *)
  2375. WMRectangles.ClipRect(rect, borderClip);
  2376. WMRectangles.ClipRect(clip, borderClip);
  2377. canvas.SetClipRect(clip);
  2378. (* draw gutter *)
  2379. rect.r := x0 - 1;
  2380. IF showLineNumbersI & (lineNumberBgColorI # 0) & WMRectangles.Intersect(rect, clip) THEN
  2381. canvas.Fill(rect, lineNumberBgColorI, WMGraphics.ModeSrcOverDst);
  2382. END;
  2383. text.AcquireRead;
  2384. la := FindLineByY(firstLineI, clip.t);
  2385. lb := FindLineByY(firstLineI, clip.b);
  2386. (* prepare selections *)
  2387. FOR i := 0 TO nofHighlights - 1 DO
  2388. highlights[i].a := highlights[i].from.GetPosition();
  2389. highlights[i].b := highlights[i].to.GetPosition();
  2390. IF highlights[i].a > highlights[i].b THEN t := highlights[i].a; highlights[i].a := highlights[i].b; highlights[i].b := t END
  2391. END;
  2392. top := borderClip.t;
  2393. IF (la = lb) & (textAlignV.Get() = WMGraphics.AlignCenter) THEN
  2394. top := (borderClip.t+borderClip.b-layout.lines[la].height) DIV 2;
  2395. (* something is wrong with ascent and height here, does not comply with the notions in fonts *)
  2396. END;
  2397. FOR i := firstLineI TO la - 1 DO
  2398. top := top + (layout.lines[i].height);
  2399. CheckParagraphBegin(i, top);
  2400. CheckParagraphEnd(i, top);
  2401. END;
  2402. IF la >= 0 THEN
  2403. (* draw the lines that intersect the clipping rectangle *)
  2404. FOR i := la TO lb DO
  2405. CheckParagraphBegin(i, top);
  2406. RenderLine(canvas, layout.lines[i], i, top, -1);
  2407. top := top + (layout.lines[i].height);
  2408. CheckParagraphEnd(i, top);
  2409. END
  2410. END;
  2411. RenderAboveTextMarkers(canvas);
  2412. text.ReleaseRead;
  2413. canvas.RestoreState(cstate);
  2414. END DrawBackground;
  2415. PROCEDURE StoreLineEnter;
  2416. VAR pos, cl : LONGINT;
  2417. BEGIN
  2418. pos := cursor.GetPosition();
  2419. cl := layout.FindLineNrByPos(pos);
  2420. lineEnter := pos - layout.GetLineStartPos(cl)
  2421. END StoreLineEnter;
  2422. (* navigation *)
  2423. PROCEDURE WheelMove*(dz: LONGINT); (** PROTECTED *)
  2424. VAR ddz: DZ;
  2425. BEGIN
  2426. IF modifierFlags * Inputs.Ctrl # {} THEN (* CTRL pressed -> Resize Font*)
  2427. text.AcquireWrite;
  2428. NEW(ddz, dz);
  2429. text.UpdateAttributes(0, text.GetLength(), ChangeAttribute, ddz);
  2430. text.ReleaseWrite;
  2431. ELSIF mouseWheelScrollSpeedI # 0 THEN
  2432. firstLine.Set(firstLine.Get() + mouseWheelScrollSpeedI * dz)
  2433. END;
  2434. END WheelMove;
  2435. (* abort a possible start of a command. Clear the command start indicator, if it was set *)
  2436. PROCEDURE AbortStart;
  2437. BEGIN
  2438. ASSERT(IsCallFromSequencer());
  2439. IF commandMarker # NIL THEN
  2440. RemoveHighlight(commandMarker);
  2441. commandMarker := NIL
  2442. END;
  2443. canStart := FALSE
  2444. END AbortStart;
  2445. (*
  2446. Handle double-click at text position <pos>.
  2447. Select the double-clicked word, whitespace or line.
  2448. Some explanations:
  2449. Why utilreader.GetPosition()+2 when searching to the left?
  2450. After we read the last character that should be included, the position of the reader is decremented.
  2451. When we now read the next character and see that it should not be included, the reader is decremented again.
  2452. -> The last character to be included was found at position utilreader.GetPosition()+2 (except when we reach EOT)
  2453. 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.
  2454. That's why utilreader.GetPosition()-1 is used instead of utilreader.GetPosition()-2.
  2455. *)
  2456. PROCEDURE DoubleClickSelect(pos : LONGINT);
  2457. CONST
  2458. LineFeed = 0AH;
  2459. Underscore = 05FH;
  2460. VAR
  2461. char : Texts.Char32;
  2462. from, to : LONGINT;
  2463. BEGIN
  2464. ASSERT(text.HasReadLock());
  2465. utilreader.SetPosition(pos);
  2466. utilreader.SetDirection(1);
  2467. utilreader.ReadCh(char);
  2468. IF (char = LineFeed) OR utilreader.eot THEN (* select line *)
  2469. IF utilreader.eot THEN to := pos;
  2470. ELSE to := pos+1;
  2471. END;
  2472. from := TextUtilities.FindPosLineStart(utilreader, pos);
  2473. ELSIF TextUtilities.IsWhiteSpace(char,text.isUTF) THEN
  2474. WHILE ~utilreader.eot & TextUtilities.IsWhiteSpace(char,text.isUTF) & (char # LineFeed) DO utilreader.ReadCh(char); END;
  2475. IF utilreader.eot THEN to := utilreader.text.GetLength();
  2476. ELSE to := utilreader.GetPosition()-1;
  2477. END;
  2478. utilreader.SetPosition(pos);
  2479. utilreader.SetDirection(-1);
  2480. utilreader.ReadCh(char);
  2481. WHILE ~utilreader.eot & TextUtilities.IsWhiteSpace(char,text.isUTF) & (char # LineFeed) DO utilreader.ReadCh(char); END;
  2482. IF utilreader.eot THEN from := 0;
  2483. ELSE from := utilreader.GetPosition()+2;
  2484. END;
  2485. ELSIF TextUtilities.IsAlphaNum(char) OR (char = Underscore) THEN (* select word *)
  2486. WHILE ~utilreader.eot & (TextUtilities.IsAlphaNum(char) OR (char = Underscore)) DO utilreader.ReadCh(char); END;
  2487. IF utilreader.eot THEN to := utilreader.text.GetLength();
  2488. ELSE to := utilreader.GetPosition()-1;
  2489. END;
  2490. utilreader.SetPosition(pos);
  2491. utilreader.SetDirection(-1);
  2492. utilreader.ReadCh(char);
  2493. WHILE ~utilreader.eot & (TextUtilities.IsAlphaNum(char) OR (char = Underscore)) DO utilreader.ReadCh(char); END;
  2494. IF utilreader.eot THEN from := 0;
  2495. ELSE from := utilreader.GetPosition()+2;
  2496. END;
  2497. ELSE (* select the character at text position pos *)
  2498. from := pos; to := pos+1;
  2499. END;
  2500. selection.SetFromTo(from, to);
  2501. cursor.SetVisible(to - from > 0);
  2502. END DoubleClickSelect;
  2503. PROCEDURE SetInterclick(new : LONGINT);
  2504. VAR old : LONGINT;
  2505. BEGIN
  2506. old := interclick;
  2507. IF (old # new) THEN
  2508. interclick := new;
  2509. CASE new OF
  2510. | Interclick01: selection.SetColor(SelectionColorInterclick01);
  2511. | Interclick02: selection.SetColor(SelectionColorInterclick02);
  2512. ELSE
  2513. selection.SetColor(SelectionColor);
  2514. END;
  2515. END;
  2516. END SetInterclick;
  2517. PROCEDURE PointerDown*(x, y : LONGINT; keys : SET);
  2518. VAR pos, a, b, internalPos : LONGINT; oldInterclick : LONGINT;
  2519. BEGIN
  2520. ViewToTextPos(x,y,pos);
  2521. internalPos := GetInternalPos(pos);
  2522. oldInterclick := interclick;
  2523. IF (keys * {0, 1} = {0,1}) THEN SetInterclick(Interclick01);
  2524. ELSIF (keys * {0,2} = {0,2}) THEN SetInterclick(Interclick02);
  2525. ELSE SetInterclick(InterclickNone);
  2526. END;
  2527. (* Determine whether to cancel an interclick if any *)
  2528. IF (oldInterclick = InterclickCancelled) OR
  2529. ((oldInterclick # InterclickNone) & (interclick # InterclickNone)) THEN
  2530. SetInterclick(InterclickCancelled);
  2531. END;
  2532. IF allowCommandExecution.Get() & (keys * {0, 1, 2} = {1}) THEN
  2533. canStart := TRUE; openFile := FALSE;
  2534. IF commandMarker = NIL THEN
  2535. commandMarker := CreateHighlight();
  2536. commandMarker.SetKind(HLUnder);
  2537. commandMarker.SetColor(LONGINT(0FF0000FFH));
  2538. text.AcquireRead;
  2539. FindCommand(internalPos, a, b);
  2540. commandMarker.SetFromTo(a, b);
  2541. cursor.SetPosition(pos);
  2542. text.ReleaseRead
  2543. END;
  2544. END;
  2545. IF canStart & (2 IN keys) THEN openFile := TRUE; SetInterclick(InterclickCancelled); END;
  2546. IF keys * {0, 1, 2} = {0, 1, 2} THEN AbortStart END;
  2547. IF allowPiemenu.Get() & (keys * {0, 1, 2} = {2}) THEN
  2548. text.AcquireRead;
  2549. ViewToTextPos(x, y, pos);
  2550. cursor.SetPosition(pos);
  2551. text.ReleaseRead;
  2552. ShowContextMenu(x, y)
  2553. END;
  2554. IF allowTextSelection.Get() &
  2555. ( (keys * {0, 1, 2} = {0}) (* left mouse for select *)
  2556. OR (keys * {0, 1, 2} = {1}) & doubleclickedWord (* remove selection when double clicking *)
  2557. OR (keys * {0,1,2} = {2}) & (~allowPiemenu.Get())) (* right mouse for selection if pie menu is not enabled *)
  2558. THEN
  2559. AbortStart;
  2560. text.AcquireRead;
  2561. ViewToTextPos(x, y, pos);
  2562. dragPossible := FALSE; selectWords := FALSE;
  2563. IF internalPos >= 0 THEN
  2564. selection.Sort;
  2565. IF (internalPos >= selection.a) & (internalPos < selection.b) & (interclick = InterclickNone) THEN
  2566. dragPossible := TRUE; downX := x; downY := y
  2567. ELSIF (interclick = InterclickNone) THEN
  2568. (* clicking the same position twice --> Word Selection Mode *)
  2569. IF (internalPos = GetInternalPos(cursor.GetPosition())) OR ((internalPos - 1 = GetInternalPos(cursor.GetPosition())) & (internalPos - 1 = text.GetLength())) THEN
  2570. (* Workaround: The 2nd check is for the very last line of a text. LayoutLine gives pos = text.GetLength()+1 *)
  2571. selectWords := TRUE; wordSelOrdered := TRUE;
  2572. doubleclickedWord := TRUE;
  2573. DoubleClickSelect(internalPos);
  2574. ELSE
  2575. selection.SetFromTo(internalPos, internalPos); (* reset selection *)
  2576. cursor.SetVisible(TRUE);
  2577. END;
  2578. selecting := TRUE;
  2579. END
  2580. END;
  2581. cursor.SetPosition(pos);
  2582. text.ReleaseRead;
  2583. CursorChanged
  2584. END;
  2585. END PointerDown;
  2586. PROCEDURE PointerMove*(x, y : LONGINT; keys : SET);
  2587. VAR pos, a, b, internalPos : LONGINT;
  2588. BEGIN
  2589. IF ~canStart & dragPossible THEN
  2590. IF (ABS(x - downX) > DragDist) OR (ABS(y - downY) > DragDist) THEN dragPossible := FALSE; AutoStartDrag END
  2591. ELSE
  2592. IF (selecting OR canStart) & (interclick = InterclickNone) THEN
  2593. text.AcquireRead;
  2594. ViewToTextPos(x, y, pos);
  2595. internalPos := GetInternalPos(pos);
  2596. IF selecting & ~doubleclickedWord THEN
  2597. selection.Sort;
  2598. IF selectWords THEN
  2599. IF internalPos < selection.from.GetPosition() THEN
  2600. pos := TextUtilities.FindPosWordLeft(utilreader, internalPos - 1);
  2601. ELSE
  2602. pos := TextUtilities.FindPosWordRight(utilreader, internalPos + 1);
  2603. END;
  2604. selection.SetTo(internalPos)
  2605. ELSE
  2606. selection.SetTo(internalPos);
  2607. END;
  2608. selection.Sort;
  2609. cursor.SetVisible(selection.b - selection.a <= 0);
  2610. Texts.SetLastSelection(text, selection.from, selection.to);
  2611. cursor.SetPosition(pos);
  2612. StoreLineEnter;
  2613. ELSIF canStart THEN
  2614. IF commandMarker # NIL THEN
  2615. FindCommand(internalPos, a, b);
  2616. commandMarker.SetFromTo(a, b)
  2617. END
  2618. END;
  2619. IF doubleclickedWord THEN doubleclickedWord := FALSE; END; (* allow selecting again *)
  2620. text.ReleaseRead;
  2621. CursorChanged
  2622. END
  2623. END
  2624. END PointerMove;
  2625. PROCEDURE PointerUp*(x, y : LONGINT; keys : SET);
  2626. BEGIN
  2627. IF canStart & (commandMarker # NIL) THEN
  2628. commandMarker.Sort;
  2629. StartCommand((commandMarker.a + commandMarker.b) DIV 2, openFile);
  2630. AbortStart
  2631. END;
  2632. IF modifierFlags * Inputs.Ctrl # {} THEN
  2633. onCtrlClicked.Call(NIL)
  2634. END;
  2635. selecting := FALSE;
  2636. doubleclickedWord := FALSE;
  2637. IF (keys * {0,1,2} = {}) THEN
  2638. IF (interclick = Interclick02) THEN
  2639. DeleteSelection;
  2640. END;
  2641. SetInterclick(InterclickNone);
  2642. END;
  2643. IF dragPossible THEN selection.SetFromTo(0, 0); cursor.SetVisible(TRUE); Texts.ClearLastSelection (* reset selection *) END;
  2644. dragPossible := FALSE
  2645. END PointerUp;
  2646. (* Transforms the TextView Coordinates into TextObject obj Coordinates *)
  2647. PROCEDURE TransformCoordinates(VAR x, y : LONGINT; obj : WMComponents.VisualComponent);
  2648. VAR line, pos, x0, y0, y1 : LONGINT;
  2649. BEGIN
  2650. ViewToTextPos(x, y, pos);
  2651. IF FindScreenPos(pos, x0, y0) THEN
  2652. IF x0 > x THEN pos := pos - 1;
  2653. IF FindScreenPos(pos, x0, y0) THEN END;
  2654. END;
  2655. line := layout.FindLineNrByPos(GetInternalPos(pos));
  2656. LineYPos(line, y0, y1);
  2657. x := x - x0;
  2658. y := y - y0;
  2659. IF line >= 0 THEN y := y - (layout.lines[line].ascent - obj.bounds.GetHeight()); END
  2660. END
  2661. END TransformCoordinates;
  2662. (* Change the pointer according to the underlaying component *)
  2663. PROCEDURE ChangePointer(pointerInfo : WMWindowManager.PointerInfo);
  2664. BEGIN
  2665. IF GetPointerInfo() # pointerInfo THEN
  2666. SetPointerInfo(pointerInfo)
  2667. END
  2668. END ChangePointer;
  2669. (* Returns TRUE if an Object is Hit, FALSE otherwise *)
  2670. PROCEDURE HitObject(x, y : LONGINT; (* keys : SET;*) VAR pos : LONGINT; VAR obj : ANY): BOOLEAN;
  2671. VAR ch, tx, ty : LONGINT;
  2672. BEGIN
  2673. text.AcquireRead;
  2674. ViewToTextPos(x, y, pos);
  2675. IF FindScreenPos(pos, tx, ty) THEN
  2676. IF tx > x THEN pos := pos - 1 END
  2677. END;
  2678. utilreader.SetPosition(GetInternalPos(pos));
  2679. utilreader.ReadCh(ch);
  2680. text.ReleaseRead;
  2681. IF ch = Texts.ObjectChar THEN obj := utilreader.object;
  2682. RETURN TRUE
  2683. ELSE
  2684. RETURN FALSE
  2685. END
  2686. END HitObject;
  2687. (* Returns TRUE if a Link is Hit, FALSE otherwise *)
  2688. PROCEDURE HitLink(x, y : LONGINT; VAR pos : LONGINT; VAR link : Texts.Link): BOOLEAN;
  2689. VAR ch, tx, ty : LONGINT;
  2690. BEGIN
  2691. text.AcquireRead;
  2692. ViewToTextPos(x, y, pos);
  2693. IF FindScreenPos(pos, tx, ty) THEN
  2694. IF tx > x THEN pos := pos - 1 END
  2695. END;
  2696. utilreader.SetPosition(GetInternalPos(pos));
  2697. utilreader.ReadCh(ch);
  2698. text.ReleaseRead;
  2699. IF utilreader.link # NIL THEN
  2700. link := utilreader.link;
  2701. RETURN TRUE
  2702. ELSE
  2703. RETURN FALSE
  2704. END
  2705. END HitLink;
  2706. PROCEDURE LinkClick(link : Texts.Link);
  2707. VAR w : LinkWrapper;
  2708. BEGIN
  2709. NEW(w); w.link := link;
  2710. onLinkClicked.Call(w)
  2711. END LinkClick;
  2712. (* builtin behaviour *)
  2713. PROCEDURE LinkClicked*(sender, data : ANY);
  2714. VAR tempLink : ARRAY 2048 OF CHAR;
  2715. tempLabel : ARRAY 256 OF CHAR;
  2716. pos, i : LONGINT;
  2717. BEGIN
  2718. IF data IS LinkWrapper THEN
  2719. COPY(data(LinkWrapper).link^, tempLink);
  2720. IF tempLink[0] = "#" THEN (* internal link *)
  2721. i := 0;
  2722. WHILE tempLink[i] # 0X DO
  2723. tempLabel[i] := tempLink[i+1];
  2724. INC(i);
  2725. END;
  2726. tempLink[i] := 0X;
  2727. (* find label in tv *)
  2728. IF FindLabel(tempLabel, pos) THEN
  2729. i := layout.nofLines-1;
  2730. WHILE (i >= 0) DO
  2731. IF layout.GetLineStartPos(i) < pos THEN firstLine.Set(i); RETURN END;
  2732. DEC(i);
  2733. END;
  2734. END;
  2735. ELSE (* other links *)
  2736. END
  2737. END
  2738. END LinkClicked;
  2739. (* Returns the position of the label in text *)
  2740. PROCEDURE FindLabel*(CONST label : ARRAY OF CHAR; VAR pos : LONGINT): BOOLEAN;
  2741. VAR ch : LONGINT;
  2742. found : BOOLEAN;
  2743. BEGIN
  2744. found := FALSE; pos := 0;
  2745. text.AcquireRead;
  2746. utilreader.SetDirection(1); utilreader.SetPosition(pos);
  2747. REPEAT
  2748. utilreader.ReadCh(ch);
  2749. IF ch = Texts.LabelChar THEN
  2750. IF utilreader.object(Texts.LabelPiece).label^ = label THEN
  2751. found := TRUE;
  2752. END;
  2753. END;
  2754. INC(pos);
  2755. UNTIL utilreader.eot OR found;
  2756. text.ReleaseRead;
  2757. RETURN found;
  2758. END FindLabel;
  2759. (* Drag away operations *)
  2760. PROCEDURE AutoStartDrag*;
  2761. VAR img : WMGraphics.Image;
  2762. c : WMGraphics.BufferCanvas;
  2763. w, h, i, la, lb, top : LONGINT;
  2764. l : LineInfo;
  2765. BEGIN
  2766. text.AcquireRead;
  2767. selection.Sort;
  2768. NEW(dragSelA, text);NEW(dragSelB, text);
  2769. dragSelA.SetPosition(selection.a); dragSelB.SetPosition(selection.b);
  2770. la := Limit(layout.FindLineNrByPos(selection.a), 0, layout.GetNofLines() - 1);
  2771. lb := Limit(layout.FindLineNrByPos(selection.b), 0, layout.GetNofLines() - 1);
  2772. (* estimate the size of the selection *)
  2773. h := 0; w := 0;
  2774. FOR i := la TO lb DO
  2775. h := h + (layout.lines[i].height);
  2776. w := Strings.Max(w, layout.lines[i].width);
  2777. END;
  2778. h := Limit(h, 20, 200);
  2779. w := Limit(w, 20, 400);
  2780. (* render to bitmap *)
  2781. NEW(img); Raster.Create(img, w, h, Raster.BGRA8888);
  2782. NEW(c, img);
  2783. top := 0;
  2784. (* hack the startpos of the first line *)
  2785. l := layout.lines[la]; l.pos := selection.a;
  2786. IF la = lb THEN RenderLine(c, l, la, top, selection.b - selection.a)
  2787. ELSE
  2788. RenderLine(c, l, la, top, -1);
  2789. top := top + l.height
  2790. END;
  2791. FOR i := la + 1 TO lb DO
  2792. IF i = lb THEN
  2793. RenderLine(c, layout.lines[i], i, top, selection.b - layout.lines[i].pos)
  2794. ELSE
  2795. RenderLine(c, layout.lines[i], i, top, -1);
  2796. top := top + (l.height)
  2797. END
  2798. END;
  2799. text.ReleaseRead;
  2800. IF StartDrag(NIL, img, 0,0,DragWasAccepted, NIL) THEN
  2801. ELSE KernelLog.String("WMTextView : Drag could not be started")
  2802. END;
  2803. END AutoStartDrag;
  2804. PROCEDURE DragWasAccepted(sender, data : ANY);
  2805. VAR di : WMWindowManager.DragInfo;
  2806. dt : WMDropTarget.DropTarget;
  2807. itf : WMDropTarget.DropInterface;
  2808. targetText, temp : Texts.Text;
  2809. string : Strings.String;
  2810. pos, a, b, res : LONGINT;
  2811. BEGIN
  2812. IF (dragSelA = NIL) OR (dragSelB = NIL) THEN RETURN END;
  2813. IF (data # NIL) & (data IS WMWindowManager.DragInfo) THEN
  2814. di := data(WMWindowManager.DragInfo);
  2815. IF (di.data # NIL) & (di.data IS WMDropTarget.DropTarget) THEN
  2816. dt := di.data(WMDropTarget.DropTarget)
  2817. ELSE RETURN
  2818. END
  2819. ELSE RETURN
  2820. END;
  2821. itf := dt.GetInterface(WMDropTarget.TypeText);
  2822. IF itf # NIL THEN
  2823. targetText := itf(WMDropTarget.DropText).text;
  2824. IF targetText # NIL THEN
  2825. targetText.AcquireWrite;
  2826. IF ~dragCopy THEN
  2827. IF TraceCopy IN Trace THEN KernelLog.String("WMTextView: Not copy"); KernelLog.Ln; END;
  2828. text.AcquireWrite;
  2829. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2830. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2831. IF (targetText # text) OR (pos < a) OR (pos > b) THEN
  2832. NEW(temp); temp.AcquireWrite; temp.CopyFromText(text, a, b-a, 0); temp.ReleaseWrite;
  2833. text.Delete(a, b- a);
  2834. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2835. temp.AcquireRead;
  2836. targetText.CopyFromText(temp, 0, temp.GetLength(), pos);
  2837. temp.ReleaseRead;
  2838. END;
  2839. text.ReleaseWrite
  2840. ELSE
  2841. IF TraceCopy IN Trace THEN KernelLog.String("WMTextView: Copy"); KernelLog.Ln; END;
  2842. text.AcquireRead;
  2843. pos := itf(WMDropTarget.DropText).pos.GetPosition();
  2844. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2845. targetText.CopyFromText(text, a, b-a, pos);
  2846. text.ReleaseRead;
  2847. END;
  2848. targetText.ReleaseWrite
  2849. END;
  2850. RETURN
  2851. END;
  2852. itf := dt.GetInterface(WMDropTarget.TypeString);
  2853. IF (itf # NIL) THEN
  2854. IF ~dragCopy THEN
  2855. text.AcquireWrite;
  2856. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2857. NEW(temp);
  2858. temp.AcquireWrite;
  2859. temp.CopyFromText(text, a, b-a, 0);
  2860. IF (temp.GetLength() > 0) THEN NEW(string, temp.GetLength() * 5); ELSE NEW(string, 1); string[0] := 0X; END;
  2861. temp.ReleaseWrite;
  2862. text.ReleaseWrite;
  2863. TextUtilities.TextToStr(temp, string^);
  2864. itf(WMDropTarget.DropString).Set(string^, res);
  2865. IF res = 0 THEN
  2866. text.AcquireWrite;
  2867. text.Delete(a, b- a);
  2868. text.ReleaseWrite;
  2869. END;
  2870. ELSE
  2871. text.AcquireRead;
  2872. a := dragSelA.GetPosition(); b := dragSelB.GetPosition();
  2873. NEW(temp);
  2874. temp.AcquireWrite;
  2875. temp.CopyFromText(text, a, b-a, 0);
  2876. IF (temp.GetLength() > 0) THEN NEW(string, temp.GetLength() * 5); ELSE NEW(string, 1); string[0] := 0X; END;
  2877. temp.ReleaseWrite;
  2878. text.ReleaseRead;
  2879. TextUtilities.TextToStr(temp, string^);
  2880. itf(WMDropTarget.DropString).Set(string^, res);
  2881. END;
  2882. END;
  2883. END DragWasAccepted;
  2884. (* Drag onto operations *)
  2885. PROCEDURE DragOver(x, y : LONGINT; dragInfo : WMWindowManager.DragInfo);
  2886. VAR pos : LONGINT;
  2887. BEGIN
  2888. IF takesFocus.Get() THEN
  2889. text.AcquireRead;
  2890. ViewToTextPos(x, y, pos);
  2891. cursor.SetVisible(TRUE);
  2892. cursor.SetPosition(pos);
  2893. StoreLineEnter;
  2894. text.ReleaseRead
  2895. END;
  2896. END DragOver;
  2897. PROCEDURE ConfirmDrag(accept: BOOLEAN; dragInfo: WMWindowManager.DragInfo);
  2898. BEGIN
  2899. IF dragInfo.onAccept # NIL THEN
  2900. dragInfo.onAccept(SELF, dragInfo)
  2901. END;
  2902. END ConfirmDrag;
  2903. PROCEDURE DragDropped*(x, y : LONGINT; dragInfo : WMWindowManager.DragInfo);
  2904. VAR dropTarget : TextDropTarget;
  2905. pos, internalPos : LONGINT;
  2906. p : Texts.TextPosition;
  2907. BEGIN
  2908. IF takesFocus.Get() THEN
  2909. text.AcquireRead;
  2910. ViewToTextPos(x, y, pos) ;
  2911. (* prevent a selection from being dropped behind the paragraph separator *)
  2912. internalPos := GetInternalPos(pos);
  2913. IF text.isUTF & (layout.bidiFormatter # NIL) THEN
  2914. IF layout.bidiFormatter.IsLastCharacterInLine(internalPos) THEN
  2915. DEC(internalPos);
  2916. END;
  2917. END;
  2918. NEW(p, text); p.SetPosition(internalPos);
  2919. NEW(dropTarget, text, p);
  2920. text.ReleaseRead;
  2921. IF ~hasFocus & ~alwaysShowCursorI THEN cursor.SetVisible(FALSE) END;
  2922. dragInfo.data := dropTarget;
  2923. ConfirmDrag(TRUE, dragInfo);
  2924. ELSE
  2925. ConfirmDrag(FALSE, dragInfo);
  2926. END;
  2927. END DragDropped;
  2928. PROCEDURE CopySelection*;
  2929. BEGIN
  2930. IF isPassword.Get() THEN RETURN END;
  2931. text.AcquireRead;
  2932. Texts.clipboard.AcquireWrite;
  2933. selection.Sort;
  2934. IF selection.b - selection.a > 0 THEN
  2935. (* clear the clipboard *)
  2936. IF Texts.clipboard.GetLength() > 0 THEN Texts.clipboard.Delete(0, Texts.clipboard.GetLength()) END;
  2937. Texts.clipboard.CopyFromText(text, selection.a, selection.b - selection.a, 0);
  2938. END;
  2939. Texts.clipboard.ReleaseWrite;
  2940. text.ReleaseRead
  2941. END CopySelection;
  2942. PROCEDURE DeleteSelection*;
  2943. BEGIN
  2944. Acquire; (* protect cursor *)
  2945. text.AcquireWrite;
  2946. selection.Sort;
  2947. text.Delete(selection.a, selection.b - selection.a);
  2948. cursor.SetVisible(TRUE);
  2949. text.ReleaseWrite;
  2950. Release;
  2951. END DeleteSelection;
  2952. PROCEDURE Paste*;
  2953. BEGIN
  2954. text.AcquireWrite;
  2955. Texts.clipboard.AcquireRead;
  2956. IF Texts.clipboard.GetLength() > 0 THEN
  2957. IF selection.b - selection.a # 0 THEN DeleteSelection() END;
  2958. text.CopyFromText(Texts.clipboard, 0, Texts.clipboard.GetLength(), cursor.GetPosition())
  2959. END;
  2960. Texts.clipboard.ReleaseRead;
  2961. text.ReleaseWrite
  2962. END Paste;
  2963. PROCEDURE SelectAll*;
  2964. BEGIN
  2965. Acquire; (* protect cursor *)
  2966. text.AcquireRead;
  2967. selection.SetFromTo(0, text.GetLength());
  2968. cursor.SetVisible(text.GetLength() <= 0);
  2969. Texts.SetLastSelection(text, selection.from, selection.to);
  2970. text.ReleaseRead;
  2971. Release;
  2972. END SelectAll;
  2973. (* Prepare to start the selection by keyboard. Clear the selection, if it is not contigous *)
  2974. PROCEDURE KeyStartSelection(pos : LONGINT);
  2975. BEGIN
  2976. IF selection.to.GetPosition() # pos THEN selection.SetFromTo(pos, pos); cursor.SetVisible(TRUE); Texts.ClearLastSelection END;
  2977. END KeyStartSelection;
  2978. (* update the keyboard selection with the new position, redraw from the last StartSelection *)
  2979. PROCEDURE KeyUpdateSelection(pos : LONGINT);
  2980. BEGIN
  2981. selection.SetTo(pos);
  2982. selection.Sort;
  2983. cursor.SetVisible(selection.b - selection.a <= 0);
  2984. Texts.SetLastSelection(text, selection.from, selection.to)
  2985. END KeyUpdateSelection;
  2986. PROCEDURE CursorChanged;
  2987. BEGIN
  2988. cursorBlinker.Show(cursor);
  2989. IF (onCursorChanged # NIL) THEN onCursorChanged END
  2990. END CursorChanged;
  2991. PROCEDURE CursorUp*(select : BOOLEAN);
  2992. VAR
  2993. pos, cPos, cl, lineStart : LONGINT;
  2994. BEGIN
  2995. Acquire;
  2996. text.AcquireRead;
  2997. pos := GetInternalPos(cursor.GetPosition());
  2998. IF select THEN
  2999. KeyStartSelection(pos)
  3000. ELSE
  3001. selection.SetFromTo(pos, pos);
  3002. cursor.SetVisible(TRUE);
  3003. Texts.ClearLastSelection
  3004. END;
  3005. cl := layout.FindLineNrByPos(pos);
  3006. IF cl > 0 THEN
  3007. DEC(cl);
  3008. lineStart := layout.GetLineStartPos(cl);
  3009. cPos := lineStart + Strings.Min(layout.GetLineLength(cl) - 1, lineEnter);
  3010. cursor.SetPosition(cPos);
  3011. IF cl < firstLineI THEN firstLine.Set(cl) END
  3012. END;
  3013. IF select THEN
  3014. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()));
  3015. END;
  3016. text.ReleaseRead;
  3017. Release;
  3018. CursorChanged
  3019. END CursorUp;
  3020. PROCEDURE CursorDown*(select : BOOLEAN);
  3021. VAR pos, cPos, cl, lineStart : LONGINT;
  3022. BEGIN
  3023. Acquire;
  3024. text.AcquireRead;
  3025. pos := GetInternalPos(cursor.GetPosition());
  3026. IF select THEN
  3027. KeyStartSelection(pos)
  3028. ELSE
  3029. selection.SetFromTo(pos, pos);
  3030. cursor.SetVisible(TRUE);
  3031. Texts.ClearLastSelection
  3032. END;
  3033. cl := layout.FindLineNrByPos(pos);
  3034. IF cl < layout.GetNofLines() - 1 THEN
  3035. INC(cl);
  3036. lineStart := layout.GetLineStartPos(cl);
  3037. cPos := lineStart + Strings.Min(layout.GetLineLength(cl) - 1, lineEnter);
  3038. cursor.SetPosition(cPos);
  3039. IF cl > FindLineByY(firstLineI, bounds.GetHeight() - bordersI.b) THEN firstLine.Set(firstLineI + 1 ) END
  3040. END;
  3041. IF select THEN
  3042. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3043. END;
  3044. text.ReleaseRead;
  3045. Release;
  3046. CursorChanged
  3047. END CursorDown;
  3048. (* Move the cursor one character/word to the left *)
  3049. PROCEDURE CursorLeft*(word, select : BOOLEAN);
  3050. VAR
  3051. pos, cPos, wPos : LONGINT;
  3052. BEGIN
  3053. Acquire;
  3054. text.AcquireRead;
  3055. PositionDebugging.SetPos(GetInternalPos(cursor.GetPosition()),cursor.GetPosition());
  3056. pos := GetInternalPos(cursor.GetPosition());
  3057. IF select THEN
  3058. KeyStartSelection(pos)
  3059. ELSE
  3060. selection.SetFromTo(pos, pos);
  3061. cursor.SetVisible(TRUE);
  3062. Texts.ClearLastSelection
  3063. END;
  3064. cPos := GetInternalPos(cursor.GetPosition()) - 1;
  3065. IF ~word THEN
  3066. cursor.SetPosition(GetDisplayPos(cPos));
  3067. ELSE
  3068. wPos := TextUtilities.FindPosWordLeft(utilreader, cPos);
  3069. cursor.SetPosition(GetDisplayPos(wPos));
  3070. END;
  3071. IF select THEN
  3072. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3073. END;
  3074. StoreLineEnter;
  3075. text.ReleaseRead;
  3076. Release;
  3077. CursorChanged
  3078. END CursorLeft;
  3079. (* Move the cursor one character/word to the right *)
  3080. PROCEDURE CursorRight*(word, select : BOOLEAN);
  3081. VAR
  3082. pos, cPos, wPos : LONGINT;
  3083. BEGIN
  3084. Acquire;
  3085. text.AcquireRead;
  3086. PositionDebugging.SetPos(GetInternalPos(cursor.GetPosition()),cursor.GetPosition());
  3087. pos := GetInternalPos(cursor.GetPosition());
  3088. IF select THEN
  3089. KeyStartSelection(pos)
  3090. ELSE
  3091. selection.SetFromTo(pos, pos);
  3092. cursor.SetVisible(TRUE);
  3093. Texts.ClearLastSelection
  3094. END;
  3095. cPos := GetInternalPos(cursor.GetPosition()) + 1;
  3096. IF ~word THEN
  3097. cursor.SetPosition(GetDisplayPos(cPos));
  3098. ELSE
  3099. wPos := TextUtilities.FindPosWordRight(utilreader, cPos);
  3100. cursor.SetPosition(GetDisplayPos(wPos));
  3101. END;
  3102. IF select THEN
  3103. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3104. END;
  3105. StoreLineEnter;
  3106. text.ReleaseRead;
  3107. Release;
  3108. CursorChanged
  3109. END CursorRight;
  3110. PROCEDURE PageDown*(select : BOOLEAN);
  3111. VAR dy : LONGINT; i, pos, iPos : LONGINT;
  3112. cx, cy : LONGINT;
  3113. BEGIN
  3114. Acquire;
  3115. text.AcquireRead;
  3116. iPos := GetInternalPos(cursor.GetPosition());
  3117. IF select THEN
  3118. KeyStartSelection(iPos)
  3119. ELSE
  3120. selection.SetFromTo(iPos, iPos);
  3121. cursor.SetVisible(TRUE);
  3122. Texts.ClearLastSelection
  3123. END;
  3124. IF firstLineI = layout.GetNofLines() - 1 THEN
  3125. cursor.SetPosition(text.GetLength());
  3126. ELSE
  3127. (* save cursor screen pos for repositioning *)
  3128. IF ~FindScreenPos(cursor.GetPosition(), cx, cy) THEN cx := 0; cy := 0 END;
  3129. i := firstLineI; dy := 0;
  3130. WHILE (i < layout.GetNofLines() - 1) & (dy < bounds.GetHeight() - bordersI.t - bordersI.b) DO
  3131. INC(i); dy := dy + (layout.lines[i].height)
  3132. END;
  3133. firstLine.Set(i);
  3134. (* set cursor to nearest pos on new page *)
  3135. ViewToTextPos(cx, cy, pos);
  3136. IF pos >= 0 THEN
  3137. cursor.SetPosition(pos);
  3138. END;
  3139. END;
  3140. IF select THEN
  3141. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3142. END;
  3143. text.ReleaseRead;
  3144. Release;
  3145. CursorChanged
  3146. END PageDown;
  3147. PROCEDURE PageUp*(select : BOOLEAN);
  3148. VAR dy : LONGINT; i, pos, iPos : LONGINT;
  3149. cx, cy : LONGINT;
  3150. BEGIN
  3151. Acquire;
  3152. text.AcquireRead;
  3153. iPos := GetInternalPos(cursor.GetPosition());
  3154. IF select THEN
  3155. KeyStartSelection(iPos)
  3156. ELSE
  3157. selection.SetFromTo(iPos, iPos);
  3158. cursor.SetVisible(TRUE);
  3159. Texts.ClearLastSelection
  3160. END;
  3161. IF firstLineI = 0 THEN
  3162. cursor.SetPosition(0);
  3163. ELSE
  3164. (* save cursor screen pos for repositioning *)
  3165. IF ~FindScreenPos(cursor.GetPosition(), cx, cy) THEN cx := 0; cy := 0 END;
  3166. (* go up one page but at least one page *)
  3167. i := firstLineI; dy := 0;
  3168. WHILE (i > 0) & (dy < bounds.GetHeight() - bordersI.t - bordersI.b) DO
  3169. DEC(i); dy := dy + (layout.lines[i].height)
  3170. END;
  3171. IF (i > 0) & (i = firstLineI) THEN DEC(i) END;
  3172. firstLine.Set(i);
  3173. (* set cursor to nearest pos on new page *)
  3174. ViewToTextPos(cx, cy, pos);
  3175. IF pos >= 0 THEN
  3176. cursor.SetPosition(pos);
  3177. END
  3178. END;
  3179. IF select THEN
  3180. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3181. END;
  3182. text.ReleaseRead;
  3183. Release;
  3184. CursorChanged
  3185. END PageUp;
  3186. PROCEDURE Home*(ctrl, select : BOOLEAN);
  3187. VAR
  3188. lineStart, cl, pos : LONGINT;
  3189. BEGIN
  3190. Acquire;
  3191. text.AcquireRead;
  3192. pos := GetInternalPos(cursor.GetPosition());
  3193. IF select THEN
  3194. KeyStartSelection(pos)
  3195. ELSE
  3196. selection.SetFromTo(pos, pos);
  3197. cursor.SetVisible(TRUE);
  3198. Texts.ClearLastSelection
  3199. END;
  3200. IF ctrl THEN
  3201. cursor.SetPosition(GetDisplayPos(0));
  3202. firstLine.Set(0)
  3203. ELSE
  3204. cl := layout.FindLineNrByPos(cursor.GetPosition());
  3205. lineStart := layout.GetLineStartPos(cl);
  3206. cursor.SetPosition(GetDisplayPos(lineStart));
  3207. END;
  3208. StoreLineEnter;
  3209. IF select THEN
  3210. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3211. END;
  3212. text.ReleaseRead;
  3213. Release;
  3214. CursorChanged
  3215. END Home;
  3216. PROCEDURE End*(ctrl, select : BOOLEAN);
  3217. VAR lineEnd, textLength, cl, pos, dispPos: LONGINT;
  3218. BEGIN
  3219. Acquire;
  3220. text.AcquireRead;
  3221. pos := GetInternalPos(cursor.GetPosition());
  3222. IF select THEN
  3223. KeyStartSelection(pos)
  3224. ELSE
  3225. selection.SetFromTo(pos, pos);
  3226. cursor.SetVisible(TRUE);
  3227. Texts.ClearLastSelection
  3228. END;
  3229. IF ctrl THEN
  3230. textLength := text.GetLength();
  3231. cursor.SetPosition(GetDisplayPos(textLength));
  3232. firstLine.Set(layout.FindLineNrByPos(text.GetLength()))
  3233. ELSE
  3234. cl := layout.FindLineNrByPos(cursor.GetPosition());
  3235. lineEnd := layout.GetLineStartPos(cl) + layout.GetLineLength(cl) - 1;
  3236. dispPos := GetDisplayPos(lineEnd);
  3237. cursor.SetPosition(dispPos);
  3238. END;
  3239. StoreLineEnter;
  3240. IF select THEN
  3241. KeyUpdateSelection(GetInternalPos(cursor.GetPosition()))
  3242. END;
  3243. text.ReleaseRead;
  3244. Release;
  3245. CursorChanged
  3246. END End;
  3247. PROCEDURE KeyEvent*(ucs :LONGINT; flags : SET; VAR keysym : LONGINT);
  3248. BEGIN
  3249. modifierFlags := flags;
  3250. IF Inputs.Release IN flags THEN RETURN END;
  3251. dragCopy := modifierFlags * Inputs.Ctrl # {};
  3252. IF keysym = 01H THEN (* Ctrl-A *)
  3253. SelectAll
  3254. ELSIF keysym = 03H THEN (* Ctrl-C *)
  3255. CopySelection
  3256. ELSIF (keysym = 0FF63H) & (flags * Inputs.Ctrl # {}) THEN (*Ctrl Insert *)
  3257. CopySelection
  3258. ELSIF keysym = 12H THEN (* Ctrl-R *)
  3259. layout.FullLayout(TRUE); Invalidate;CheckNumberOfLines;
  3260. KernelLog.String("Refreshed"); KernelLog.Ln;
  3261. ELSIF keysym = 0FF51H THEN (* Cursor Left *)
  3262. CursorLeft(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3263. ELSIF keysym = 0FF53H THEN (* Cursor Right *)
  3264. CursorRight(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3265. ELSIF keysym = 0FF54H THEN (* Cursor Down *)
  3266. CursorDown(flags * Inputs.Shift # {})
  3267. ELSIF keysym = 0FF52H THEN (* Cursor Up *)
  3268. CursorUp(flags * Inputs.Shift # {})
  3269. ELSIF keysym = 0FF56H THEN (* Page Down *)
  3270. PageDown(flags * Inputs.Shift # {})
  3271. ELSIF keysym = 0FF55H THEN (* Page Up *)
  3272. PageUp(flags * Inputs.Shift # {})
  3273. ELSIF keysym = 0FF50H THEN (* Cursor Home *)
  3274. Home(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3275. ELSIF keysym = 0FF57H THEN (* Cursor End *)
  3276. End(flags * Inputs.Ctrl # {}, flags * Inputs.Shift # {})
  3277. END
  3278. END KeyEvent;
  3279. (* called by users that override the KeyEvents to allow copy drag drop *)
  3280. PROCEDURE SetFlags*(flags : SET);
  3281. BEGIN
  3282. modifierFlags := flags;
  3283. dragCopy := modifierFlags * Inputs.Ctrl # {};
  3284. END SetFlags;
  3285. PROCEDURE FindCommandRange*(pos: LONGINT; VAR start, end, nofLastSelections : LONGINT);
  3286. VAR ch : LONGINT; string : ARRAY 23 OF CHAR; i : LONGINT; sDoCommands, lastWasTilde : BOOLEAN;
  3287. escapeString: ARRAY 32 OF LONGINT; escapePos: LONGINT; escape: BOOLEAN;
  3288. (* note: this simple algorithm can be emplyed if the substring to be implicitly searched for does not contain its first character *)
  3289. PROCEDURE String(escape: BOOLEAN; CONST escapeString: ARRAY OF LONGINT);
  3290. VAR done: BOOLEAN; escapePos: LONGINT;
  3291. BEGIN
  3292. done := FALSE; escapePos := -1;
  3293. REPEAT
  3294. utilreader.ReadCh(ch);
  3295. IF ch = ORD('"') THEN
  3296. IF escape THEN
  3297. escapePos := 0;
  3298. ELSE
  3299. done := TRUE
  3300. END;
  3301. ELSIF escapePos >= 0 THEN
  3302. IF escapeString[escapePos] = 0 THEN
  3303. IF ch =ORD("\") THEN done := TRUE
  3304. ELSE escapePos := -1
  3305. END;
  3306. ELSIF escapeString[escapePos] # ch THEN
  3307. escapePos := -1;
  3308. ELSE
  3309. INC(escapePos);
  3310. END;
  3311. END;
  3312. UNTIL done OR utilreader.eot;
  3313. END String;
  3314. BEGIN
  3315. nofLastSelections := 0;
  3316. text.AcquireRead;
  3317. utilreader.SetDirection(-1); utilreader.SetPosition(pos);
  3318. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3319. start := utilreader.GetPosition() + 2;
  3320. IF utilreader.eot THEN DEC(start, 2) END;
  3321. (* search ~ *)
  3322. i := 0; sDoCommands := FALSE; lastWasTilde := FALSE;
  3323. utilreader.SetDirection(1); utilreader.SetPosition(start);
  3324. REPEAT
  3325. utilreader.ReadCh(ch);
  3326. IF ch = ORD('"') THEN
  3327. escapeString[escapePos] := 0;
  3328. String(escape, escapeString);
  3329. ELSIF ch =ORD("\") THEN
  3330. escape := TRUE;
  3331. escapePos := 0;
  3332. ELSIF escape THEN
  3333. IF TextUtilities.IsWhiteSpace(ch,text.isUTF) THEN escape := FALSE
  3334. ELSE escapeString[escapePos] := ch; INC(escapePos);
  3335. END;
  3336. END;
  3337. (* check whether the command is SystemTools.DoCommands *)
  3338. IF (i < 22) THEN
  3339. string[i] := CHR(ch);
  3340. INC(i);
  3341. IF (i = 22) THEN
  3342. string[22] := 0X;
  3343. IF (string = "SystemTools.DoCommands") OR Strings.StartsWith2("PreliminaryCommands",string) THEN
  3344. sDoCommands := TRUE;
  3345. END;
  3346. END;
  3347. END;
  3348. IF (CHR(ch) = "^") THEN
  3349. INC(nofLastSelections);
  3350. END;
  3351. (* We do a special treatment of the command SystemTools.DoCommands since we don't want a single
  3352. tilde character to delimit the parameter string for the particular command - but two tilde characters *)
  3353. IF sDoCommands THEN
  3354. IF (ch = ORD("~")) THEN
  3355. IF ~lastWasTilde THEN
  3356. lastWasTilde := TRUE;
  3357. utilreader.ReadCh(ch);
  3358. ELSE
  3359. (* Two tilde characters only separated with whitespace means this is the
  3360. end of the SystemTools.DoCommands parameter string *)
  3361. END;
  3362. ELSIF lastWasTilde & ~TextUtilities.IsWhiteSpace(ch,text.isUTF) THEN
  3363. lastWasTilde := FALSE;
  3364. END;
  3365. END;
  3366. UNTIL (ch = ORD("~")) OR (utilreader.eot);
  3367. end := utilreader.GetPosition() - 1;
  3368. IF utilreader.eot THEN INC(end) END;
  3369. text.ReleaseRead
  3370. END FindCommandRange;
  3371. PROCEDURE FindCommand*(pos: LONGINT; VAR start, end : LONGINT);
  3372. VAR ch : LONGINT;
  3373. BEGIN
  3374. text.AcquireRead;
  3375. utilreader.SetDirection(-1); utilreader.SetPosition(pos);
  3376. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3377. start := utilreader.GetPosition() + 2;
  3378. IF utilreader.eot THEN DEC(start, 2) END;
  3379. utilreader.SetDirection(1); utilreader.SetPosition(pos);
  3380. REPEAT utilreader.ReadCh(ch) UNTIL TextUtilities.IsWhiteSpace(ch,text.isUTF) OR utilreader.eot;
  3381. end := utilreader.GetPosition() - 1;
  3382. IF utilreader.eot THEN INC(end) END;
  3383. text.ReleaseRead;
  3384. END FindCommand;
  3385. (** Start the command in the text, starting on pos (or wordboundary before),
  3386. caller should hold lock on text to make the pos stable *)
  3387. PROCEDURE StartCommand*(pos : LONGINT; openFile : BOOLEAN);
  3388. VAR
  3389. start, end, bufSize : LONGINT;
  3390. context : Commands.Context;
  3391. arg : Streams.StringReader;
  3392. command : ARRAY MaxCommandLength OF CHAR;
  3393. parameters : POINTER TO ARRAY OF CHAR;
  3394. s : Strings.String;
  3395. msg : ARRAY 128 OF CHAR;
  3396. ignore : Modules.Name;
  3397. paramSize, nofLastSelections, i, j, a, b, res : LONGINT;
  3398. selectionText : Texts.Text;
  3399. selectionOk : BOOLEAN;
  3400. from, to: Texts.TextPosition;
  3401. commandCaller:OBJECT;
  3402. commandWriter, errorWriter: Streams.Writer;
  3403. BEGIN
  3404. Acquire;
  3405. text.AcquireRead;
  3406. IF openFile THEN FindCommand(pos, start, end)
  3407. ELSE FindCommandRange(pos, start, end, nofLastSelections)
  3408. END;
  3409. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), MaxCallParameterBuf), 1);
  3410. NEW(s, bufSize);
  3411. paramSize := 0;
  3412. TextUtilities.SubTextToStrAt(text, start, end - start, paramSize, s^);
  3413. INC(paramSize);
  3414. text.ReleaseRead;
  3415. Release;
  3416. IF Inputs.Shift * modifierFlags # {} THEN
  3417. (*
  3418. Command / open will not see the caller => called as if no calling context was specified.
  3419. => Opening a text while holding a shift key down will usually result in a new viewer being opened.
  3420. *)
  3421. commandCaller := NIL
  3422. ELSE
  3423. commandCaller := SELF.commandCaller;
  3424. END;
  3425. IF openFile THEN
  3426. FileHandlers.OpenFile(s^, NIL, commandCaller)
  3427. ELSE
  3428. command := "";
  3429. i := 0;
  3430. WHILE (i < MaxCommandLength) & (s[i] # 0X) & (s[i] # ";") & (s[i] # " ") & (s[i] # 09X) & (s[i] # 0DX) & (s[i] # 0AX) DO
  3431. command[i] := s[i]; INC(i);
  3432. END;
  3433. IF i < MaxCommandLength THEN
  3434. command[i] := 0X;
  3435. INC(i);
  3436. Commands.Split(command, ignore, ignore, res, msg);
  3437. IF res # Commands.Ok THEN
  3438. KernelLog.String("WMTextView: Command parsing error, res: "); KernelLog.Int(res, 0);
  3439. KernelLog.String(" ("); KernelLog.String(msg); KernelLog.String(")"); KernelLog.Ln;
  3440. RETURN;
  3441. END;
  3442. ELSE
  3443. KernelLog.String("WMTextView: Command execution error: Command too long"); KernelLog.Ln;
  3444. RETURN;
  3445. END;
  3446. IF (Inputs.Alt * modifierFlags # {}) THEN
  3447. (* execute AltMMCommand with actual command and its parameters as parameter *)
  3448. COPY(AltMMCommand, command);
  3449. commandWriter := NIL; errorWriter := NIL;
  3450. i := 0;
  3451. ELSE
  3452. commandWriter := SELF.commandWriter;
  3453. errorWriter := SELF.errorWriter;
  3454. END;
  3455. IF (i < LEN(s)) THEN (* copy parameter string *)
  3456. selectionOk := FALSE;
  3457. IF (nofLastSelections > 0) THEN
  3458. IF Texts.GetLastSelection(selectionText, from, to) THEN
  3459. selectionOk := TRUE;
  3460. selectionText.AcquireRead;
  3461. a := Strings.Min(from.GetPosition(), to.GetPosition());
  3462. b := Strings.Max(from.GetPosition(), to.GetPosition());
  3463. INC(paramSize, b - a + 1);
  3464. END;
  3465. END;
  3466. NEW(parameters, paramSize);
  3467. j := 0;
  3468. WHILE (i < LEN(s)) & (j < LEN(parameters)-1) DO
  3469. IF (s[i] = "^") & selectionOk THEN
  3470. TextUtilities.SubTextToStrAt(selectionText, a, b - a, j, parameters^);
  3471. ELSE
  3472. parameters[j] := s[i]; INC(j);
  3473. END;
  3474. INC(i);
  3475. END;
  3476. parameters[j] := 0X;
  3477. IF selectionOk THEN
  3478. selectionText.ReleaseRead;
  3479. END;
  3480. ELSE
  3481. NEW(parameters, 1); parameters[0] := 0X;
  3482. END;
  3483. NEW(arg, LEN(parameters)); arg.SetRaw(parameters^, 0, LEN(parameters));
  3484. NEW(context, NIL, arg, commandWriter, errorWriter, commandCaller);
  3485. IF TraceCommands IN Trace THEN
  3486. KernelLog.String("WMTextView: Executing command: '"); KernelLog.String(command); KernelLog.String("'");
  3487. KernelLog.String(", parameters: ");
  3488. IF (parameters[0] = 0X) THEN KernelLog.String("None"); ELSE KernelLog.String("'"); KernelLog.String(parameters^); KernelLog.String("'"); END;
  3489. KernelLog.Ln;
  3490. END;
  3491. Commands.Activate(command, context, {}, res, msg);
  3492. IF (res # Commands.Ok) THEN
  3493. IF commandWriter # NIL THEN
  3494. commandWriter.String("WMTextView: Command execution error, res: "); commandWriter.Int(res, 0);
  3495. commandWriter.String(" ("); commandWriter.String(msg); commandWriter.String(")"); commandWriter.Ln;
  3496. commandWriter.Update;
  3497. ELSE
  3498. KernelLog.String("WMTextView: Command execution error, res: "); KernelLog.Int(res, 0);
  3499. KernelLog.String(" ("); KernelLog.String(msg); KernelLog.String(")"); KernelLog.Ln;
  3500. END;
  3501. END;
  3502. END;
  3503. END StartCommand;
  3504. PROCEDURE Start(sender, data: ANY);
  3505. VAR msg: ARRAY 512 OF CHAR; res: LONGINT;
  3506. BEGIN
  3507. IF (data # NIL) & (data IS ClickInfo) THEN
  3508. IF data(ClickInfo).cmdPar # NIL THEN
  3509. Commands.Call(data(ClickInfo).cmdPar^, {}, res, msg);
  3510. IF res # 0 THEN KernelLog.String("WMTextView: "); KernelLog.String(msg); KernelLog.Ln END;
  3511. END
  3512. END
  3513. END Start;
  3514. PROCEDURE Open(sender, data: ANY);
  3515. BEGIN
  3516. IF (data # NIL) & (data IS ClickInfo) THEN
  3517. IF data(ClickInfo).cmd # NIL THEN
  3518. FileHandlers.OpenFile(data(ClickInfo).cmd^, NIL, commandCaller)
  3519. END
  3520. END
  3521. END Open;
  3522. PROCEDURE PieMenuStart(sender, data: ANY);
  3523. BEGIN
  3524. Start(piemenu, piemenu.userData)
  3525. END PieMenuStart;
  3526. PROCEDURE PieMenuOpen(sender, data: ANY);
  3527. BEGIN
  3528. Open(piemenu, piemenu.userData)
  3529. END PieMenuOpen;
  3530. PROCEDURE PieMenuCopy(sender, data: ANY);
  3531. BEGIN
  3532. CopySelection;
  3533. END PieMenuCopy;
  3534. PROCEDURE PieMenuPaste(sender, data: ANY);
  3535. BEGIN
  3536. Paste;
  3537. END PieMenuPaste;
  3538. PROCEDURE ShowContextMenu(x, y: LONGINT);
  3539. VAR
  3540. popup : WMPopups.Popup;
  3541. start, end, bufSize : LONGINT;
  3542. command, s : Strings.String;
  3543. clickInfo : ClickInfo;
  3544. str : ARRAY 256 OF CHAR;
  3545. window : WMWindowManager.Window;
  3546. nofLastSelections : LONGINT;
  3547. BEGIN
  3548. ASSERT(IsCallFromSequencer());
  3549. text.AcquireRead;
  3550. FindCommand(cursor.GetPosition(), start, end);
  3551. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), 4096), 1);
  3552. NEW(command, bufSize);
  3553. TextUtilities.SubTextToStr(text, start, end - start, command^);
  3554. FindCommandRange(cursor.GetPosition(), start, end, nofLastSelections);
  3555. bufSize := Strings.Max(Strings.Min((end - start) * 5 + 1 (* for UTF *), MaxCallParameterBuf), 1);
  3556. NEW(s, bufSize);
  3557. TextUtilities.SubTextToStr(text, start, end - start, s^);
  3558. text.ReleaseRead;
  3559. NEW(clickInfo);
  3560. clickInfo.cmd := command;
  3561. clickInfo.cmdPar := s;
  3562. IF UsePieMenu THEN
  3563. NEW(piemenu); piemenu.SetEnabled({0, 1, 2, 3});
  3564. piemenu.SetText(1, Strings.NewString("Open"));
  3565. piemenu.SetText(3, Strings.NewString("Start"));
  3566. piemenu.SetText(2, Strings.NewString("Copy"));
  3567. piemenu.SetText(0, Strings.NewString("Paste"));
  3568. piemenu.userData := clickInfo;
  3569. piemenu.on1.Add(PieMenuOpen);
  3570. piemenu.on2.Add(PieMenuCopy);
  3571. piemenu.on3.Add(PieMenuStart);
  3572. piemenu.on0.Add(PieMenuPaste);
  3573. manager := WMWindowManager.GetDefaultManager();
  3574. window := manager.GetPositionOwner(x, y);
  3575. IF window = NIL THEN RETURN END;
  3576. Acquire; ToWMCoordinates(x, y, x, y); Release;
  3577. piemenu.Show(window, x, y, FALSE);
  3578. (* TODO: Can't set := NIL, since its used by the button handlers *)
  3579. ELSE
  3580. NEW(popup);
  3581. str := "Start "; Strings.Append(str, command^); popup.AddParButton(str, Start, clickInfo);
  3582. str := "Open "; Strings.Append(str, command^); popup.AddParButton(str, Open, clickInfo);
  3583. Acquire; ToWMCoordinates(x, y, x, y); Release;
  3584. popup.Popup(x, y);
  3585. END
  3586. END ShowContextMenu;
  3587. PROCEDURE HandleInternal(VAR x: WMMessages.Message);
  3588. VAR pos : LONGINT; obj : ANY; link : Texts.Link;
  3589. BEGIN
  3590. ASSERT(IsCallFromSequencer());
  3591. IF (x.msgType = WMMessages.MsgKey) & objHasFocus THEN (* forward KeyMsg *)
  3592. WITH focusObject : WMComponents.VisualComponent DO
  3593. focusObject.Handle(x);
  3594. InvalidateRange(focusPos, focusPos+1)
  3595. END
  3596. ELSIF (x.msgType # WMMessages.MsgKey) & HitObject(x.x, x.y, pos, obj) THEN (* forward Msg *)
  3597. SetFocus; cursor.SetVisible(FALSE);
  3598. IF obj IS WMComponents.VisualComponent THEN
  3599. WITH obj : WMComponents.VisualComponent DO
  3600. (* remove oldObject first *)
  3601. IF (oldObject # NIL) & (oldObject # obj) THEN
  3602. oldObject(WMComponents.VisualComponent).Handle(x);
  3603. InvalidateRange(oldPos, oldPos+1);
  3604. END;
  3605. TransformCoordinates(x.x, x.y, obj); (* transform to obj coords *)
  3606. obj.Handle(x); (* call obj Handle *)
  3607. ChangePointer(obj.GetPointerInfo()); (* change the pointer Image *)
  3608. InvalidateRange(pos, pos+1); (* redraw obj *)
  3609. oldObject := obj; oldPos := pos; (* store last object *)
  3610. (* transfer focus to Object *)
  3611. IF (x.msgType = WMMessages.MsgPointer) & (x.flags * {0, 1, 2} = {0}) THEN
  3612. (* remove old focus first *)
  3613. IF (focusObject # NIL) & (focusObject # obj) THEN
  3614. focusObject(WMComponents.VisualComponent).FocusLost;
  3615. InvalidateRange(focusPos, focusPos+1)
  3616. END;
  3617. objHasFocus := TRUE;
  3618. focusObject := obj; focusPos := pos;
  3619. (* FocusLost *)
  3620. END
  3621. END
  3622. END
  3623. ELSIF (x.msgType = WMMessages.MsgPointer) & HitLink(x.x, x.y, pos, link) THEN (* Link *)
  3624. ChangePointer(manager.pointerLink);
  3625. IF (x.msgSubType = 2) &(oldFlags / x.flags = {CallURLPointer}) THEN LinkClick(link); END;
  3626. oldFlags := x.flags;
  3627. ELSE
  3628. ChangePointer(manager.pointerText); (* change Pointer back *)
  3629. (* transfer focus back to TextView *)
  3630. IF (focusObject # NIL) & (x.msgType = WMMessages.MsgPointer) & (x.flags * {0, 1, 2} = {0}) THEN
  3631. focusObject(WMComponents.VisualComponent).FocusLost;
  3632. objHasFocus := FALSE;
  3633. InvalidateRange(focusPos, focusPos+1);
  3634. FocusReceived;
  3635. focusObject := NIL
  3636. END;
  3637. (* update last Object *)
  3638. IF (oldObject # NIL) & (x.msgType = WMMessages.MsgPointer) THEN
  3639. oldObject(WMComponents.VisualComponent).Handle(x);
  3640. InvalidateRange(oldPos, oldPos+1);
  3641. oldObject := NIL
  3642. END;
  3643. IF (x.msgType = WMMessages.MsgExt) & (x.ext # NIL) & (x.ext IS Texts.StyleChangedMsg) THEN
  3644. layout.FullLayout(TRUE); Invalidate; CheckNumberOfLines;
  3645. ELSE
  3646. HandleInternal^(x);
  3647. END;
  3648. END
  3649. END HandleInternal;
  3650. END TextView;
  3651. TYPE
  3652. FontEntry = OBJECT
  3653. VAR
  3654. name : ARRAY 256 OF CHAR;
  3655. attributes : FontAttributes;
  3656. next : FontEntry;
  3657. PROCEDURE &Init(CONST name : ARRAY OF CHAR);
  3658. BEGIN
  3659. COPY(name, SELF.name);
  3660. attributes := NIL;
  3661. next := NIL;
  3662. END Init;
  3663. END FontEntry;
  3664. FontAttributes = OBJECT
  3665. VAR
  3666. font : WMGraphics.Font; (* { font # {} *)
  3667. size : LONGINT;
  3668. style : SET;
  3669. next : FontAttributes;
  3670. PROCEDURE &Init(size : LONGINT; style : SET);
  3671. BEGIN
  3672. font := NIL;
  3673. SELF.size := size;
  3674. SELF.style := style;
  3675. next := NIL;
  3676. END Init;
  3677. END FontAttributes;
  3678. (* not thread-safe! not global to avoid locking and keep size smaller *)
  3679. FontCache = OBJECT
  3680. VAR
  3681. entries : FontEntry;
  3682. defaultFont : WMGraphics.Font;
  3683. PROCEDURE &Init;
  3684. BEGIN
  3685. NEW(entries, "head"); (* head of list *)
  3686. defaultFont := WMGraphics.GetDefaultFont();
  3687. END Init;
  3688. PROCEDURE Find(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3689. VAR font : WMGraphics.Font; e : FontEntry; a : FontAttributes;
  3690. BEGIN
  3691. font := NIL;
  3692. e := entries.next;
  3693. WHILE (e # NIL ) & (e.name < name) DO e := e.next; END;
  3694. IF (e # NIL) & (e.name = name) THEN
  3695. a := e.attributes;
  3696. WHILE (a # NIL) & (a.size < size) DO a := a.next; END;
  3697. WHILE (a # NIL) & (a.size = size) & (a.style # style) DO a := a.next; END;
  3698. IF (a # NIL) & (a.size = size) THEN
  3699. ASSERT(a.font # NIL);
  3700. font := a.font;
  3701. END;
  3702. END;
  3703. RETURN font;
  3704. END Find;
  3705. PROCEDURE Add(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3706. VAR entry, e : FontEntry; attribute, a : FontAttributes;
  3707. BEGIN
  3708. e := entries;
  3709. WHILE (e.next # NIL) & (e.next.name < name) DO e := e.next; END;
  3710. IF (e.next # NIL) & (e.next.name = name) THEN
  3711. entry := e.next;
  3712. ELSE
  3713. NEW(entry, name);
  3714. entry.next := e.next;
  3715. e.next := entry;
  3716. END;
  3717. ASSERT(entry # NIL);
  3718. NEW(attribute, size, style);
  3719. attribute.font := WMGraphics.GetFont(name, size, style);
  3720. IF (entry.attributes = NIL) THEN
  3721. entry.attributes := attribute;
  3722. ELSIF (entry.attributes.size >= attribute.size) THEN
  3723. attribute.next := entry.attributes;
  3724. entry.attributes := attribute;
  3725. ELSE
  3726. a := entry.attributes;
  3727. WHILE (a.next # NIL) & (a.next.size < attribute.size) DO a := a.next; END;
  3728. attribute.next := a.next;
  3729. a.next := attribute;
  3730. END;
  3731. ASSERT(attribute.font # NIL);
  3732. RETURN attribute.font;
  3733. END Add;
  3734. (* Get specified font. If not available, the system default font is returned *)
  3735. PROCEDURE GetFont(CONST name : ARRAY OF CHAR; size : LONGINT; style : SET) : WMGraphics.Font;
  3736. VAR font : WMGraphics.Font;
  3737. BEGIN
  3738. font := Find(name, size, style);
  3739. IF (font = NIL) THEN
  3740. font := Add(name, size, style);
  3741. END;
  3742. ASSERT(font # NIL);
  3743. RETURN font;
  3744. END GetFont;
  3745. END FontCache;
  3746. VAR
  3747. manager : WMWindowManager.WindowManager;
  3748. cursorBlinker- : CursorBlinker;
  3749. PTVIsMultiLine, PTVIsPassword, PTVShowBorder, PTValwaysShowCursor, PTVShowLabels : WMProperties.BooleanProperty;
  3750. PTVAllowCommandExecution, PTVAllowTextSelection, PTVAllowPiemenu : WMProperties.BooleanProperty;
  3751. PTVWrapMode, PTVMouseWheelScrollSpeed, PVTtextAlignV : WMProperties.Int32Property;
  3752. PTVfirstLine, PTVleftShift, PTVPasswordChar : WMProperties.Int32Property;
  3753. PTVdefaultTextColor, PTVdefaultTextBgColor : WMProperties.ColorProperty;
  3754. PTVborders : WMProperties.RectangleProperty;
  3755. PTVonLinkClick, PTVonLinkClickInfo : Strings.String;
  3756. PTVonCtrlLinkClick, PTVonCtrlLinkClickInfo : Strings.String;
  3757. PTVShowLineNumbers, PTVIndicateTabs : WMProperties.BooleanProperty;
  3758. PTVHighlighting : WMProperties.StringProperty;
  3759. PTVLineNumberColor, PTVLineNumberBgColor, PTVclBgCurrentLine : WMProperties.ColorProperty;
  3760. currentTextView : TextView;
  3761. StrTextView : Strings.String;
  3762. DefaultStyle : POINTER TO RECORD END;
  3763. PROCEDURE Limit(x, min, max : LONGINT) : LONGINT;
  3764. BEGIN
  3765. IF x < min THEN x := min END;
  3766. IF x > max THEN x := max END;
  3767. RETURN x
  3768. END Limit;
  3769. (* Actually, this is a hack... but for now, do it. *)
  3770. PROCEDURE GetNewSize(CONST fontname : ARRAY OF CHAR; value, currentSize : LONGINT; VAR newSize : LONGINT);
  3771. BEGIN
  3772. IF (fontname = "Oberon") THEN
  3773. IF (value >0) THEN
  3774. IF (currentSize <= 8) THEN newSize := 10;
  3775. ELSIF (currentSize <= 10) THEN newSize := 12;
  3776. ELSIF (currentSize <= 12) THEN newSize := 14;
  3777. ELSIF (currentSize <= 14) THEN newSize := 16;
  3778. ELSIF (currentSize <= 16) THEN newSize := 20;
  3779. ELSIF (currentSize <= 20) THEN newSize := 24;
  3780. ELSE (* go to default *)
  3781. newSize := 24; (* max. size of Oberon font *)
  3782. END;
  3783. ELSE
  3784. IF (currentSize >= 24) THEN newSize := 20;
  3785. ELSIF (currentSize >= 20) THEN newSize := 16;
  3786. ELSIF (currentSize >= 16) THEN newSize := 14;
  3787. ELSIF (currentSize >= 14) THEN newSize := 12;
  3788. ELSIF (currentSize >= 12) THEN newSize := 10;
  3789. ELSE
  3790. newSize := 8;
  3791. END;
  3792. END;
  3793. ELSIF (fontname = "Courier") THEN
  3794. IF (value > 0) THEN
  3795. IF (currentSize <= 8) THEN newSize := 10;
  3796. ELSE
  3797. newSize := 12;
  3798. END;
  3799. ELSE
  3800. IF (currentSize >= 12) THEN newSize := 10;
  3801. ELSE
  3802. newSize := 8;
  3803. END;
  3804. END;
  3805. ELSE
  3806. newSize := currentSize + value * currentSize DIV 4;
  3807. END;
  3808. IF (newSize < 8) THEN newSize := 8; END;
  3809. TRACE(currentSize, value, newSize);
  3810. END GetNewSize;
  3811. TYPE
  3812. DZ = OBJECT (Texts.Attributes);
  3813. VAR value: LONGINT;
  3814. PROCEDURE &Init(v: LONGINT);
  3815. BEGIN
  3816. value := v;
  3817. END Init;
  3818. END DZ;
  3819. PROCEDURE EnsureAttribute(VAR attr : Texts.Attributes);
  3820. BEGIN
  3821. IF (attr = NIL) THEN
  3822. NEW(attr); NEW(attr.fontInfo);
  3823. attr.fontInfo.name := "Vera";
  3824. attr.fontInfo.size := 16;
  3825. attr.fontInfo.style := {};
  3826. attr.color := 0000000FFH;
  3827. attr.bgcolor := 000000000H;
  3828. END
  3829. END EnsureAttribute;
  3830. PROCEDURE ChangeAttribute(VAR attr : Texts.Attributes; userData : ANY);
  3831. VAR dz: DZ;
  3832. BEGIN
  3833. IF (userData # NIL) & (userData IS DZ) THEN
  3834. EnsureAttribute(attr);
  3835. dz := userData(DZ);
  3836. GetNewSize(attr.fontInfo.name,-dz.value, attr.fontInfo.size, attr.fontInfo.size);
  3837. attr.fontInfo.fontcache := NIL;
  3838. END;
  3839. END ChangeAttribute;
  3840. PROCEDURE GetFontFromAttr(info : Texts.FontInfo) : WMGraphics.Font;
  3841. BEGIN
  3842. RETURN WMGraphics.GetFont(info.name, info.size, info.style);
  3843. END GetFontFromAttr;
  3844. PROCEDURE IsSameFont(f1, f2 : WMGraphics.Font) : BOOLEAN;
  3845. BEGIN
  3846. RETURN (f1 = f2) OR ((f1 # NIL) & (f2 # NIL) & (f1.size = f2.size) & (f1.style = f2.style) & (f1.name = f2.name));
  3847. END IsSameFont;
  3848. PROCEDURE CheckFont(style : SyntaxHighlighter.Style; font : WMGraphics.Font; VAR fontCache : FontCache);
  3849. VAR fontname : ARRAY 256 OF CHAR; fontsize : LONGINT; fontstyle : SET;
  3850. BEGIN
  3851. ASSERT(style # NIL);
  3852. IF (fontCache = NIL) THEN NEW(fontCache); END;
  3853. IF (style.defined * SyntaxHighlighter.FontMask = SyntaxHighlighter.FontMask) OR (font = NIL) THEN
  3854. COPY(style.attributes.fontInfo.name, fontname);
  3855. fontsize := style.attributes.fontInfo.size;
  3856. fontstyle := style.attributes.fontInfo.style;
  3857. ELSIF (font # NIL) THEN
  3858. IF (SyntaxHighlighter.FontName IN style.defined) THEN COPY(style.attributes.fontInfo.name, fontname); ELSE COPY(font.name, fontname); END;
  3859. IF (SyntaxHighlighter.FontSize IN style.defined) THEN fontsize := style.attributes.fontInfo.size; ELSE fontsize := font.size; END;
  3860. IF (SyntaxHighlighter.FontStyle IN style.defined) THEN fontstyle := style.attributes.fontInfo.style; ELSE fontstyle := font.style; END;
  3861. END;
  3862. IF (style.attributes.fontInfo.fontcache = NIL) OR ~IsSameFont(style.attributes.fontInfo.fontcache (WMGraphics.Font), font) THEN
  3863. style.attributes.fontInfo.fontcache := fontCache.GetFont(fontname, fontsize, fontstyle);
  3864. END;
  3865. ASSERT(style.attributes.fontInfo.fontcache # NIL);
  3866. END CheckFont;
  3867. PROCEDURE InitStrings;
  3868. BEGIN
  3869. StrTextView := Strings.NewString("TextView");
  3870. PTVonLinkClick := Strings.NewString("Link Click Event");
  3871. PTVonLinkClickInfo := Strings.NewString("fired when a link is pressed");
  3872. PTVonCtrlLinkClick := Strings.NewString("Ctrl Click Event");
  3873. PTVonCtrlLinkClickInfo := Strings.NewString("fired when Ctrl pressend and clicked");
  3874. END InitStrings;
  3875. PROCEDURE InitPrototypes;
  3876. BEGIN
  3877. NEW(PTVIsMultiLine, NIL, Strings.NewString("multiLine"), Strings.NewString("defines if more than one line is visible"));
  3878. PTVIsMultiLine.Set(TRUE);
  3879. NEW(PTVShowBorder, NIL, Strings.NewString("ShowBorder"), Strings.NewString("show border"));
  3880. PTVShowBorder.Set(FALSE);
  3881. NEW(PTVIsPassword, NIL, Strings.NewString("password"),
  3882. Strings.NewString("defines if the view is a password text. Characters are replaced by passwordChar"));
  3883. NEW(PTVPasswordChar, NIL, Strings.NewString("passwordChar"),
  3884. Strings.NewString("character that is the placeholder for a character in a password"));
  3885. PTVPasswordChar.Set(43);
  3886. NEW(PTValwaysShowCursor, NIL, Strings.NewString("alwaysShowCursor"),
  3887. Strings.NewString("set to true, if the cursor should not be hidden when focus is lost"));
  3888. PTValwaysShowCursor.Set(FALSE);
  3889. NEW(PTVShowLabels, NIL, Strings.NewString("ShowLabels"),
  3890. Strings.NewString("set to true, if the labels should be shown in the text"));
  3891. PTVShowLabels.Set(FALSE);
  3892. NEW(PTVMouseWheelScrollSpeed, NIL, Strings.NewString("MouseWheelScrollSpeed"),
  3893. Strings.NewString("Multiplier for mouse wheel, 0 to disable mouse wheel scrolling"));
  3894. PTVMouseWheelScrollSpeed.Set(3);
  3895. NEW(PTVAllowCommandExecution, NIL, Strings.NewString("allowCommandExecution"),
  3896. Strings.NewString("if set to true, middle-clicked words are executed as command"));
  3897. PTVAllowCommandExecution.Set(TRUE);
  3898. NEW(PTVAllowTextSelection, NIL, Strings.NewString("allowTextSelection"),
  3899. Strings.NewString("is the user allowed to select text using the mouse?"));
  3900. PTVAllowTextSelection.Set(TRUE);
  3901. NEW(PTVAllowPiemenu, NIL, Strings.NewString("allowPiemenu"),
  3902. Strings.NewString("if set to true, a mouse right-click opens the pie menu"));
  3903. PTVAllowPiemenu.Set(TRUE);
  3904. NEW(PTVWrapMode, NIL, Strings.NewString("wrapMode"), Strings.NewString("Set text wrapping mode"));
  3905. PTVWrapMode.Set(WrapWord);
  3906. NEW(PTVfirstLine, NIL, Strings.NewString("firstLine"),
  3907. Strings.NewString("the first visible line of text in the view"));
  3908. PTVfirstLine.Set(0);
  3909. NEW(PTVleftShift, NIL, Strings.NewString("leftShift"),
  3910. Strings.NewString("how many pixels the text in the view is shifted to the left"));
  3911. PTVleftShift.Set(0);
  3912. NEW(PTVdefaultTextColor, NIL, Strings.NewString("defaultTextColor"),
  3913. Strings.NewString("the color of a text that does not explicitly specify a color"));
  3914. PTVdefaultTextColor.Set(0FFH);
  3915. NEW(PTVdefaultTextBgColor, NIL, Strings.NewString("defaultTextBgColor"),
  3916. Strings.NewString("The color of a text background if not specified otherwise in the text"));
  3917. PTVdefaultTextBgColor.Set(0);
  3918. NEW(PTVborders, NIL, Strings.NewString("borders"),
  3919. Strings.NewString("spaces from bounds of the component to the text"));
  3920. PTVborders.Set(WMRectangles.MakeRect(5, 5, 5, 5));
  3921. NEW(PTVIndicateTabs, NIL, Strings.NewString("IndicateTabs"), Strings.NewString("Indicate tabs?"));
  3922. PTVIndicateTabs.Set(FALSE);
  3923. NEW(PTVShowLineNumbers, NIL, Strings.NewString("ShowLineNumbers"), Strings.NewString("Show line numbers?"));
  3924. PTVShowLineNumbers.Set(FALSE);
  3925. NEW(PTVLineNumberColor, NIL, Strings.NewString("LineNumberColor"), Strings.NewString("Color of line numbers"));
  3926. PTVLineNumberColor.Set(WMGraphics.Black);
  3927. NEW(PTVLineNumberBgColor, NIL, Strings.NewString("LineNumberBgColor"), Strings.NewString("Background color of line numbers"));
  3928. PTVLineNumberBgColor.Set(0CCCCCCFFH);
  3929. NEW(PTVHighlighting, NIL, Strings.NewString("Highlighting"), Strings.NewString("Name of highlighting to be applied"));
  3930. PTVHighlighting.Set(NIL);
  3931. NEW(PTVclBgCurrentLine, NIL, Strings.NewString("ClBgCurrentLine"), Strings.NewString("Background color of currently edited line"));
  3932. PTVclBgCurrentLine.Set(0);
  3933. NEW(PVTtextAlignV, NIL, Strings.NewString("TextAlignV"), Strings.NewString("vertical Text Alignment"));
  3934. PVTtextAlignV.Set(WMGraphics.AlignTop);
  3935. END InitPrototypes;
  3936. PROCEDURE EnablePiemenu*;
  3937. BEGIN
  3938. PTVAllowPiemenu.Set( TRUE );
  3939. KernelLog.String( "Piemenu enabled" ); KernelLog.Ln
  3940. END EnablePiemenu;
  3941. PROCEDURE DisablePiemenu*;
  3942. BEGIN
  3943. PTVAllowPiemenu.Set( FALSE );
  3944. KernelLog.String( "Piemenu disabled" ); KernelLog.Ln
  3945. END DisablePiemenu;
  3946. PROCEDURE TextViewFactory*() : XML.Element;
  3947. VAR e : TextView;
  3948. BEGIN
  3949. NEW(e); RETURN e
  3950. END TextViewFactory;
  3951. (* Inserts a ocharacter from the outside into the current textView's text at its current position *)
  3952. PROCEDURE InsertChar*(newChar : Char32) : INTEGER;
  3953. BEGIN
  3954. IF currentTextView # NIL THEN
  3955. RETURN currentTextView.InsertChar(newChar);
  3956. ELSE
  3957. RETURN -3;
  3958. END;
  3959. END InsertChar;
  3960. PROCEDURE Refresh*;
  3961. BEGIN
  3962. IF currentTextView # NIL THEN
  3963. currentTextView.layout.FullLayout(TRUE);
  3964. currentTextView.Invalidate;
  3965. currentTextView.CheckNumberOfLines;
  3966. END;
  3967. END Refresh;
  3968. PROCEDURE Cleanup;
  3969. BEGIN
  3970. cursorBlinker.Finalize;
  3971. END Cleanup;
  3972. PROCEDURE GenTextView*(): XML.Element;
  3973. VAR e : TextView;
  3974. BEGIN
  3975. NEW(e); RETURN e
  3976. END GenTextView;
  3977. BEGIN
  3978. NEW(cursorBlinker);
  3979. NEW(DefaultStyle);
  3980. Modules.InstallTermHandler(Cleanup);
  3981. InitStrings;
  3982. InitPrototypes;
  3983. manager := WMWindowManager.GetDefaultManager();
  3984. END WMTextView.