fpviews.pas 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Views and view-related functions for the IDE
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPViews;
  12. {$i globdir.inc}
  13. interface
  14. uses
  15. Dos,Objects,Drivers,
  16. FVConsts,
  17. Views,Menus,Dialogs,StdDlg,App,Gadgets,Tabs,
  18. ASCIITAB,
  19. WEditor,WCEdit,
  20. WUtils,WHelp,WHlpView,WViews,WANSI,
  21. Comphook,
  22. {$ifndef NODEBUG}
  23. { Needed here for CORE_ADDR definition }
  24. {$ifdef GDBMI}
  25. gdbmiint,
  26. {$else GDBMI}
  27. gdbint,
  28. {$endif GDBMI}
  29. {$endif NODEBUG}
  30. FPConst,FPUsrScr;
  31. type
  32. TEditor = TCodeEditor;
  33. PEditor = PCodeEditor;
  34. PStoreCollection = ^TStoreCollection;
  35. TStoreCollection = object(TStringCollection)
  36. function Add(const S: string): PString;
  37. end;
  38. PIntegerLine = ^TIntegerLine;
  39. TIntegerLine = object(TInputLine)
  40. constructor Init(var Bounds: TRect; AMin, AMax: longint);
  41. end;
  42. PFPHeapView = ^TFPHeapView;
  43. TFPHeapView = object(THeapView)
  44. constructor Init(var Bounds: TRect);
  45. constructor InitKb(var Bounds: TRect);
  46. procedure HandleEvent(var Event: TEvent); virtual;
  47. end;
  48. PFPClockView = ^TFPClockView;
  49. TFPClockView = object(TClockView)
  50. constructor Init(var Bounds: TRect);
  51. procedure HandleEvent(var Event: TEvent); virtual;
  52. function GetPalette: PPalette; virtual;
  53. end;
  54. PFPWindow = ^TFPWindow;
  55. TFPWindow = object(TWindow)
  56. AutoNumber: boolean;
  57. procedure HandleEvent(var Event: TEvent); virtual;
  58. procedure SetState(AState: Word; Enable: Boolean); virtual;
  59. procedure UpdateCommands; virtual;
  60. constructor Load(var S: TStream);
  61. procedure Store(var S: TStream);
  62. procedure Update; virtual;
  63. procedure SelectInDebugSession;
  64. end;
  65. PFPHelpViewer = ^TFPHelpViewer;
  66. TFPHelpViewer = object(THelpViewer)
  67. function GetLocalMenu: PMenu; virtual;
  68. function GetCommandTarget: PView; virtual;
  69. end;
  70. PFPHelpWindow = ^TFPHelpWindow;
  71. TFPHelpWindow = object(THelpWindow)
  72. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word; AContext: THelpCtx; ANumber: Integer);
  73. destructor Done;virtual;
  74. procedure InitHelpView; virtual;
  75. procedure Show; {virtual;}
  76. procedure Hide; {virtual;}
  77. procedure HandleEvent(var Event: TEvent); virtual;
  78. function GetPalette: PPalette; virtual;
  79. constructor Load(var S: TStream);
  80. procedure Store(var S: TStream);
  81. end;
  82. PTextScroller = ^TTextScroller;
  83. TTextScroller = object(TStaticText)
  84. TopLine: integer;
  85. Speed : integer;
  86. Lines : PUnsortedStringCollection;
  87. constructor Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  88. function GetLineCount: integer; virtual;
  89. function GetLine(I: integer): string; virtual;
  90. procedure HandleEvent(var Event: TEvent); virtual;
  91. procedure Update; virtual;
  92. procedure Reset; virtual;
  93. procedure Scroll; virtual;
  94. procedure Draw; virtual;
  95. destructor Done; virtual;
  96. private
  97. LastTT: longint;
  98. end;
  99. TAlign = (alLeft,alCenter,alRight);
  100. PFPToolTip = ^TFPToolTip;
  101. TFPToolTip = object(TView)
  102. constructor Init(var Bounds: TRect; const AText: string; AAlign: TAlign);
  103. procedure Draw; virtual;
  104. function GetText: string;
  105. procedure SetText(const AText: string);
  106. function GetAlign: TAlign;
  107. procedure SetAlign(AAlign: TAlign);
  108. function GetPalette: PPalette; virtual;
  109. destructor Done; virtual;
  110. private
  111. Text: PString;
  112. Align: TAlign;
  113. end;
  114. PSourceEditor = ^TSourceEditor;
  115. TSourceEditor = object(TFileEditor)
  116. CompileStamp : longint;
  117. CodeCompleteTip: PFPToolTip;
  118. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  119. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  120. {$ifndef NODEBUG}
  121. private
  122. ShouldHandleBreakpoints : boolean;
  123. {$endif NODEBUG}
  124. public
  125. { Syntax highlight }
  126. function IsReservedWord(const S: string): boolean; virtual;
  127. function IsAsmReservedWord(const S: string): boolean; virtual;
  128. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  129. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  130. { CodeTemplates }
  131. function TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean; virtual;
  132. function SelectCodeTemplate(var ShortCut: string): boolean; virtual;
  133. { CodeComplete }
  134. function CompleteCodeWord(const WordS: string; var Text: string): boolean; virtual;
  135. procedure FindMatchingDelimiter(ScanForward: boolean); virtual;
  136. procedure SetCodeCompleteWord(const S: string); virtual;
  137. procedure AlignCodeCompleteTip;
  138. procedure HandleEvent(var Event: TEvent); virtual;
  139. {$ifdef DebugUndo}
  140. procedure DumpUndo;
  141. procedure UndoAll;
  142. procedure RedoAll;
  143. {$endif DebugUndo}
  144. function Valid(Command: Word): Boolean;virtual;
  145. function GetLocalMenu: PMenu; virtual;
  146. function GetCommandTarget: PView; virtual;
  147. function CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup; virtual;
  148. procedure ModifiedChanged; virtual;
  149. procedure InsertOptions; virtual;
  150. procedure PushInfo(Const st : string);virtual;
  151. procedure PopInfo;virtual;
  152. procedure DeleteLine(I: sw_integer); virtual;
  153. procedure BackSpace; virtual;
  154. procedure DelChar; virtual;
  155. procedure DelSelect; virtual;
  156. function InsertNewLine : Sw_integer;virtual;
  157. function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  158. procedure AddLine(const S: string); virtual;
  159. end;
  160. PSourceWindow = ^TSourceWindow;
  161. TSourceWindow = object(TFPWindow)
  162. Editor : PSourceEditor;
  163. Indicator : PIndicator;
  164. NoNameCount : longint;
  165. constructor Init(var Bounds: TRect; AFileName: string);
  166. function GetTitle(MaxSize: sw_Integer): TTitleStr; virtual;
  167. procedure SetTitle(ATitle: string); virtual;
  168. procedure UpdateTitle; virtual;
  169. procedure HandleEvent(var Event: TEvent); virtual;
  170. procedure Update; virtual;
  171. procedure UpdateCommands; virtual;
  172. function GetPalette: PPalette; virtual;
  173. constructor Load(var S: TStream);
  174. procedure Store(var S: TStream);
  175. procedure Show; virtual;
  176. procedure Hide; virtual;
  177. procedure Close; virtual;
  178. destructor Done; virtual;
  179. end;
  180. {$ifndef NODEBUG}
  181. PGDBSourceEditor = ^TGDBSourceEditor;
  182. TGDBSourceEditor = object(TSourceEditor)
  183. function InsertNewLine : Sw_integer;virtual;
  184. function Valid(Command: Word): Boolean; virtual;
  185. procedure AddLine(const S: string); virtual;
  186. procedure AddErrorLine(const S: string); virtual;
  187. { Syntax highlight }
  188. function IsReservedWord(const S: string): boolean; virtual;
  189. private
  190. Silent,
  191. AutoRepeat,
  192. IgnoreStringAtEnd : boolean;
  193. LastCommand : String;
  194. end;
  195. PGDBWindow = ^TGDBWindow;
  196. TGDBWindow = object(TFPWindow)
  197. Editor : PGDBSourceEditor;
  198. Indicator : PIndicator;
  199. constructor Init(var Bounds: TRect);
  200. procedure HandleEvent(var Event: TEvent); virtual;
  201. procedure WriteText(Buf : PAnsiChar;IsError : boolean);
  202. procedure WriteString(Const S : string);
  203. procedure WriteErrorString(Const S : string);
  204. procedure WriteOutputText(Buf : PAnsiChar);
  205. procedure WriteErrorText(Buf : PAnsiChar);
  206. function GetPalette: PPalette;virtual;
  207. constructor Load(var S: TStream);
  208. procedure Store(var S: TStream);
  209. procedure UpdateCommands; virtual;
  210. destructor Done; virtual;
  211. end;
  212. PDisasLine = ^TDisasLine;
  213. TDisasLine = object(TLine)
  214. address : CORE_ADDR;{ should be target size of address for cross debuggers }
  215. end;
  216. PDisasLineCollection = ^TDisasLineCollection;
  217. TDisasLineCollection = object(TLineCollection)
  218. function At(Index: sw_Integer): PDisasLine;
  219. end;
  220. PDisassemblyEditor = ^TDisassemblyEditor;
  221. TDisassemblyEditor = object(TSourceEditor)
  222. CurrentSource : String;
  223. CurrentLine : longint;
  224. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  225. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  226. procedure ReleaseSource;
  227. destructor Done;virtual;
  228. procedure AddSourceLine(const AFileName: string;line : longint); virtual;
  229. procedure AddAssemblyLine(const S: string;AAddress : CORE_ADDR); virtual;
  230. function GetCurrentLine(address : CORE_ADDR) : PDisasLine;
  231. private
  232. Source : PSourceWindow;
  233. OwnsSource : Boolean;
  234. DisasLines : PDisasLineCollection;
  235. MinAddress,MaxAddress : CORE_ADDR;
  236. CurL : PDisasLine;
  237. end;
  238. PDisassemblyWindow = ^TDisassemblyWindow;
  239. TDisassemblyWindow = object(TFPWindow)
  240. Editor : PDisassemblyEditor;
  241. Indicator : PIndicator;
  242. constructor Init(var Bounds: TRect);
  243. procedure LoadFunction(Const FuncName : string);
  244. procedure LoadAddress(Addr : CORE_ADDR);
  245. function ProcessPChar(p : PAnsiChar) : boolean;
  246. procedure HandleEvent(var Event: TEvent); virtual;
  247. procedure WriteSourceString(Const S : string;line : longint);
  248. procedure WriteDisassemblyString(Const S : string;address : CORE_ADDR);
  249. procedure SetCurAddress(address : CORE_ADDR);
  250. procedure UpdateCommands; virtual;
  251. function GetPalette: PPalette;virtual;
  252. destructor Done; virtual;
  253. end;
  254. {$endif NODEBUG}
  255. PClipboardWindow = ^TClipboardWindow;
  256. TClipboardWindow = object(TSourceWindow)
  257. constructor Init;
  258. procedure Close; virtual;
  259. constructor Load(var S: TStream);
  260. procedure Store(var S: TStream);
  261. destructor Done; virtual;
  262. end;
  263. PMessageItem = ^TMessageItem;
  264. TMessageItem = object(TObject)
  265. TClass : longint;
  266. Text : PString;
  267. Module : PString;
  268. Row,Col : sw_integer;
  269. constructor Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  270. function GetText(MaxLen: Sw_integer): string; virtual;
  271. procedure Selected; virtual;
  272. function GetModuleName: string; virtual;
  273. destructor Done; virtual;
  274. end;
  275. PMessageListBox = ^TMessageListBox;
  276. TMessageListBox = object(THSListBox)
  277. Transparent : boolean;
  278. NoSelection : boolean;
  279. MaxWidth : Sw_integer;
  280. ModuleNames : PStoreCollection;
  281. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  282. procedure SetState(AState: Word; Enable: Boolean); virtual;
  283. procedure AddItem(P: PMessageItem); virtual;
  284. function AddModuleName(const Name: string): PString; virtual;
  285. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  286. procedure Clear; virtual;
  287. procedure TrackSource; virtual;
  288. procedure GotoSource; virtual;
  289. procedure Draw; virtual;
  290. procedure HandleEvent(var Event: TEvent); virtual;
  291. function GetLocalMenu: PMenu; virtual;
  292. constructor Load(var S: TStream);
  293. procedure Store(var S: TStream);
  294. destructor Done; virtual;
  295. end;
  296. PFPDlgWindow = ^TFPDlgWindow;
  297. TFPDlgWindow = object(TDlgWindow)
  298. procedure HandleEvent(var Event: TEvent); virtual;
  299. end;
  300. (*
  301. PTabItem = ^TTabItem;
  302. TTabItem = record
  303. Next : PTabItem;
  304. View : PView;
  305. Dis : boolean;
  306. end;
  307. PTabDef = ^TTabDef;
  308. TTabDef = record
  309. Next : PTabDef;
  310. Name : PString;
  311. Items : PTabItem;
  312. DefItem : PView;
  313. ShortCut : AnsiChar;
  314. end;
  315. PTab = ^TTab;
  316. TTab = object(TGroup)
  317. TabDefs : PTabDef;
  318. ActiveDef : integer;
  319. DefCount : word;
  320. constructor Init(var Bounds: TRect; ATabDef: PTabDef);
  321. function AtTab(Index: integer): PTabDef; virtual;
  322. procedure SelectTab(Index: integer); virtual;
  323. function TabCount: integer;
  324. procedure SelectNextTab(Forwards: boolean);
  325. function Valid(Command: Word): Boolean; virtual;
  326. procedure ChangeBounds(var Bounds: TRect); virtual;
  327. procedure HandleEvent(var Event: TEvent); virtual;
  328. function GetPalette: PPalette; virtual;
  329. procedure Draw; virtual;
  330. procedure SetState(AState: Word; Enable: Boolean); virtual;
  331. destructor Done; virtual;
  332. private
  333. InDraw: boolean;
  334. end;
  335. *)
  336. PScreenView = ^TScreenView;
  337. TScreenView = object(TScroller)
  338. Screen: PScreen;
  339. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  340. AScreen: PScreen);
  341. procedure Draw; virtual;
  342. procedure Update; virtual;
  343. procedure HandleEvent(var Event: TEvent); virtual;
  344. end;
  345. PScreenWindow = ^TScreenWindow;
  346. TScreenWindow = object(TFPWindow)
  347. ScreenView : PScreenView;
  348. constructor Init(AScreen: PScreen; ANumber: integer);
  349. destructor Done; virtual;
  350. end;
  351. PFPChDirDialog = ^TFPChDirDialog;
  352. TFPChDirDialog = object(TChDirDialog)
  353. constructor Init(AOptions: Word; HistoryId: Sw_Word);
  354. end;
  355. PFPAboutDialog = ^TFPAboutDialog;
  356. TFPAboutDialog = object(TCenterDialog)
  357. constructor Init;
  358. procedure ToggleInfo;
  359. procedure HandleEvent(var Event: TEvent); virtual;
  360. private
  361. Scroller: PTextScroller;
  362. TitleST : PStaticText;
  363. end;
  364. PFPASCIIChart = ^TFPASCIIChart;
  365. TFPASCIIChart = object(TASCIIChart)
  366. constructor Init;
  367. constructor Load(var S: TStream);
  368. procedure Store(var S: TStream);
  369. procedure HandleEvent(var Event: TEvent); virtual;
  370. destructor Done; virtual;
  371. end;
  372. PVideoModeListBox = ^TVideoModeListBox;
  373. TVideoModeListBox = object(TDropDownListBox)
  374. function GetText(Item: pointer; MaxLen: sw_integer): string; virtual;
  375. end;
  376. PFPDesktop = ^TFPDesktop;
  377. TFPDesktop = object(TDesktop)
  378. constructor Init(var Bounds: TRect);
  379. procedure InitBackground; virtual;
  380. constructor Load(var S: TStream);
  381. procedure Store(var S: TStream);
  382. end;
  383. PFPMemo = ^TFPMemo;
  384. TFPMemo = object(TCodeEditor)
  385. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  386. PScrollBar; AIndicator: PIndicator);
  387. function IsReservedWord(const S: string): boolean; virtual;
  388. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  389. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  390. function GetPalette: PPalette; virtual;
  391. procedure HandleEvent(var Event: TEvent); virtual;
  392. end;
  393. PFPCodeMemo = ^TFPCodeMemo;
  394. TFPCodeMemo = object(TFPMemo)
  395. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  396. PScrollBar; AIndicator: PIndicator);
  397. function IsReservedWord(const S: string): boolean; virtual;
  398. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  399. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring; virtual;
  400. end;
  401. function SearchFreeWindowNo: integer;
  402. function IsWindow(P: PView): boolean;
  403. function IsThereAnyEditor: boolean;
  404. function IsThereAnyWindow: boolean;
  405. function IsThereAnyVisibleWindow: boolean;
  406. function IsThereAnyVisibleEditorWindow: boolean; {any visible Source Editor, including Clipboard}
  407. function IsThereAnyNumberedWindow: boolean;
  408. function FirstEditorWindow: PSourceWindow;
  409. function EditorWindowFile(const Name : String): PSourceWindow;
  410. procedure AskToReloadAllModifiedFiles;
  411. {$ifndef NODEBUG}
  412. function InDisassemblyWindow :boolean;
  413. {$endif NODEBUG}
  414. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  415. procedure DisposeTabItem(P: PTabItem);
  416. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  417. procedure DisposeTabDef(P: PTabDef);
  418. function GetEditorCurWord(Editor: PEditor; ValidSpecChars: TCharSet): string;
  419. procedure InitReservedWords;
  420. procedure DoneReservedWords;
  421. function GetReservedWordCount: integer;
  422. function GetReservedWord(Index: integer): string;
  423. function GetAsmReservedWordCount: integer;
  424. function GetAsmReservedWord(Index: integer): string;
  425. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  426. function GetNextEditorBounds(var Bounds: TRect): boolean;
  427. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  428. function IOpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer; ShowIt: boolean): PSourceWindow;
  429. function LastSourceEditor : PSourceWindow;
  430. function SearchOnDesktop(FileName : string;tryexts:boolean) : PSourceWindow;
  431. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts: boolean): PSourceWindow;
  432. function TryToOpenFileMulti(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts: boolean): PSourceWindow;
  433. function ITryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts, ShowIt,
  434. ForceNewWindow:boolean): PSourceWindow;
  435. function LocateSourceFile(const FileName: string; tryexts: boolean): string;
  436. function SearchWindow(const Title: string): PWindow;
  437. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  438. {$ifdef VESA}
  439. procedure InitVESAScreenModes;
  440. procedure DoneVESAScreenModes;
  441. {$endif}
  442. procedure NoDebugger;
  443. const
  444. SourceCmds : TCommandSet =
  445. ([cmSave,cmSaveAs,cmCompile,cmHide,cmDoReload]);
  446. EditorCmds : TCommandSet =
  447. ([cmPrint,cmFind,cmReplace,cmSearchAgain,cmJumpLine,cmHelpTopicSearch,cmSelectAll,cmUnselect]);
  448. CompileCmds : TCommandSet =
  449. ([cmMake,cmBuild,cmRun]);
  450. CalcClipboard : extended = 0;
  451. OpenFileName : string = '';
  452. OpenFileLastExt : string[12] = '*.pas';
  453. NewEditorOpened : boolean = false;
  454. var MsgParms : array[1..10] of
  455. record
  456. case byte of
  457. 0 : (Ptr : pointer);
  458. 1 : (Long: longint);
  459. end;
  460. const menu_key_common_copy_borland = 'Ctrl+Ins';
  461. menu_key_common_copy_microsoft = 'Ctrl+C';
  462. menu_key_edit_undo = 'Alt+BkSp';
  463. menu_key_edit_cut_borland = 'Shift+Del';
  464. menu_key_edit_copy_borland = menu_key_common_copy_borland;
  465. menu_key_edit_paste_borland = 'Shift+Ins';
  466. menu_key_edit_cut_microsoft = 'Ctrl+X';
  467. menu_key_edit_copy_microsoft = menu_key_common_copy_microsoft;
  468. menu_key_edit_paste_microsoft = 'Ctrl+V';
  469. menu_key_edit_all_borland = '';
  470. menu_key_edit_clear = 'Ctrl+Del';
  471. menu_key_common_helpindex = 'Shift+F1';
  472. menu_key_common_topicsearch = 'Ctrl+F1';
  473. menu_key_common_prevtopic = 'Alt+F1';
  474. menu_key_help_helpindex= menu_key_common_helpindex;
  475. menu_key_help_topicsearch = menu_key_common_topicsearch;
  476. menu_key_help_prevtopic= menu_key_common_prevtopic;
  477. menu_key_hlplocal_index = menu_key_common_helpindex;
  478. menu_key_hlplocal_topicsearch = menu_key_common_topicsearch;
  479. menu_key_hlplocal_prevtopic = menu_key_common_prevtopic;
  480. menu_key_hlplocal_copy_borland = menu_key_common_copy_borland;
  481. menu_key_hlplocal_copy_microsoft = menu_key_common_copy_microsoft;
  482. {Configurable keys.}
  483. const menu_key_edit_cut:string[63]=menu_key_edit_cut_borland;
  484. menu_key_edit_copy:string[63]=menu_key_edit_copy_borland;
  485. menu_key_edit_paste:string[63]=menu_key_edit_paste_borland;
  486. menu_key_edit_all:string[63]=menu_key_edit_all_borland;
  487. menu_key_hlplocal_copy:string[63]=menu_key_hlplocal_copy_borland;
  488. procedure RegisterFPViews;
  489. implementation
  490. uses
  491. Video,Strings,Keyboard,Validate,
  492. globtype,Tokens,Version,
  493. systems,cpubase,
  494. {$ifdef jvm}
  495. //itcpujas,
  496. {$else}
  497. itcpugas,
  498. {$endif jvm}
  499. {$if defined(I386) or defined(x64_86)}
  500. rax86,
  501. {$endif}
  502. {$ifdef m68k}
  503. ag68kgas,
  504. {$endif}
  505. {$ifdef USE_EXTERNAL_COMPILER}
  506. fpintf, { superseeds version_string of version unit }
  507. {$endif USE_EXTERNAL_COMPILER}
  508. {$ifdef VESA}Vesa,{$endif}
  509. FPSwitch,FPSymbol,FPDebug,FPVars,FPUtils,FPCompil,FPHelp,
  510. FPTools,FPIDE,FPCodTmp,FPCodCmp;
  511. const
  512. RSourceEditor: TStreamRec = (
  513. ObjType: 1500;
  514. VmtLink: Ofs(TypeOf(TSourceEditor)^);
  515. Load: @TSourceEditor.Load;
  516. Store: @TSourceEditor.Store
  517. );
  518. RSourceWindow: TStreamRec = (
  519. ObjType: 1501;
  520. VmtLink: Ofs(TypeOf(TSourceWindow)^);
  521. Load: @TSourceWindow.Load;
  522. Store: @TSourceWindow.Store
  523. );
  524. RFPHelpViewer: TStreamRec = (
  525. ObjType: 1502;
  526. VmtLink: Ofs(TypeOf(TFPHelpViewer)^);
  527. Load: @TFPHelpViewer.Load;
  528. Store: @TFPHelpViewer.Store
  529. );
  530. RFPHelpWindow: TStreamRec = (
  531. ObjType: 1503;
  532. VmtLink: Ofs(TypeOf(TFPHelpWindow)^);
  533. Load: @TFPHelpWindow.Load;
  534. Store: @TFPHelpWindow.Store
  535. );
  536. RClipboardWindow: TStreamRec = (
  537. ObjType: 1504;
  538. VmtLink: Ofs(TypeOf(TClipboardWindow)^);
  539. Load: @TClipboardWindow.Load;
  540. Store: @TClipboardWindow.Store
  541. );
  542. RMessageListBox: TStreamRec = (
  543. ObjType: 1505;
  544. VmtLink: Ofs(TypeOf(TMessageListBox)^);
  545. Load: @TMessageListBox.Load;
  546. Store: @TMessageListBox.Store
  547. );
  548. RFPDesktop: TStreamRec = (
  549. ObjType: 1506;
  550. VmtLink: Ofs(TypeOf(TFPDesktop)^);
  551. Load: @TFPDesktop.Load;
  552. Store: @TFPDesktop.Store
  553. );
  554. RFPASCIIChart: TStreamRec = (
  555. ObjType: 1509;
  556. VmtLink: Ofs(TypeOf(TFPASCIIChart)^);
  557. Load: @TFPASCIIChart.Load;
  558. Store: @TFPASCIIChart.Store
  559. );
  560. RFPDlgWindow: TStreamRec = (
  561. ObjType: 1511;
  562. VmtLink: Ofs(TypeOf(TFPDlgWindow)^);
  563. Load: @TFPDlgWindow.Load;
  564. Store: @TFPDlgWindow.Store
  565. );
  566. {$ifndef NODEBUG}
  567. RGDBWindow: TStreamRec = (
  568. ObjType: 1508;
  569. VmtLink: Ofs(TypeOf(TGDBWindow)^);
  570. Load: @TGDBWindow.Load;
  571. Store: @TGDBWindow.Store
  572. );
  573. RGDBSourceEditor: TStreamRec = (
  574. ObjType: 1507;
  575. VmtLink: Ofs(TypeOf(TGDBSourceEditor)^);
  576. Load: @TGDBSourceEditor.Load;
  577. Store: @TGDBSourceEditor.Store
  578. );
  579. RDisassemblyEditor: TStreamRec = (
  580. ObjType: 1512;
  581. VmtLink: Ofs(TypeOf(TDisassemblyEditor)^);
  582. Load: @TDisassemblyEditor.Load;
  583. Store: @TDisassemblyEditor.Store
  584. );
  585. RDisassemblyWindow: TStreamRec = (
  586. ObjType: 1513;
  587. VmtLink: Ofs(TypeOf(TDisassemblyWindow)^);
  588. Load: @TDisassemblyWindow.Load;
  589. Store: @TDisassemblyWindow.Store
  590. );
  591. {$endif NODEBUG}
  592. const
  593. GlobalNoNameCount : integer = 0;
  594. var
  595. ReservedWords : array[1..ReservedWordMaxLen] of PStringCollection;
  596. AsmReservedWords : array[1..ReservedWordMaxLen] of PStringCollection;
  597. {$ifdef useresstrings}
  598. resourcestring
  599. {$else}
  600. const
  601. {$endif}
  602. { Source editor local menu items }
  603. menu_srclocal_openfileatcursor = 'Open ~f~ile at cursor';
  604. menu_srclocal_browseatcursor = '~B~rowse symbol at cursor';
  605. menu_srclocal_topicsearch = 'Topic ~s~earch';
  606. menu_srclocal_options = '~O~ptions...';
  607. menu_srclocal_reload = '~R~eload modified file';
  608. { Help viewer local menu items }
  609. menu_hlplocal_debug = 'Debug infos';
  610. menu_hlplocal_contents = '~C~ontents';
  611. menu_hlplocal_index = '~I~ndex';
  612. menu_hlplocal_topicsearch = '~T~opic search';
  613. menu_hlplocal_prevtopic = '~P~revious topic';
  614. menu_hlplocal_copy = '~C~opy';
  615. { Messages local menu items }
  616. menu_msglocal_clear = '~C~lear';
  617. menu_msglocal_gotosource = '~G~oto source';
  618. menu_msglocal_tracksource = '~T~rack source';
  619. menu_edit_cut = 'Cu~t~';
  620. menu_edit_copy = '~C~opy';
  621. menu_edit_paste = '~P~aste';
  622. menu_edit_clear = 'C~l~ear';
  623. msg_errorreadingfile = 'Error reading file %s';
  624. msg_loadingfile = 'Loading %s';
  625. msg_storingfile = 'Storing %s';
  626. msg_closingfile = 'Closing %s';
  627. dialog_gdbwindow = 'GDB window';
  628. dialog_disaswindow = 'Disassembly window';
  629. dialog_clipboard = 'Clipboard';
  630. dialog_userscreen = 'User screen';
  631. dialog_about = 'About';
  632. label_about_compilerversion = 'Compiler Version';
  633. label_about_debugger = 'Debugger';
  634. menu_msglocal_saveas = 'Save ~a~s';
  635. msg_openingsourcefile = 'Opening source file... (%s)';
  636. msg_readingfileineditor = 'Reading %s into editor...';
  637. msg_nodebuggersupportavailable = 'No debugger support available.';
  638. {****************************************************************************
  639. TStoreCollection
  640. ****************************************************************************}
  641. function TStoreCollection.Add(const S: string): PString;
  642. var P: PString;
  643. Index: Sw_integer;
  644. begin
  645. if S='' then P:=nil else
  646. if Search(@S,Index) then P:=At(Index) else
  647. begin
  648. P:=NewStr(S);
  649. Insert(P);
  650. end;
  651. Add:=P;
  652. end;
  653. function IsThereAnyEditor: boolean;
  654. function EditorWindow(P: PView): boolean;
  655. begin
  656. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  657. end;
  658. begin
  659. IsThereAnyEditor:=Desktop^.FirstThat(@EditorWindow)<>nil;
  660. end;
  661. procedure AskToReloadAllModifiedFiles;
  662. procedure EditorWindowModifiedOnDisk(P: PView);
  663. begin
  664. if (P^.HelpCtx=hcSourceWindow) then
  665. PSourceWindow(P)^.Editor^.ReloadFile;
  666. end;
  667. begin
  668. Desktop^.ForEach(TCallbackProcParam(@EditorWindowModifiedOnDisk));
  669. end;
  670. function IsThereAnyHelpWindow: boolean;
  671. begin
  672. IsThereAnyHelpWindow:=(HelpWindow<>nil) and (HelpWindow^.GetState(sfVisible));
  673. end;
  674. function IsThereAnyNumberedWindow: boolean;
  675. var _Is: boolean;
  676. begin
  677. _Is:=Message(Desktop,evBroadcast,cmSearchWindow,nil)<>nil;
  678. _Is:=_Is or ( (ClipboardWindow<>nil) and ClipboardWindow^.GetState(sfVisible));
  679. IsThereAnyNumberedWindow:=_Is;
  680. end;
  681. function IsWindow(P: PView): boolean;
  682. var OK: boolean;
  683. begin
  684. OK:=false;
  685. if (P^.HelpCtx=hcSourceWindow) or
  686. (P^.HelpCtx=hcHelpWindow) or
  687. (P^.HelpCtx=hcClipboardWindow) or
  688. (P^.HelpCtx=hcCalcWindow) or
  689. (P^.HelpCtx=hcInfoWindow) or
  690. (P^.HelpCtx=hcBrowserWindow) or
  691. (P^.HelpCtx=hcMessagesWindow) or
  692. (P^.HelpCtx=hcCompilerMessagesWindow) or
  693. (P^.HelpCtx=hcGDBWindow) or
  694. (P^.HelpCtx=hcdisassemblyWindow) or
  695. (P^.HelpCtx=hcWatchesWindow) or
  696. (P^.HelpCtx=hcRegistersWindow) or
  697. (P^.HelpCtx=hcFPURegisters) or
  698. (P^.HelpCtx=hcVectorRegisters) or
  699. (P^.HelpCtx=hcStackWindow) or
  700. (P^.HelpCtx=hcBreakpointListWindow) or
  701. (P^.HelpCtx=hcASCIITableWindow)
  702. then
  703. OK:=true;
  704. IsWindow:=OK;
  705. end;
  706. function IsThereAnyWindow: boolean;
  707. function CheckIt(P: PView): boolean;
  708. begin
  709. CheckIt:=IsWindow(P);
  710. end;
  711. begin
  712. IsThereAnyWindow:=Desktop^.FirstThat(@CheckIt)<>nil;
  713. end;
  714. function IsThereAnyVisibleWindow: boolean;
  715. function CheckIt(P: PView): boolean;
  716. begin
  717. CheckIt:=IsWindow(P) and P^.GetState(sfVisible);
  718. end;
  719. begin
  720. IsThereAnyVisibleWindow:=Desktop^.FirstThat(@CheckIt)<>nil;
  721. end;
  722. function IsThereAnyVisibleEditorWindow: boolean;
  723. function EditorWindow(P: PView): boolean;
  724. begin
  725. EditorWindow:=((P^.HelpCtx=hcSourceWindow) or (P^.HelpCtx=hcClipboardWindow)) and P^.GetState(sfVisible);
  726. end;
  727. begin
  728. IsThereAnyVisibleEditorWindow:=Desktop^.FirstThat(@EditorWindow)<>nil;
  729. end;
  730. function FirstEditorWindow: PSourceWindow;
  731. function EditorWindow(P: PView): boolean;
  732. begin
  733. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  734. end;
  735. begin
  736. FirstEditorWindow:=pointer(Desktop^.FirstThat(@EditorWindow));
  737. end;
  738. function EditorWindowFile(const Name : String): PSourceWindow;
  739. var
  740. SName : string;
  741. function EditorWindow(P: PView): boolean;
  742. begin
  743. EditorWindow:=(TypeOf(P^)=TypeOf(TSourceWindow)) and
  744. (FixFileName(PSourceWindow(P)^.Editor^.FileName)=SName);
  745. end;
  746. begin
  747. SName:=FixFileName(FExpand(Name));
  748. EditorWindowFile:=pointer(Desktop^.FirstThat(@EditorWindow));
  749. end;
  750. {$ifndef NODEBUG}
  751. function InDisassemblyWindow :boolean;
  752. var
  753. PW : PWindow;
  754. function CheckIt(P: PView): boolean;
  755. begin
  756. CheckIt:=IsWindow(P) and P^.GetState(sfVisible) and
  757. (P^.HelpCtx <> hcWatchesWindow) and
  758. (P^.HelpCtx <> hcStackWindow) and
  759. (P^.HelpCtx <> hcRegistersWindow) and
  760. (P^.HelpCtx <> hcVectorRegisters) and
  761. (P^.HelpCtx <> hcFPURegisters);
  762. end;
  763. begin
  764. PW:=PWindow(Desktop^.FirstThat(@CheckIt));
  765. InDisassemblyWindow:=Assigned(PW) and
  766. (TypeOf(PW^)=TypeOf(TDisassemblyWindow));
  767. end;
  768. {$endif NODEBUG}
  769. function GetEditorCurWord(Editor: PEditor; ValidSpecChars: TCharSet): string;
  770. var S: string;
  771. PS,PE: byte;
  772. function Trim(S: string): string;
  773. const TrimChars : set of AnsiChar = [#0,#9,' ',#255];
  774. begin
  775. while (length(S)>0) and (S[1] in TrimChars) do Delete(S,1,1);
  776. while (length(S)>0) and (S[length(S)] in TrimChars) do Delete(S,length(S),1);
  777. Trim:=S;
  778. end;
  779. const AlphaNum : set of AnsiChar = ['A'..'Z','0'..'9','_'];
  780. begin
  781. with Editor^ do
  782. begin
  783. S:=GetDisplayText(CurPos.Y);
  784. PS:=CurPos.X; while (PS>0) and (Upcase(S[PS]) in AlphaNum) do Dec(PS);
  785. PE:=CurPos.X; while (PE<length(S)) and (Upcase(S[PE+1]) in (AlphaNum+ValidSpecChars)) do Inc(PE);
  786. S:=Trim(copy(S,PS+1,PE-PS));
  787. end;
  788. GetEditorCurWord:=S;
  789. end;
  790. {*****************************************************************************
  791. Tab
  792. *****************************************************************************}
  793. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  794. var P: PTabItem;
  795. begin
  796. New(P); FillChar(P^,SizeOf(P^),0);
  797. P^.Next:=ANext; P^.View:=AView;
  798. NewTabItem:=P;
  799. end;
  800. procedure DisposeTabItem(P: PTabItem);
  801. begin
  802. if P<>nil then
  803. begin
  804. if P^.View<>nil then Dispose(P^.View, Done);
  805. Dispose(P);
  806. end;
  807. end;
  808. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  809. var P: PTabDef;
  810. x: byte;
  811. begin
  812. New(P);
  813. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  814. x:=pos('~',AName);
  815. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  816. else P^.ShortCut:=#0;
  817. P^.DefItem:=ADefItem;
  818. NewTabDef:=P;
  819. end;
  820. procedure DisposeTabDef(P: PTabDef);
  821. var PI,X: PTabItem;
  822. begin
  823. DisposeStr(P^.Name);
  824. PI:=P^.Items;
  825. while PI<>nil do
  826. begin
  827. X:=PI^.Next;
  828. DisposeTabItem(PI);
  829. PI:=X;
  830. end;
  831. Dispose(P);
  832. end;
  833. {*****************************************************************************
  834. Reserved Words
  835. *****************************************************************************}
  836. function GetReservedWordCount: integer;
  837. var
  838. Count,I: integer;
  839. begin
  840. Count:=0;
  841. for I:=ord(Low(tToken)) to ord(High(tToken)) do
  842. with TokenInfo^[TToken(I)] do
  843. if (str<>'') and (str[1] in['A'..'Z']) and (length(str)>1) then
  844. Inc(Count);
  845. GetReservedWordCount:=Count;
  846. end;
  847. function GetReservedWord(Index: integer): string;
  848. var
  849. Count,Idx,I: integer;
  850. S: string;
  851. begin
  852. Idx:=-1;
  853. Count:=-1;
  854. I:=ord(Low(tToken));
  855. while (I<=ord(High(tToken))) and (Idx=-1) do
  856. with TokenInfo^[TToken(I)] do
  857. begin
  858. if (str<>'') and (str[1] in['A'..'Z']) and (length(str)>1) then
  859. begin
  860. Inc(Count);
  861. if Count=Index then
  862. Idx:=I;
  863. end;
  864. Inc(I);
  865. end;
  866. if Idx=-1 then
  867. S:=''
  868. else
  869. S:=TokenInfo^[TToken(Idx)].str;
  870. GetReservedWord:=S;
  871. end;
  872. {$ifdef powerpc}
  873. {$define USE_TasmCondFlag}
  874. { powerpc only has A_B prefix }
  875. const
  876. CondAsmOps = 1;
  877. CondAsmOpStr : array [0..CondAsmOps-1] of string[2] = ('b');
  878. {$define Use_gas_op2str}
  879. {$endif}
  880. {$ifdef powerpc64}
  881. {$define USE_TasmCondFlag}
  882. { powerpc64 only has A_B prefix }
  883. const
  884. CondAsmOps = 1;
  885. CondAsmOpStr : array [0..CondAsmOps-1] of string[2] = ('b');
  886. {$define Use_gas_op2str}
  887. {$endif}
  888. {$ifdef i386}
  889. {$define USE_TasmCond}
  890. {$define Use_std_op2str}
  891. {$endif}
  892. {$ifdef m68k}
  893. {$define USE_None}
  894. {$define Use_gas_op2str}
  895. {$endif}
  896. function GetAsmReservedWordCount: integer;
  897. begin
  898. GetAsmReservedWordCount:=ord(lastop) - ord(firstop)
  899. {$ifdef Use_TasmCond}
  900. + CondAsmOps*(ord(high(TasmCond))-ord(low(TasmCond)));
  901. {$endif Use_TasmCond}
  902. {$ifdef Use_TasmCondFlag}
  903. + CondAsmOps*(ord(high(TasmCondFlag))-ord(low(TasmCondFlag)));
  904. {$endif Use_TasmCondFlag}
  905. {$ifdef Use_None}
  906. ;
  907. {$endif Use_None}
  908. end;
  909. {$define NOASM}
  910. function GetAsmReservedWord(Index: integer): string;
  911. var
  912. CondNum,CondOpNum : integer;
  913. begin
  914. {$ifdef m68k}
  915. {$undef NOASM}
  916. if index <= ord(lastop) - ord(firstop) then
  917. GetAsmReservedWord:=gas_op2str[tasmop(Index+ord(firstop))]
  918. else
  919. GetAsmReservedWord:='';
  920. (*
  921. begin
  922. index:=index - (ord(lastop) - ord(firstop) );
  923. CondOpNum:= index div (ord(high(TasmCond))-ord(low(TasmCond)));
  924. CondNum:=index - (CondOpNum * (ord(high(TasmCond))-ord(low(TasmCond))));
  925. GetAsmReservedWord:=CondAsmOpStr[CondOpNum]+cond2str[TasmCond(CondNum+ord(low(TAsmCond))+1)];
  926. end;
  927. *)
  928. {$else not m68k}
  929. if index <= ord(lastop) - ord(firstop) then
  930. {$ifdef Use_gas_op2str}
  931. GetAsmReservedWord:=gas_op2str[tasmop(Index+ord(firstop))]
  932. {$endif Use_gas_op2str}
  933. {$ifdef Use_std_op2str}
  934. GetAsmReservedWord:=std_op2str[tasmop(Index+ord(firstop))]
  935. {$endif Use_std_op2str}
  936. {$ifdef Use_TASMCond}
  937. {$undef NOASM}
  938. else
  939. begin
  940. index:=index - (ord(lastop) - ord(firstop) );
  941. CondOpNum:= index div (ord(high(TasmCond))-ord(low(TasmCond)));
  942. CondNum:=index - (CondOpNum * (ord(high(TasmCond))-ord(low(TasmCond))));
  943. GetAsmReservedWord:=CondAsmOpStr[CondOpNum]+cond2str[TasmCond(CondNum+ord(low(TAsmCond))+1)];
  944. end;
  945. {$endif Use_TASMCond}
  946. {$ifdef Use_TASMCondFlag}
  947. {$undef NOASM}
  948. else
  949. begin
  950. index:=index - (ord(lastop) - ord(firstop) );
  951. CondOpNum:= index div (ord(high(TasmCondFlag))-ord(low(TasmCondFlag)));
  952. CondNum:=index - (CondOpNum * (ord(high(TasmCondFlag))-ord(low(TasmCondFlag))));
  953. GetAsmReservedWord:=CondAsmOpStr[CondOpNum]+AsmCondFlag2Str[TasmCondFlag(CondNum+ord(low(TAsmCondFlag))+1)];
  954. end;
  955. {$endif Use_TASMCond}
  956. {$endif not m68k}
  957. {$ifdef NOASM}
  958. GetAsmReservedWord:='';
  959. {$endif NOASM}
  960. end;
  961. procedure InitReservedWords;
  962. var WordS: string;
  963. Idx,I,J : sw_integer;
  964. begin
  965. InitTokens;
  966. for I:=Low(ReservedWords) to High(ReservedWords) do
  967. New(ReservedWords[I], Init(50,10));
  968. for I:=1 to GetReservedWordCount do
  969. begin
  970. WordS:=GetReservedWord(I-1); Idx:=length(WordS);
  971. if (Idx>=Low(ReservedWords)) and (Idx<=High(ReservedWords)) then
  972. ReservedWords[Idx]^.Insert(NewStr(WordS));
  973. end;
  974. for I:=Low(AsmReservedWords) to High(AsmReservedWords) do
  975. New(AsmReservedWords[I], Init(50,10));
  976. for I:=1 to GetAsmReservedWordCount do
  977. begin
  978. WordS:=UpcaseStr(GetAsmReservedWord(I-1)); Idx:=length(WordS);
  979. if (Idx>=Low(AsmReservedWords)) and (Idx<=High(AsmReservedWords)) then
  980. begin
  981. if not AsmReservedWords[Idx]^.Search(@WordS, J) then
  982. AsmReservedWords[Idx]^.Insert(NewStr(WordS));
  983. end;
  984. end;
  985. end;
  986. procedure DoneReservedWords;
  987. var I: integer;
  988. begin
  989. for I:=Low(ReservedWords) to High(ReservedWords) do
  990. if assigned(ReservedWords[I]) then
  991. begin
  992. dispose(ReservedWords[I],done);
  993. ReservedWords[I]:=nil;
  994. end;
  995. for I:=Low(AsmReservedWords) to High(AsmReservedWords) do
  996. if assigned(AsmReservedWords[I]) then
  997. begin
  998. dispose(AsmReservedWords[I],done);
  999. ReservedWords[I]:=nil;
  1000. end;
  1001. DoneTokens;
  1002. end;
  1003. function IsFPReservedWord(const S: string): boolean;
  1004. var _Is: boolean;
  1005. Idx,Item: sw_integer;
  1006. UpS: string;
  1007. begin
  1008. Idx:=length(S); _Is:=false;
  1009. if (Low(ReservedWords)<=Idx) and (Idx<=High(ReservedWords)) and
  1010. (ReservedWords[Idx]<>nil) and (ReservedWords[Idx]^.Count<>0) then
  1011. begin
  1012. UpS:=UpcaseStr(S);
  1013. _Is:=ReservedWords[Idx]^.Search(@UpS,Item);
  1014. end;
  1015. IsFPReservedWord:=_Is;
  1016. end;
  1017. function IsFPAsmReservedWord(S: string): boolean;
  1018. var _Is: boolean;
  1019. Idx,Item,Len: sw_integer;
  1020. LastC : AnsiChar;
  1021. LastTwo : String[2];
  1022. begin
  1023. Idx:=length(S); _Is:=false;
  1024. if (Low(AsmReservedWords)<=Idx) and (Idx<=High(AsmReservedWords)) and
  1025. (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  1026. begin
  1027. S:=UpcaseStr(S);
  1028. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  1029. {$ifdef i386}
  1030. if not _Is and (Length(S)>1) then
  1031. begin
  1032. LastC:=S[Length(S)];
  1033. if LastC in ['B','D','L','Q','S','T','V','W'] then
  1034. begin
  1035. Delete(S,Length(S),1);
  1036. Dec(Idx);
  1037. if (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  1038. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  1039. if not _Is and (Length(S)>1) then
  1040. begin
  1041. LastTwo:=S[Length(S)]+LastC;
  1042. if (LastTwo='BL') or
  1043. (LastTwo='WL') or
  1044. (LastTwo='BW') then
  1045. begin
  1046. Delete(S,Length(S),1);
  1047. Dec(Idx);
  1048. if (AsmReservedWords[Idx]<>nil) and (AsmReservedWords[Idx]^.Count<>0) then
  1049. _Is:=AsmReservedWords[Idx]^.Search(@S,Item);
  1050. end;
  1051. end;
  1052. end;
  1053. end;
  1054. {$endif i386}
  1055. end;
  1056. IsFPAsmReservedWord:=_Is;
  1057. end;
  1058. {*****************************************************************************
  1059. SearchWindow
  1060. *****************************************************************************}
  1061. function SearchWindowWithNo(No: integer): PWindow;
  1062. var P: PWindow;
  1063. begin
  1064. P:=Message(Desktop,evBroadcast,cmSearchWindow+No,nil);
  1065. if pointer(P)=pointer(Desktop) then P:=nil;
  1066. SearchWindowWithNo:=P;
  1067. end;
  1068. function SearchWindow(const Title: string): PWindow;
  1069. function Match(P: PView): boolean;
  1070. var W: PWindow;
  1071. OK: boolean;
  1072. begin
  1073. W:=nil;
  1074. { we have a crash here because of the TStatusLine
  1075. that can also have one of these values
  1076. but is not a Window object PM }
  1077. if P<>pointer(StatusLine) then
  1078. if IsWindow(P) then
  1079. W:=PWindow(P);
  1080. OK:=(W<>nil);
  1081. if OK then
  1082. begin
  1083. OK:=CompareText(W^.GetTitle(255),Title)=0;
  1084. end;
  1085. Match:=OK;
  1086. end;
  1087. var W: PView;
  1088. begin
  1089. W:=Application^.FirstThat(@Match);
  1090. { This is wrong because TStatusLine is also considered PM }
  1091. if not Assigned(W) then W:=Desktop^.FirstThat(@Match);
  1092. { But why do we need to check all ??
  1093. Probably because of the ones which were not inserted into
  1094. Desktop as the Messages view
  1095. Exactly. Some windows are inserted directly in the Application and not
  1096. in the Desktop. btw. Does TStatusLine.HelpCtx really change? Why?
  1097. Only GetHelpCtx should return different values depending on the
  1098. focused view (and it's helpctx), but TStatusLine's HelpCtx field
  1099. shouldn't change... Gabor
  1100. if Assigned(W)=false then W:=Desktop^.FirstThat(@Match);}
  1101. SearchWindow:=PWindow(W);
  1102. end;
  1103. function SearchFreeWindowNo: integer;
  1104. var No: integer;
  1105. begin
  1106. No:=1;
  1107. while (No<100) and (SearchWindowWithNo(No)<>nil) do
  1108. Inc(No);
  1109. if No=100 then No:=0;
  1110. SearchFreeWindowNo:=No;
  1111. end;
  1112. {*****************************************************************************
  1113. TIntegerLine
  1114. *****************************************************************************}
  1115. constructor TIntegerLine.Init(var Bounds: TRect; AMin, AMax: longint);
  1116. begin
  1117. if inherited Init(Bounds, Bounds.B.X-Bounds.A.X-1)=false then
  1118. Fail;
  1119. Validator:=New(PRangeValidator, Init(AMin, AMax));
  1120. end;
  1121. {*****************************************************************************
  1122. SourceEditor
  1123. *****************************************************************************}
  1124. function SearchCoreForFileName(AFileName: string): PCodeEditorCore;
  1125. var EC: PCodeEditorCore;
  1126. function Check(P: PView): boolean;
  1127. var OK: boolean;
  1128. begin
  1129. OK:=P^.HelpCtx=hcSourceWindow;
  1130. if OK then
  1131. with PSourceWindow(P)^ do
  1132. if FixFileName(Editor^.FileName)=AFileName then
  1133. begin
  1134. EC:=Editor^.Core;
  1135. OK:=true;
  1136. end
  1137. else
  1138. OK:=false;
  1139. Check:=OK;
  1140. end;
  1141. begin
  1142. EC:=nil;
  1143. AFileName:=FixFileName(AFileName);
  1144. { do not use the same core for all new files }
  1145. if AFileName<>'' then
  1146. Desktop^.FirstThat(@Check);
  1147. SearchCoreForFileName:=EC;
  1148. end;
  1149. constructor TSourceEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  1150. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  1151. var EC: PCodeEditorCore;
  1152. begin
  1153. EC:=SearchCoreForFileName(AFileName);
  1154. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,EC,AFileName);
  1155. SetStoreUndo(true);
  1156. CompileStamp:=0;
  1157. end;
  1158. Const
  1159. FreePascalSpecSymbolCount : array [TSpecSymbolClass] of integer =
  1160. (
  1161. 3,{ssCommentPrefix}
  1162. 1,{ssCommentSingleLinePrefix}
  1163. 2,{ssCommentSuffix}
  1164. 1,{ssStringPrefix}
  1165. 1,{ssStringSuffix}
  1166. 1,{ssDirectivePrefix}
  1167. 1,{ssDirectiveSuffix}
  1168. 1,{ssAsmPrefix}
  1169. 1 {ssAsmSuffix}
  1170. );
  1171. FreePascalEmptyString : string[1] = '';
  1172. FreePascalCommentPrefix1 : string[1] = '{';
  1173. FreePascalCommentPrefix2 : string[2] = '(*';
  1174. FreePascalCommentPrefix3 : string[2] = '//';
  1175. FreePascalCommentSingleLinePrefix : string[2] = '//';
  1176. FreePascalCommentSuffix1 : string[1] = '}';
  1177. FreePascalCommentSuffix2 : string[2] = '*)';
  1178. FreePascalStringPrefix : string[1] = '''';
  1179. FreePascalStringSuffix : string[1] = '''';
  1180. FreePascalDirectivePrefix : string[2] = '{$';
  1181. FreePascalDirectiveSuffix : string[1] = '}';
  1182. FreePascalAsmPrefix : string[3] = 'ASM';
  1183. FreePascalAsmSuffix : string[3] = 'END';
  1184. function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  1185. begin
  1186. GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
  1187. end;
  1188. function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  1189. begin
  1190. GetSpecSymbol:=@FreePascalEmptyString;
  1191. case SpecClass of
  1192. ssCommentPrefix :
  1193. case Index of
  1194. 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
  1195. 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
  1196. 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
  1197. end;
  1198. ssCommentSingleLinePrefix :
  1199. case Index of
  1200. 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
  1201. end;
  1202. ssCommentSuffix :
  1203. case Index of
  1204. 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
  1205. 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
  1206. end;
  1207. ssStringPrefix :
  1208. GetSpecSymbol:=@FreePascalStringPrefix;
  1209. ssStringSuffix :
  1210. GetSpecSymbol:=@FreePascalStringSuffix;
  1211. { must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
  1212. ssAsmPrefix :
  1213. GetSpecSymbol:=@FreePascalAsmPrefix;
  1214. ssAsmSuffix :
  1215. GetSpecSymbol:=@FreePascalAsmSuffix;
  1216. ssDirectivePrefix :
  1217. GetSpecSymbol:=@FreePascalDirectivePrefix;
  1218. ssDirectiveSuffix :
  1219. GetSpecSymbol:=@FreePascalDirectiveSuffix;
  1220. end;
  1221. end;
  1222. function TSourceEditor.IsReservedWord(const S: string): boolean;
  1223. begin
  1224. IsReservedWord:=IsFPReservedWord(S);
  1225. end;
  1226. function TSourceEditor.IsAsmReservedWord(const S: string): boolean;
  1227. begin
  1228. IsAsmReservedWord:=IsFPAsmReservedWord(S);
  1229. end;
  1230. function TSourceEditor.TranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean;
  1231. begin
  1232. TranslateCodeTemplate:=FPTranslateCodeTemplate(ShortCut,ALines);
  1233. end;
  1234. function TSourceEditor.SelectCodeTemplate(var ShortCut: string): boolean;
  1235. var D: PCodeTemplatesDialog;
  1236. OK: boolean;
  1237. begin
  1238. New(D, Init(true,ShortCut));
  1239. OK:=Desktop^.ExecView(D)=cmOK;
  1240. if OK then ShortCut:=D^.GetSelectedShortCut;
  1241. Dispose(D, Done);
  1242. SelectCodeTemplate:=OK;
  1243. end;
  1244. function TSourceEditor.CompleteCodeWord(const WordS: string; var Text: string): boolean;
  1245. begin
  1246. CompleteCodeWord:=FPCompleteCodeWord(WordS,Text);
  1247. end;
  1248. procedure TSourceEditor.FindMatchingDelimiter(ScanForward: boolean);
  1249. var
  1250. St,nextResWord : String;
  1251. LineText,LineAttr: string;
  1252. Res,found,addit : boolean;
  1253. JumpPos: TPoint;
  1254. X,Y,lexchange,curlevel,linecount : sw_integer;
  1255. function GetLexChange(const S : string) : sw_integer;
  1256. begin
  1257. if (S='END') or (S='THEN') or (S='UNTIL') then
  1258. GetLexChange:=-1
  1259. else if (S='ASM') or (S='BEGIN') or (S='CASE') or (S='CLASS') or
  1260. (S='IF') or (S='OBJECT') or (S='RECORD') or (S='REPEAT') then
  1261. GetLexChange:=+1
  1262. else
  1263. GetLexChange:=0;
  1264. end;
  1265. begin
  1266. st:=UpcaseStr(GetCurrentWord);
  1267. if st<>'' then
  1268. Res:=IsReservedWord(St)
  1269. else
  1270. Res:=false;
  1271. LexChange:=GetLexChange(St);
  1272. if not res or (LexChange=0) or not
  1273. IsFlagSet(efSyntaxHighlight) then
  1274. Inherited FindMatchingDelimiter(ScanForward)
  1275. else
  1276. begin
  1277. JumpPos.X:=-1; JumpPos.Y:=-1;
  1278. Y:=CurPos.Y; X:=CurPos.X;
  1279. found:=false;
  1280. LineCount:=0;
  1281. curlevel:=lexchange;
  1282. if LexChange>0 then
  1283. begin
  1284. repeat
  1285. Inc(LineCount);
  1286. NextResWord:='';
  1287. GetDisplayTextFormat(Y,LineText,LineAttr);
  1288. if LineCount<>1 then X:=-1
  1289. else if ord(LineAttr[X+1])<>coReservedWordColor then
  1290. exit;
  1291. repeat
  1292. Inc(X);
  1293. if X<length(LineText) then
  1294. begin
  1295. AddIt:=ord(LineAttr[X+1])=coReservedWordColor;
  1296. if AddIt then
  1297. NextResWord:=NextResWord+UpCase(LineText[X+1]);
  1298. end;
  1299. if ((X=length(LineText)) or (Not AddIt)) and
  1300. (NextResWord<>'') and
  1301. IsReservedWord(NextResWord) then
  1302. begin
  1303. LexChange:=GetLexChange(NextResWord);
  1304. CurLevel:=CurLevel+LexChange;
  1305. if CurLevel=0 then
  1306. begin
  1307. JumpPos.X:=X-Length(NextResWord);
  1308. JumpPos.Y:=Y;
  1309. end;
  1310. NextResWord:='';
  1311. end;
  1312. until (X>=length(LineText)) or (JumpPos.X<>-1);
  1313. Inc(Y);
  1314. until (Y>=GetLineCount) or (JumpPos.X<>-1);
  1315. if (Y=GetLineCount) and (JumpPos.X=-1) then
  1316. begin
  1317. ErrorBox('No match',nil);
  1318. exit;
  1319. end;
  1320. end
  1321. else if (LexChange<0) then
  1322. begin
  1323. repeat
  1324. Inc(LineCount);
  1325. NextResWord:='';
  1326. GetDisplayTextFormat(Y,LineText,LineAttr);
  1327. if LineCount<>1 then
  1328. X:=Length(LineText)
  1329. else if ord(LineAttr[X+1])<>coReservedWordColor then
  1330. exit;
  1331. repeat
  1332. Dec(X);
  1333. if X>=0 then
  1334. begin
  1335. AddIt:=ord(LineAttr[X+1])=coReservedWordColor;
  1336. if AddIt then
  1337. NextResWord:=UpCase(LineText[X+1])+NextResWord;
  1338. end;
  1339. if ((X=0) or (Not AddIt)) and
  1340. (NextResWord<>'') and
  1341. IsReservedWord(NextResWord) then
  1342. begin
  1343. LexChange:=GetLexChange(NextResWord);
  1344. CurLevel:=CurLevel+LexChange;
  1345. if CurLevel=0 then
  1346. begin
  1347. if AddIt then
  1348. JumpPos.X:=X
  1349. else
  1350. JumpPos.X:=X+1;
  1351. JumpPos.Y:=Y;
  1352. end;
  1353. NextResWord:='';
  1354. end;
  1355. until (X<=0) or (JumpPos.X<>-1);
  1356. Dec(Y);
  1357. until (Y<0) or (JumpPos.X<>-1);
  1358. if (Y<0) and (JumpPos.X=-1) then
  1359. begin
  1360. ErrorBox('No match',nil);
  1361. exit;
  1362. end;
  1363. end;
  1364. if JumpPos.X<>-1 then
  1365. begin
  1366. SetCurPtr(JumpPos.X,JumpPos.Y);
  1367. TrackCursor(do_centre);
  1368. end;
  1369. end;
  1370. end;
  1371. procedure TSourceEditor.SetCodeCompleteWord(const S: string);
  1372. var R: TRect;
  1373. begin
  1374. inherited SetCodeCompleteWord(S);
  1375. if S='' then
  1376. begin
  1377. if Assigned(CodeCompleteTip) then Dispose(CodeCompleteTip, Done);
  1378. CodeCompleteTip:=nil;
  1379. end
  1380. else
  1381. begin
  1382. R.Assign(0,0,20,1);
  1383. if Assigned(CodeCompleteTip)=false then
  1384. begin
  1385. New(CodeCompleteTip, Init(R, S, alCenter));
  1386. CodeCompleteTip^.Hide;
  1387. Application^.Insert(CodeCompleteTip);
  1388. end
  1389. else
  1390. CodeCompleteTip^.SetText(S);
  1391. AlignCodeCompleteTip;
  1392. end;
  1393. end;
  1394. procedure TSourceEditor.AlignCodeCompleteTip;
  1395. var P: TPoint;
  1396. S: string;
  1397. R: TRect;
  1398. begin
  1399. if Assigned(CodeCompleteTip)=false then Exit;
  1400. S:=CodeCompleteTip^.GetText;
  1401. P.Y:=CurPos.Y;
  1402. { determine the center of current word fragment }
  1403. P.X:=CurPos.X-(length(GetCodeCompleteFrag) div 2);
  1404. { calculate position for centering the complete word over/below the current }
  1405. P.X:=P.X-(length(S) div 2);
  1406. P.X:=P.X-Delta.X;
  1407. P.Y:=P.Y-Delta.Y;
  1408. MakeGlobal(P,P);
  1409. if Assigned(CodeCompleteTip^.Owner) then
  1410. CodeCompleteTip^.Owner^.MakeLocal(P,P);
  1411. { ensure that the tooltip stays in screen }
  1412. P.X:=Min(Max(0,P.X),ScreenWidth-length(S)-2-1);
  1413. { align it vertically }
  1414. if P.Y>round(ScreenHeight*3/4) then
  1415. Dec(P.Y)
  1416. else
  1417. Inc(P.Y);
  1418. R.Assign(P.X,P.Y,P.X+1+length(S)+1,P.Y+1);
  1419. CodeCompleteTip^.Locate(R);
  1420. if CodeCompleteTip^.GetState(sfVisible)=false then
  1421. CodeCompleteTip^.Show;
  1422. end;
  1423. procedure TSourceEditor.ModifiedChanged;
  1424. begin
  1425. inherited ModifiedChanged;
  1426. if (@Self<>Clipboard) and GetModified then
  1427. begin
  1428. { global flags }
  1429. EditorModified:=true;
  1430. { reset compile flags as the file is
  1431. not the same as at the compilation anymore }
  1432. CompileStamp:=-1;
  1433. end;
  1434. end;
  1435. procedure TSourceEditor.InsertOptions;
  1436. var C: PUnsortedStringCollection;
  1437. Y: sw_integer;
  1438. S: string;
  1439. begin
  1440. Lock;
  1441. New(C, Init(10,10));
  1442. GetCompilerOptionLines(C);
  1443. if C^.Count>0 then
  1444. begin
  1445. for Y:=0 to C^.Count-1 do
  1446. begin
  1447. S:=C^.At(Y)^;
  1448. InsertLine(Y,S);
  1449. end;
  1450. AdjustSelectionPos(0,0,0,C^.Count);
  1451. UpdateAttrs(0,attrAll);
  1452. DrawLines(0);
  1453. SetModified(true);
  1454. end;
  1455. Dispose(C, Done);
  1456. UnLock;
  1457. end;
  1458. procedure TSourceEditor.PushInfo(Const st : string);
  1459. begin
  1460. PushStatus(st);
  1461. end;
  1462. procedure TSourceEditor.PopInfo;
  1463. begin
  1464. PopStatus;
  1465. end;
  1466. procedure TSourceEditor.DeleteLine(I: sw_integer);
  1467. begin
  1468. inherited DeleteLine(I);
  1469. {$ifndef NODEBUG}
  1470. If ShouldHandleBreakpoints then
  1471. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1472. {$endif NODEBUG}
  1473. end;
  1474. procedure TSourceEditor.BackSpace;
  1475. {$ifndef NODEBUG}
  1476. var
  1477. MoveBreakpointToPreviousLine,WasEnabled : boolean;
  1478. PBStart,PBEnd : PBreakpoint;
  1479. I : longint;
  1480. {$endif NODEBUG}
  1481. begin
  1482. {$ifdef NODEBUG}
  1483. inherited Backspace;
  1484. {$else}
  1485. MoveBreakpointToPreviousLine:=(CurPos.X=0) and (CurPos.Y>0);
  1486. If MoveBreakpointToPreviousLine then
  1487. begin
  1488. ShouldHandleBreakpoints:=false;
  1489. I:=CurPos.Y+1;
  1490. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,I);
  1491. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,I-1);
  1492. end;
  1493. inherited Backspace;
  1494. if MoveBreakpointToPreviousLine then
  1495. begin
  1496. ShouldHandleBreakpoints:=true;
  1497. if assigned(PBEnd) then
  1498. begin
  1499. if assigned(PBStart) then
  1500. begin
  1501. if PBEnd^.state=bs_enabled then
  1502. PBStart^.state:=bs_enabled;
  1503. BreakpointsCollection^.Free(PBEnd);
  1504. end
  1505. else
  1506. begin
  1507. WasEnabled:=PBEnd^.state=bs_enabled;
  1508. if WasEnabled then
  1509. begin
  1510. PBEnd^.state:=bs_disabled;
  1511. PBEnd^.UpdateSource;
  1512. end;
  1513. PBEnd^.line:=I-1;
  1514. if WasEnabled then
  1515. begin
  1516. PBEnd^.state:=bs_enabled;
  1517. PBEnd^.UpdateSource;
  1518. end;
  1519. end;
  1520. end;
  1521. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1522. end;
  1523. {$endif NODEBUG}
  1524. end;
  1525. function TSourceEditor.InsertNewLine : Sw_integer;
  1526. {$ifndef NODEBUG}
  1527. var
  1528. MoveBreakpointToNextLine : boolean;
  1529. I : longint;
  1530. {$endif NODEBUG}
  1531. begin
  1532. {$ifdef NODEBUG}
  1533. InsertNewLine:=inherited InsertNewLine;
  1534. {$else}
  1535. ShouldHandleBreakpoints:=false;
  1536. MoveBreakpointToNextLine:=Cursor.x<Length(RTrim(GetDisplayText(CurPos.Y)));
  1537. I:=CurPos.Y+1;
  1538. InsertNewLine:=inherited InsertNewLine;
  1539. if MoveBreakpointToNextLine then
  1540. BreakpointsCollection^.AdaptBreakpoints(@Self,I-1,1)
  1541. else
  1542. BreakpointsCollection^.AdaptBreakpoints(@Self,I,1);
  1543. ShouldHandleBreakpoints:=true;
  1544. {$endif NODEBUG}
  1545. end;
  1546. procedure TSourceEditor.DelChar;
  1547. var
  1548. S: string;
  1549. I,CI : sw_integer;
  1550. {$ifndef NODEBUG}
  1551. PBStart,PBEnd : PBreakpoint;
  1552. MoveBreakpointOneLineUp,WasEnabled : boolean;
  1553. {$endif NODEBUG}
  1554. begin
  1555. if IsReadOnly then Exit;
  1556. S:=GetLineText(CurPos.Y);
  1557. I:=CurPos.Y+1;
  1558. CI:=LinePosToCharIdx(CurPos.Y,CurPos.X);
  1559. {$ifndef NODEBUG}
  1560. if ((CI>length(S)) or (S='')) and (CurPos.Y<GetLineCount-1) then
  1561. begin
  1562. MoveBreakpointOneLineUp:=true;
  1563. ShouldHandleBreakpoints:=false;
  1564. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,I+1);
  1565. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,I);
  1566. end
  1567. else
  1568. MoveBreakpointOneLineUp:=false;
  1569. {$endif NODEBUG}
  1570. Inherited DelChar;
  1571. {$ifndef NODEBUG}
  1572. if MoveBreakpointOneLineUp then
  1573. begin
  1574. ShouldHandleBreakpoints:=true;
  1575. if assigned(PBEnd) then
  1576. begin
  1577. if assigned(PBStart) then
  1578. begin
  1579. if PBEnd^.state=bs_enabled then
  1580. PBStart^.state:=bs_enabled;
  1581. BreakpointsCollection^.Free(PBEnd);
  1582. end
  1583. else
  1584. begin
  1585. WasEnabled:=PBEnd^.state=bs_enabled;
  1586. if WasEnabled then
  1587. begin
  1588. PBEnd^.state:=bs_disabled;
  1589. PBEnd^.UpdateSource;
  1590. end;
  1591. PBEnd^.line:=I;
  1592. if WasEnabled then
  1593. begin
  1594. PBEnd^.state:=bs_enabled;
  1595. PBEnd^.UpdateSource;
  1596. end;
  1597. end;
  1598. end;
  1599. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-1);
  1600. end;
  1601. {$endif NODEBUG}
  1602. end;
  1603. procedure TSourceEditor.DelSelect;
  1604. {$ifndef NODEBUG}
  1605. var
  1606. MoveBreakpointToFirstLine,WasEnabled : boolean;
  1607. PBStart,PBEnd : PBreakpoint;
  1608. I,J : longint;
  1609. {$endif NODEBUG}
  1610. begin
  1611. {$ifdef NODEBUG}
  1612. inherited DelSelect;
  1613. {$else}
  1614. ShouldHandleBreakpoints:=false;
  1615. J:=SelEnd.Y-SelStart.Y;
  1616. MoveBreakpointToFirstLine:=J>0;
  1617. PBEnd:=BreakpointsCollection^.FindBreakpointAt(@Self,SelEnd.Y);
  1618. PBStart:=BreakpointsCollection^.FindBreakpointAt(@Self,SelEnd.Y);
  1619. I:=SelStart.Y;
  1620. inherited DelSelect;
  1621. if MoveBreakpointToFirstLine and assigned(PBEnd) then
  1622. begin
  1623. If assigned(PBStart) then
  1624. begin
  1625. if PBEnd^.state=bs_enabled then
  1626. PBStart^.state:=bs_enabled;
  1627. BreakpointsCollection^.Free(PBEnd);
  1628. end
  1629. else
  1630. begin
  1631. WasEnabled:=PBEnd^.state=bs_enabled;
  1632. if WasEnabled then
  1633. begin
  1634. PBEnd^.state:=bs_disabled;
  1635. PBEnd^.UpdateSource;
  1636. end;
  1637. PBEnd^.line:=I;
  1638. if WasEnabled then
  1639. begin
  1640. PBEnd^.state:=bs_enabled;
  1641. PBEnd^.UpdateSource;
  1642. end;
  1643. end;
  1644. end;
  1645. BreakpointsCollection^.AdaptBreakpoints(@Self,I,-J);
  1646. ShouldHandleBreakpoints:=true;
  1647. {$endif NODEBUG}
  1648. end;
  1649. function TSourceEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  1650. begin
  1651. InsertLine := inherited InsertLine(LineNo,S);
  1652. {$ifndef NODEBUG}
  1653. If ShouldHandleBreakpoints then
  1654. BreakpointsCollection^.AdaptBreakpoints(@Self,LineNo,1);
  1655. {$endif NODEBUG}
  1656. end;
  1657. procedure TSourceEditor.AddLine(const S: string);
  1658. begin
  1659. inherited AddLine(S);
  1660. {$ifndef NODEBUG}
  1661. BreakpointsCollection^.AdaptBreakpoints(@Self,GetLineCount,1);
  1662. {$endif NODEBUG}
  1663. end;
  1664. function TSourceEditor.GetLocalMenu: PMenu;
  1665. var M: PMenu;
  1666. MI: PMenuItem;
  1667. begin
  1668. MI:=
  1669. NewItem(menu_edit_cut,menu_key_edit_cut,cut_key,cmCut,hcCut,
  1670. NewItem(menu_edit_copy,menu_key_edit_copy,copy_key,cmCopy,hcCopy,
  1671. NewItem(menu_edit_paste,menu_key_edit_paste,paste_key,cmPaste,hcPaste,
  1672. NewItem(menu_edit_clear,menu_key_edit_clear,kbCtrlDel,cmClear,hcClear,
  1673. NewLine(
  1674. NewItem(menu_srclocal_openfileatcursor,'',kbNoKey,cmOpenAtCursor,hcOpenAtCursor,
  1675. NewItem(menu_srclocal_browseatcursor,'',kbNoKey,cmBrowseAtCursor,hcBrowseAtCursor,
  1676. NewItem(menu_srclocal_topicsearch,menu_key_help_topicsearch,kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  1677. NewLine(
  1678. NewItem(menu_srclocal_options,'',kbNoKey,cmEditorOptions,hcEditorOptions,
  1679. nil))))))))));
  1680. if IsChangedOnDisk then
  1681. MI:=NewItem(menu_srclocal_reload,'',kbNoKey,cmDoReload,hcDoReload,
  1682. MI);
  1683. M:=NewMenu(MI);
  1684. GetLocalMenu:=M;
  1685. end;
  1686. function TSourceEditor.GetCommandTarget: PView;
  1687. begin
  1688. GetCommandTarget:=@Self;
  1689. end;
  1690. function TSourceEditor.CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup;
  1691. var MV: PAdvancedMenuPopup;
  1692. begin
  1693. New(MV, Init(Bounds,M));
  1694. CreateLocalMenuView:=MV;
  1695. end;
  1696. {$ifdef DebugUndo}
  1697. procedure TSourceEditor.DumpUndo;
  1698. var
  1699. i : sw_integer;
  1700. begin
  1701. ClearToolMessages;
  1702. AddToolCommand('UndoList Dump');
  1703. for i:=0 to Core^.UndoList^.count-1 do
  1704. with Core^.UndoList^.At(i)^ do
  1705. begin
  1706. if is_grouped_action then
  1707. AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
  1708. else
  1709. AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
  1710. ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
  1711. end;
  1712. if Core^.RedoList^.count>0 then
  1713. AddToolCommand('RedoList Dump');
  1714. for i:=0 to Core^.RedoList^.count-1 do
  1715. with Core^.RedoList^.At(i)^ do
  1716. begin
  1717. if is_grouped_action then
  1718. AddToolMessage('','Group '+ActionString[action]+' '+IntToStr(ActionCount)+' elementary actions',0,0)
  1719. else
  1720. AddToolMessage('',ActionString[action]+' '+IntToStr(StartPos.Y+1)+':'+IntToStr(StartPos.X+1)+
  1721. ' '+IntToStr(EndPos.Y+1)+':'+IntToStr(EndPos.X+1)+' "'+GetStr(Text)+'"',0,0);
  1722. end;
  1723. UpdateToolMessages;
  1724. if Assigned(MessagesWindow) then
  1725. MessagesWindow^.Focus;
  1726. end;
  1727. procedure TSourceEditor.UndoAll;
  1728. begin
  1729. While Core^.UndoList^.count>0 do
  1730. Undo;
  1731. end;
  1732. procedure TSourceEditor.RedoAll;
  1733. begin
  1734. While Core^.RedoList^.count>0 do
  1735. Redo;
  1736. end;
  1737. {$endif DebugUndo}
  1738. function TSourceEditor.Valid(Command: Word): Boolean;
  1739. var OK: boolean;
  1740. begin
  1741. OK:=inherited Valid(Command);
  1742. if OK and ({(Command=cmClose) or already handled in TFileEditor.Valid PM }
  1743. (Command=cmAskSaveAll)) then
  1744. if IsClipboard=false then
  1745. OK:=SaveAsk(Command,false);
  1746. Valid:=OK;
  1747. end;
  1748. procedure TSourceEditor.HandleEvent(var Event: TEvent);
  1749. var DontClear: boolean;
  1750. S: string;
  1751. begin
  1752. TranslateMouseClick(@Self,Event);
  1753. case Event.What of
  1754. evKeyDown :
  1755. begin
  1756. DontClear:=false;
  1757. case Event.KeyCode of
  1758. kbCtrlEnter :
  1759. Message(@Self,evCommand,cmOpenAtCursor,nil);
  1760. else DontClear:=true;
  1761. end;
  1762. if not DontClear then ClearEvent(Event);
  1763. end;
  1764. end;
  1765. inherited HandleEvent(Event);
  1766. case Event.What of
  1767. evBroadcast :
  1768. case Event.Command of
  1769. cmCalculatorPaste :
  1770. begin
  1771. InsertText(FloatToStr(CalcClipboard,0));
  1772. ClearEvent(Event);
  1773. end;
  1774. end;
  1775. evCommand :
  1776. begin
  1777. DontClear:=false;
  1778. case Event.Command of
  1779. {$ifdef DebugUndo}
  1780. cmDumpUndo : DumpUndo;
  1781. cmUndoAll : UndoAll;
  1782. cmRedoAll : RedoAll;
  1783. {$endif DebugUndo}
  1784. cmDoReload : ReloadFile;
  1785. cmBrowseAtCursor:
  1786. begin
  1787. S:=LowerCaseStr(GetEditorCurWord(@Self,[]));
  1788. OpenOneSymbolBrowser(S);
  1789. end;
  1790. cmOpenAtCursor :
  1791. begin
  1792. S:=LowerCaseStr(GetEditorCurWord(@Self,['.']));
  1793. if Pos('.',S)<>0 then
  1794. OpenFileName:=S else
  1795. OpenFileName:=S+'.pp'+ListSeparator+
  1796. S+'.pas'+ListSeparator+
  1797. S+'.inc';
  1798. Message(Application,evCommand,cmOpen,nil);
  1799. end;
  1800. cmEditorOptions :
  1801. Message(Application,evCommand,cmEditorOptions,@Self);
  1802. cmHelp :
  1803. Message(@Self,evCommand,cmHelpTopicSearch,@Self);
  1804. cmHelpTopicSearch :
  1805. HelpTopicSearch(@Self);
  1806. else DontClear:=true;
  1807. end;
  1808. if not DontClear then ClearEvent(Event);
  1809. end;
  1810. end;
  1811. end;
  1812. constructor TFPHeapView.Init(var Bounds: TRect);
  1813. begin
  1814. if inherited Init(Bounds)=false then Fail;
  1815. Options:=Options or gfGrowHiX or gfGrowHiY;
  1816. EventMask:=EventMask or evIdle;
  1817. GrowMode:=gfGrowAll;
  1818. end;
  1819. constructor TFPHeapView.InitKb(var Bounds: TRect);
  1820. begin
  1821. if inherited InitKb(Bounds)=false then Fail;
  1822. Options:=Options or gfGrowHiX or gfGrowHiY;
  1823. EventMask:=EventMask or evIdle;
  1824. GrowMode:=gfGrowAll;
  1825. end;
  1826. procedure TFPHeapView.HandleEvent(var Event: TEvent);
  1827. begin
  1828. case Event.What of
  1829. evIdle :
  1830. Update;
  1831. end;
  1832. inherited HandleEvent(Event);
  1833. end;
  1834. constructor TFPClockView.Init(var Bounds: TRect);
  1835. begin
  1836. inherited Init(Bounds);
  1837. EventMask:=EventMask or evIdle;
  1838. end;
  1839. procedure TFPClockView.HandleEvent(var Event: TEvent);
  1840. begin
  1841. case Event.What of
  1842. evIdle :
  1843. Update;
  1844. end;
  1845. inherited HandleEvent(Event);
  1846. end;
  1847. function TFPClockView.GetPalette: PPalette;
  1848. const P: string[length(CFPClockView)] = CFPClockView;
  1849. begin
  1850. GetPalette:=@P;
  1851. end;
  1852. procedure TFPWindow.SetState(AState: Word; Enable: Boolean);
  1853. var OldState: word;
  1854. begin
  1855. OldState:=State;
  1856. inherited SetState(AState,Enable);
  1857. if AutoNumber then
  1858. if (AState and (sfVisible+sfExposed))<>0 then
  1859. if GetState(sfVisible+sfExposed) then
  1860. begin
  1861. if Number=0 then
  1862. Number:=SearchFreeWindowNo;
  1863. ReDraw;
  1864. end
  1865. else
  1866. Number:=0;
  1867. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  1868. UpdateCommands;
  1869. end;
  1870. procedure TFPWindow.UpdateCommands;
  1871. begin
  1872. end;
  1873. procedure TFPWindow.Update;
  1874. begin
  1875. ReDraw;
  1876. end;
  1877. procedure TFPWindow.SelectInDebugSession;
  1878. var
  1879. F,PrevCurrent : PView;
  1880. begin
  1881. DeskTop^.Lock;
  1882. PrevCurrent:=Desktop^.Current;
  1883. F:=PrevCurrent;
  1884. While assigned(F) and
  1885. ((F^.HelpCtx = hcGDBWindow) or
  1886. (F^.HelpCtx = hcdisassemblyWindow) or
  1887. (F^.HelpCtx = hcWatchesWindow) or
  1888. (F^.HelpCtx = hcStackWindow) or
  1889. (F^.HelpCtx = hcRegistersWindow) or
  1890. (F^.HelpCtx = hcVectorRegisters) or
  1891. (F^.HelpCtx = hcFPURegisters)) do
  1892. F:=F^.NextView;
  1893. if F<>@Self then
  1894. Select;
  1895. if PrevCurrent<>F then
  1896. Begin
  1897. Desktop^.InsertBefore(@self,F);
  1898. PrevCurrent^.Select;
  1899. End;
  1900. DeskTop^.Unlock;
  1901. end;
  1902. procedure TFPWindow.HandleEvent(var Event: TEvent);
  1903. begin
  1904. case Event.What of
  1905. evBroadcast :
  1906. case Event.Command of
  1907. cmUpdate :
  1908. Update;
  1909. cmSearchWindow+1..cmSearchWindow+99 :
  1910. if (Event.Command-cmSearchWindow=Number) then
  1911. ClearEvent(Event);
  1912. end;
  1913. end;
  1914. inherited HandleEvent(Event);
  1915. end;
  1916. constructor TFPWindow.Load(var S: TStream);
  1917. begin
  1918. inherited Load(S);
  1919. S.Read(AutoNumber,SizeOf(AutoNumber));
  1920. end;
  1921. procedure TFPWindow.Store(var S: TStream);
  1922. begin
  1923. inherited Store(S);
  1924. S.Write(AutoNumber,SizeOf(AutoNumber));
  1925. end;
  1926. function TFPHelpViewer.GetLocalMenu: PMenu;
  1927. var M: PMenu;
  1928. begin
  1929. M:=NewMenu(
  1930. {$ifdef DEBUG}
  1931. NewItem(menu_hlplocal_debug,'',kbNoKey,cmHelpDebug,hcHelpDebug,
  1932. {$endif DEBUG}
  1933. NewItem(menu_hlplocal_contents,'',kbNoKey,cmHelpContents,hcHelpContents,
  1934. NewItem(menu_hlplocal_index,menu_key_hlplocal_index,kbShiftF1,cmHelpIndex,hcHelpIndex,
  1935. NewItem(menu_hlplocal_topicsearch,menu_key_hlplocal_topicsearch,kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  1936. NewItem(menu_hlplocal_prevtopic,menu_key_hlplocal_prevtopic,kbAltF1,cmHelpPrevTopic,hcHelpPrevTopic,
  1937. NewLine(
  1938. NewItem(menu_hlplocal_copy,menu_key_hlplocal_copy,copy_key,cmCopy,hcCopy,
  1939. nil)))))))
  1940. {$ifdef DEBUG}
  1941. )
  1942. {$endif DEBUG}
  1943. ;
  1944. GetLocalMenu:=M;
  1945. end;
  1946. function TFPHelpViewer.GetCommandTarget: PView;
  1947. begin
  1948. GetCommandTarget:=Application;
  1949. end;
  1950. constructor TFPHelpWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word;
  1951. AContext: THelpCtx; ANumber: Integer);
  1952. begin
  1953. inherited Init(Bounds,ATitle,ASourceFileID,AContext,ANumber);
  1954. HelpCtx:=hcHelpWindow;
  1955. HideOnClose:=true;
  1956. end;
  1957. destructor TFPHelpWindow.Done;
  1958. begin
  1959. if HelpWindow=@Self then
  1960. HelpWindow:=nil;
  1961. Inherited Done;
  1962. end;
  1963. procedure TFPHelpWindow.InitHelpView;
  1964. var R: TRect;
  1965. begin
  1966. GetExtent(R); R.Grow(-1,-1);
  1967. HelpView:=New(PFPHelpViewer, Init(R, HSB, VSB));
  1968. HelpView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1969. end;
  1970. procedure TFPHelpWindow.Show;
  1971. begin
  1972. inherited Show;
  1973. if GetState(sfVisible) and (Number=0) then
  1974. begin
  1975. Number:=SearchFreeWindowNo;
  1976. ReDraw;
  1977. end;
  1978. end;
  1979. procedure TFPHelpWindow.Hide;
  1980. begin
  1981. inherited Hide;
  1982. if GetState(sfVisible)=false then
  1983. Number:=0;
  1984. end;
  1985. procedure TFPHelpWindow.HandleEvent(var Event: TEvent);
  1986. begin
  1987. case Event.What of
  1988. evBroadcast :
  1989. case Event.Command of
  1990. cmUpdate :
  1991. ReDraw;
  1992. cmSearchWindow+1..cmSearchWindow+99 :
  1993. if (Event.Command-cmSearchWindow=Number) then
  1994. ClearEvent(Event);
  1995. end;
  1996. end;
  1997. inherited HandleEvent(Event);
  1998. end;
  1999. function TFPHelpWindow.GetPalette: PPalette;
  2000. const P: string[length(CIDEHelpDialog)] = CIDEHelpDialog;
  2001. begin
  2002. GetPalette:=@P;
  2003. end;
  2004. constructor TFPHelpWindow.Load(var S: TStream);
  2005. begin
  2006. Abstract;
  2007. end;
  2008. procedure TFPHelpWindow.Store(var S: TStream);
  2009. begin
  2010. Abstract;
  2011. end;
  2012. constructor TSourceWindow.Init(var Bounds: TRect; AFileName: string);
  2013. var HSB,VSB: PScrollBar;
  2014. R: TRect;
  2015. PA : Array[1..2] of pointer;
  2016. LoadFile: boolean;
  2017. begin
  2018. inherited Init(Bounds,AFileName,{SearchFreeWindowNo}0);
  2019. AutoNumber:=true;
  2020. Options:=Options or ofTileAble;
  2021. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2022. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2023. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2024. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2025. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2026. New(Indicator, Init(R));
  2027. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2028. Insert(Indicator);
  2029. GetExtent(R); R.Grow(-1,-1);
  2030. LoadFile:=(AFileName<>'') and (AFileName<>'*');
  2031. if (AFileName='') then
  2032. begin
  2033. Inc(GlobalNoNameCount);
  2034. NoNameCount:=GlobalNoNameCount;
  2035. end
  2036. else
  2037. NoNameCount:=-1;
  2038. if AFileName='*' then
  2039. AFileName:='';
  2040. New(Editor, Init(R, HSB, VSB, Indicator,AFileName));
  2041. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2042. {load from file if there is no other window with the same file }
  2043. if Editor^.Core^.GetBindingCount = 1 then
  2044. if LoadFile then
  2045. begin
  2046. if Editor^.LoadFile=false then
  2047. ErrorBox(FormatStrStr(msg_errorreadingfile,AFileName),nil)
  2048. { warn if modified, but not if modified in another
  2049. already open window PM }
  2050. else if Editor^.GetModified and (Editor^.Core^.GetBindingCount=1) then
  2051. begin
  2052. PA[1]:=@AFileName;
  2053. Ptrint(PA[2]):={Editor^.ChangedLine}-1;
  2054. EditorDialog(edChangedOnloading,@PA);
  2055. end;
  2056. end;
  2057. Insert(Editor);
  2058. {$ifndef NODEBUG}
  2059. If assigned(BreakpointsCollection) then
  2060. BreakpointsCollection^.ShowBreakpoints(@Self);
  2061. {$endif NODEBUG}
  2062. UpdateTitle;
  2063. end;
  2064. procedure TSourceWindow.UpdateTitle;
  2065. var Name: string;
  2066. Count: sw_integer;
  2067. begin
  2068. if Editor^.FileName<>'' then
  2069. begin
  2070. Name:=SmartPath(Editor^.FileName);
  2071. Count:=Editor^.Core^.GetBindingCount;
  2072. if Count>1 then
  2073. begin
  2074. Name:=Name+':'+IntToStr(Editor^.Core^.GetBindingIndex(Editor)+1);
  2075. end;
  2076. SetTitle(Name);
  2077. end
  2078. else if NoNameCount>=0 then
  2079. begin
  2080. SetTitle('noname'+IntToStrZ(NonameCount,2)+'.pas');
  2081. end;
  2082. end;
  2083. function TSourceWindow.GetTitle(MaxSize: sw_Integer): TTitleStr;
  2084. begin
  2085. GetTitle:=OptimizePath(inherited GetTitle(255),MaxSize);
  2086. end;
  2087. procedure TSourceWindow.SetTitle(ATitle: string);
  2088. begin
  2089. if Title<>nil then DisposeStr(Title);
  2090. Title:=NewStr(ATitle);
  2091. Frame^.DrawView;
  2092. end;
  2093. procedure TSourceWindow.HandleEvent(var Event: TEvent);
  2094. var DontClear: boolean;
  2095. begin
  2096. case Event.What of
  2097. evBroadcast :
  2098. case Event.Command of
  2099. cmUpdate :
  2100. Update;
  2101. cmUpdateTitle :
  2102. UpdateTitle;
  2103. cmSearchWindow :
  2104. if @Self<>ClipboardWindow then
  2105. ClearEvent(Event);
  2106. end;
  2107. evCommand :
  2108. begin
  2109. DontClear:=false;
  2110. case Event.Command of
  2111. cmHide :
  2112. Hide;
  2113. cmSave :
  2114. if Editor^.IsClipboard=false then
  2115. if (Editor^.FileName='') then
  2116. Editor^.SaveAs
  2117. else
  2118. Editor^.Save;
  2119. cmSaveAs :
  2120. if Editor^.IsClipboard=false then
  2121. Editor^.SaveAs;
  2122. else DontClear:=true;
  2123. end;
  2124. if DontClear=false then ClearEvent(Event);
  2125. end;
  2126. end;
  2127. inherited HandleEvent(Event);
  2128. end;
  2129. procedure TSourceWindow.UpdateCommands;
  2130. var Active: boolean;
  2131. begin
  2132. Active:=GetState(sfActive);
  2133. if Editor^.IsClipboard=false then
  2134. begin
  2135. SetCmdState(SourceCmds+CompileCmds,Active);
  2136. SetCmdState(EditorCmds,Active);
  2137. end;
  2138. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd+[cmHide],Active);
  2139. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2140. end;
  2141. procedure TSourceWindow.Update;
  2142. begin
  2143. ReDraw;
  2144. end;
  2145. function TSourceWindow.GetPalette: PPalette;
  2146. const P: string[length(CSourceWindow)] = CSourceWindow;
  2147. begin
  2148. GetPalette:=@P;
  2149. end;
  2150. constructor TSourceWindow.Load(var S: TStream);
  2151. begin
  2152. Title:=S.ReadStr;
  2153. PushStatus(FormatStrStr(msg_loadingfile,GetStr(Title)));
  2154. inherited Load(S);
  2155. GetSubViewPtr(S,Indicator);
  2156. GetSubViewPtr(S,Editor);
  2157. {$ifndef NODEBUG}
  2158. If assigned(BreakpointsCollection) then
  2159. BreakpointsCollection^.ShowBreakpoints(@Self);
  2160. {$endif NODEBUG}
  2161. PopStatus;
  2162. end;
  2163. procedure TSourceWindow.Store(var S: TStream);
  2164. begin
  2165. S.WriteStr(Title);
  2166. PushStatus(FormatStrStr(msg_storingfile,GetStr(Title)));
  2167. inherited Store(S);
  2168. PutSubViewPtr(S,Indicator);
  2169. PutSubViewPtr(S,Editor);
  2170. PopStatus;
  2171. end;
  2172. procedure TSourceWindow.Show;
  2173. begin
  2174. inherited Show;
  2175. IDEApp.SetCmdState([cmTile,cmCascade],true);
  2176. end;
  2177. procedure TSourceWindow.Hide;
  2178. begin
  2179. inherited Hide;
  2180. IDEApp.SetCmdState([cmTile,cmCascade],IsThereAnyVisibleEditorWindow);
  2181. end;
  2182. procedure TSourceWindow.Close;
  2183. begin
  2184. inherited Close;
  2185. end;
  2186. destructor TSourceWindow.Done;
  2187. begin
  2188. PushStatus(FormatStrStr(msg_closingfile,GetStr(Title)));
  2189. if not IDEApp.IsClosing then
  2190. Message(Application,evBroadcast,cmSourceWndClosing,@Self);
  2191. inherited Done;
  2192. IDEApp.SourceWindowClosed;
  2193. { if not IDEApp.IsClosing then
  2194. Message(Application,evBroadcast,cmUpdate,@Self);}
  2195. PopStatus;
  2196. end;
  2197. {$ifndef NODEBUG}
  2198. function TGDBSourceEditor.Valid(Command: Word): Boolean;
  2199. var OK: boolean;
  2200. begin
  2201. OK:=TCodeEditor.Valid(Command);
  2202. { do NOT ask for save !!
  2203. if OK and ((Command=cmClose) or (Command=cmQuit)) then
  2204. if IsClipboard=false then
  2205. OK:=SaveAsk; }
  2206. Valid:=OK;
  2207. end;
  2208. procedure TGDBSourceEditor.AddLine(const S: string);
  2209. begin
  2210. if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
  2211. inherited AddLine(S);
  2212. LimitsChanged;
  2213. end;
  2214. procedure TGDBSourceEditor.AddErrorLine(const S: string);
  2215. begin
  2216. if Silent then exit;
  2217. inherited AddLine(S);
  2218. { display like breakpoints in red }
  2219. SetLineFlagState(GetLineCount-1,lfBreakpoint,true);
  2220. LimitsChanged;
  2221. end;
  2222. const
  2223. GDBReservedCount = 6;
  2224. GDBReservedLongest = 3;
  2225. GDBReserved : array[1..GDBReservedCount] of String[GDBReservedLongest] =
  2226. ('gdb','b','n','s','f','bt');
  2227. function IsGDBReservedWord(const S : string) : boolean;
  2228. var
  2229. i : longint;
  2230. begin
  2231. for i:=1 to GDBReservedCount do
  2232. if (S=GDBReserved[i]) then
  2233. begin
  2234. IsGDBReservedWord:=true;
  2235. exit;
  2236. end;
  2237. IsGDBReservedWord:=false;
  2238. end;
  2239. function TGDBSourceEditor.IsReservedWord(const S: string): boolean;
  2240. begin
  2241. IsReservedWord:=IsGDBReservedWord(S);
  2242. end;
  2243. function TGDBSourceEditor.InsertNewLine: Sw_integer;
  2244. Var
  2245. S : string;
  2246. CommandCalled : boolean;
  2247. begin
  2248. if IsReadOnly then begin InsertNewLine:=-1; Exit; end;
  2249. if CurPos.Y<GetLineCount then S:=GetDisplayText(CurPos.Y) else S:='';
  2250. s:=Copy(S,1,CurPos.X);
  2251. CommandCalled:=false;
  2252. if Pos(GDBPrompt,S)=1 then
  2253. Delete(S,1,length(GDBPrompt));
  2254. {$ifndef NODEBUG}
  2255. if assigned(Debugger) then
  2256. if S<>'' then
  2257. begin
  2258. LastCommand:=S;
  2259. { should be true only if we are at the end ! }
  2260. IgnoreStringAtEnd:=(CurPos.Y=GetLineCount-1) and
  2261. (CurPos.X>=length(RTrim(GetDisplayText(GetLineCount-1))));
  2262. Debugger^.Command(S);
  2263. CommandCalled:=true;
  2264. IgnoreStringAtEnd:=false;
  2265. end
  2266. else if AutoRepeat and (CurPos.Y=GetLineCount-1) then
  2267. begin
  2268. Debugger^.Command(LastCommand);
  2269. CommandCalled:=true;
  2270. end;
  2271. {$endif NODEBUG}
  2272. InsertNewLine:=inherited InsertNewLine;
  2273. If CommandCalled then
  2274. InsertText(GDBPrompt);
  2275. end;
  2276. constructor TGDBWindow.Init(var Bounds: TRect);
  2277. var HSB,VSB: PScrollBar;
  2278. R: TRect;
  2279. begin
  2280. inherited Init(Bounds,dialog_gdbwindow,0);
  2281. Options:=Options or ofTileAble;
  2282. AutoNumber:=true;
  2283. HelpCtx:=hcGDBWindow;
  2284. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2285. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2286. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2287. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2288. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2289. New(Indicator, Init(R));
  2290. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2291. Insert(Indicator);
  2292. GetExtent(R); R.Grow(-1,-1);
  2293. New(Editor, Init(R, HSB, VSB, Indicator, GDBOutputFile));
  2294. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2295. Editor^.SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs);
  2296. if ExistsFile(GDBOutputFile) then
  2297. begin
  2298. if Editor^.LoadFile=false then
  2299. ErrorBox(FormatStrStr(msg_errorreadingfile,GDBOutputFile),nil);
  2300. end
  2301. else
  2302. { Empty files are buggy !! }
  2303. Editor^.AddLine('');
  2304. Insert(Editor);
  2305. {$ifndef NODEBUG}
  2306. {$ifndef GDBMI}
  2307. if assigned(Debugger) then
  2308. Debugger^.SetCommand('width ' + IntToStr(Size.X-1));
  2309. {$endif GDBMI}
  2310. {$endif NODEBUG}
  2311. Editor^.silent:=false;
  2312. Editor^.AutoRepeat:=true;
  2313. Editor^.InsertText(GDBPrompt);
  2314. end;
  2315. procedure TGDBWindow.HandleEvent(var Event: TEvent);
  2316. var DontClear: boolean;
  2317. begin
  2318. case Event.What of
  2319. evCommand :
  2320. begin
  2321. DontClear:=false;
  2322. case Event.Command of
  2323. cmSaveAs :
  2324. Editor^.SaveAs;
  2325. else DontClear:=true;
  2326. end;
  2327. if DontClear=false then ClearEvent(Event);
  2328. end;
  2329. end;
  2330. inherited HandleEvent(Event);
  2331. end;
  2332. destructor TGDBWindow.Done;
  2333. begin
  2334. if @Self=GDBWindow then
  2335. GDBWindow:=nil;
  2336. inherited Done;
  2337. end;
  2338. constructor TGDBWindow.Load(var S: TStream);
  2339. begin
  2340. inherited Load(S);
  2341. GetSubViewPtr(S,Indicator);
  2342. GetSubViewPtr(S,Editor);
  2343. GDBWindow:=@self;
  2344. end;
  2345. procedure TGDBWindow.Store(var S: TStream);
  2346. begin
  2347. inherited Store(S);
  2348. PutSubViewPtr(S,Indicator);
  2349. PutSubViewPtr(S,Editor);
  2350. end;
  2351. function TGDBWindow.GetPalette: PPalette;
  2352. const P: string[length(CSourceWindow)] = CSourceWindow;
  2353. begin
  2354. GetPalette:=@P;
  2355. end;
  2356. procedure TGDBWindow.WriteOutputText(Buf : PAnsiChar);
  2357. begin
  2358. {selected normal color ?}
  2359. WriteText(Buf,false);
  2360. end;
  2361. procedure TGDBWindow.WriteErrorText(Buf : PAnsiChar);
  2362. begin
  2363. {selected normal color ?}
  2364. WriteText(Buf,true);
  2365. end;
  2366. procedure TGDBWindow.WriteString(Const S : string);
  2367. begin
  2368. Editor^.AddLine(S);
  2369. end;
  2370. procedure TGDBWindow.WriteErrorString(Const S : string);
  2371. begin
  2372. Editor^.AddErrorLine(S);
  2373. end;
  2374. procedure TGDBWindow.WriteText(Buf : PAnsiChar;IsError : boolean);
  2375. var p,pe : PAnsiChar;
  2376. s : string;
  2377. begin
  2378. p:=buf;
  2379. DeskTop^.Lock;
  2380. While assigned(p) and (p^<>#0) do
  2381. begin
  2382. pe:=strscan(p,#10);
  2383. { if pe-p is more than High(s), discard for this round }
  2384. if (pe<>nil) and (pe-p > high(s)) then
  2385. pe:=nil;
  2386. if (pe<>nil) then
  2387. pe^:=#0;
  2388. s:=strpas(p);
  2389. If IsError then
  2390. Editor^.AddErrorLine(S)
  2391. else
  2392. Editor^.AddLine(S);
  2393. { restore for dispose }
  2394. if pe<>nil then
  2395. pe^:=#10;
  2396. if pe=nil then
  2397. begin
  2398. if strlen(p)<High(s) then
  2399. p:=nil
  2400. else
  2401. p:=p+High(s);
  2402. end
  2403. else
  2404. begin
  2405. p:=pe;
  2406. inc(p);
  2407. end;
  2408. end;
  2409. DeskTop^.Unlock;
  2410. Editor^.Draw;
  2411. end;
  2412. procedure TGDBWindow.UpdateCommands;
  2413. var Active: boolean;
  2414. begin
  2415. Active:=GetState(sfActive);
  2416. SetCmdState([cmSaveAs,cmHide,cmRun],Active);
  2417. SetCmdState(EditorCmds,Active);
  2418. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,Active);
  2419. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2420. end;
  2421. function TDisasLineCollection.At(Index: sw_Integer): PDisasLine;
  2422. begin
  2423. At := PDisasLine(Inherited At(Index));
  2424. end;
  2425. constructor TDisassemblyEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  2426. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  2427. begin
  2428. Inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,AFileName);
  2429. GrowMode:=gfGrowHiX+gfGrowHiY;
  2430. SetFlags(efInsertMode+efSyntaxHighlight+efNoIndent+efExpandAllTabs{+efHighlightRow});
  2431. New(DisasLines,Init(500,1000));
  2432. Core^.ChangeLinesTo(DisasLines);
  2433. { do not allow to write into that window }
  2434. ReadOnly:=true;
  2435. AddLine('');
  2436. MinAddress:=0;
  2437. MaxAddress:=0;
  2438. CurL:=nil;
  2439. OwnsSource:=false;
  2440. Source:=nil;
  2441. end;
  2442. destructor TDisassemblyEditor.Done;
  2443. begin
  2444. ReleaseSource;
  2445. Inherited Done;
  2446. end;
  2447. procedure TDisassemblyEditor.ReleaseSource;
  2448. begin
  2449. if OwnsSource and assigned(source) then
  2450. begin
  2451. Desktop^.Delete(Source);
  2452. Dispose(Source,Done);
  2453. end;
  2454. OwnsSource:=false;
  2455. Source:=nil;
  2456. CurrentSource:='';
  2457. end;
  2458. procedure TDisassemblyEditor.AddSourceLine(const AFileName: string;line : longint);
  2459. var
  2460. S : String;
  2461. begin
  2462. if AFileName<>CurrentSource then
  2463. begin
  2464. ReleaseSource;
  2465. Source:=SearchOnDesktop(FileName,false);
  2466. if not assigned(Source) then
  2467. begin
  2468. Source:=ITryToOpenFile(nil,AFileName,0,line,false,false,true);
  2469. OwnsSource:=true;
  2470. end
  2471. else
  2472. OwnsSource:=false;
  2473. CurrentSource:=AFileName;
  2474. end;
  2475. if Assigned(Source) and (line>0) then
  2476. S:=Trim(Source^.Editor^.GetLineText(line-1))
  2477. else
  2478. S:='<source not found>';
  2479. CurrentLine:=Line;
  2480. inherited AddLine(AFileName+':'+IntToStr(line)+' '+S);
  2481. { display differently }
  2482. SetLineFlagState(GetLineCount-1,lfSpecialRow,true);
  2483. LimitsChanged;
  2484. end;
  2485. procedure TDisassemblyEditor.AddAssemblyLine(const S: string;AAddress : CORE_ADDR);
  2486. var
  2487. PL : PDisasLine;
  2488. LI : PEditorLineInfo;
  2489. begin
  2490. if AAddress<>0 then
  2491. inherited AddLine('$'+hexstr(AAddress,sizeof(CORE_ADDR)*2)+S)
  2492. else
  2493. inherited AddLine(S);
  2494. PL:=DisasLines^.At(DisasLines^.count-1);
  2495. PL^.Address:=AAddress;
  2496. LI:=PL^.GetEditorInfo(@Self);
  2497. if AAddress<>0 then
  2498. LI^.BeginsWithAsm:=true;
  2499. LimitsChanged;
  2500. if ((AAddress<minaddress) or (minaddress=0)) and (AAddress<>0) then
  2501. MinAddress:=AAddress;
  2502. if (AAddress>maxaddress) or (maxaddress=0) then
  2503. MaxAddress:=AAddress;
  2504. end;
  2505. function TDisassemblyEditor.GetCurrentLine(address : CORE_ADDR) : PDisasLine;
  2506. function IsCorrectLine(PL : PDisasLine) : boolean;
  2507. begin
  2508. IsCorrectLine:=PL^.Address=Address;
  2509. end;
  2510. Var
  2511. PL : PDisasLine;
  2512. begin
  2513. PL:=DisasLines^.FirstThat(TCallbackFunBoolParam(@IsCorrectLine));
  2514. if Assigned(PL) then
  2515. begin
  2516. if assigned(CurL) then
  2517. CurL^.SetFlagState(lfDebuggerRow,false);
  2518. SetCurPtr(0,DisasLines^.IndexOf(PL));
  2519. PL^.SetFlags(lfDebuggerRow);
  2520. CurL:=PL;
  2521. TrackCursor(do_not_centre);
  2522. end;
  2523. GetCurrentLine:=PL;
  2524. end;
  2525. { PDisassemblyWindow = ^TDisassemblyWindow;
  2526. TDisassemblyWindow = object(TFPWindow)
  2527. Editor : PDisassemblyEditor;
  2528. Indicator : PIndicator; }
  2529. constructor TDisassemblyWindow.Init(var Bounds: TRect);
  2530. var HSB,VSB: PScrollBar;
  2531. R: TRect;
  2532. begin
  2533. inherited Init(Bounds,dialog_disaswindow,0);
  2534. Options:=Options or ofTileAble;
  2535. AutoNumber:=true;
  2536. HelpCtx:=hcDisassemblyWindow;
  2537. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2538. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2539. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2540. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2541. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2542. New(Indicator, Init(R));
  2543. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2544. Insert(Indicator);
  2545. GetExtent(R); R.Grow(-1,-1);
  2546. New(Editor, Init(R, HSB, VSB, nil, GDBOutputFile));
  2547. Insert(Editor);
  2548. DisassemblyWindow:=@Self;
  2549. end;
  2550. procedure TDisassemblyWindow.LoadFunction(Const FuncName : string);
  2551. var
  2552. p : PAnsiChar;
  2553. begin
  2554. {$ifndef NODEBUG}
  2555. If not assigned(Debugger) then Exit;
  2556. Debugger^.SetCommand('print symbol on');
  2557. Debugger^.SetCommand('width 0');
  2558. Debugger^.Command('disas /m '+FuncName);
  2559. p:=StrNew(Debugger^.GetOutput);
  2560. ProcessPChar(p);
  2561. if (Debugger^.IsRunning) and (FuncName='') then
  2562. Editor^.GetCurrentLine(Debugger^.current_pc);
  2563. {$endif NODEBUG}
  2564. end;
  2565. procedure TDisassemblyWindow.LoadAddress(Addr : CORE_ADDR);
  2566. var
  2567. p : PAnsiChar;
  2568. begin
  2569. {$ifndef NODEBUG}
  2570. If not assigned(Debugger) then Exit;
  2571. Debugger^.SetCommand('print symbol on');
  2572. Debugger^.SetCommand('width 0');
  2573. Debugger^.Command('disas /m 0x'+HexStr(Addr,sizeof(Addr)*2));
  2574. p:=StrNew(Debugger^.GetOutput);
  2575. ProcessPChar(p);
  2576. if Debugger^.IsRunning and
  2577. (Debugger^.current_pc>=Editor^.MinAddress) and
  2578. (Debugger^.current_pc<=Editor^.MaxAddress) then
  2579. Editor^.GetCurrentLine(Debugger^.current_pc);
  2580. {$endif NODEBUG}
  2581. end;
  2582. function TDisassemblyWindow.ProcessPChar(p : PAnsiChar) : boolean;
  2583. var
  2584. p1: PAnsiChar;
  2585. pline : PAnsiChar;
  2586. pos1, pos2, CurLine, PrevLine : longint;
  2587. CurAddr : CORE_ADDR;
  2588. err : word;
  2589. curaddress, cursymofs, CurFile,
  2590. PrevFile, line : string;
  2591. begin
  2592. ProcessPChar:=true;
  2593. Lock;
  2594. Editor^.DisasLines^.FreeAll;
  2595. Editor^.SetFlags(Editor^.GetFlags or efSyntaxHighlight or efKeepLineAttr);
  2596. Editor^.MinAddress:=0;
  2597. Editor^.MaxAddress:=0;
  2598. Editor^.CurL:=nil;
  2599. p1:=p;
  2600. PrevFile:='';
  2601. PrevLine:=0;
  2602. while assigned(p) do
  2603. begin
  2604. pline:=strscan(p,#10);
  2605. if assigned(pline) then
  2606. pline^:=#0;
  2607. line:=trim(strpas(p));
  2608. CurAddr:=0;
  2609. if assigned(pline) then
  2610. begin
  2611. pline^:=#10;
  2612. p:=pline+1;
  2613. end
  2614. else
  2615. p:=nil;
  2616. { now process the line }
  2617. { Remove current position marker }
  2618. if copy(line,1,3)='=> ' then
  2619. begin
  2620. system.delete(line,1,3);
  2621. end;
  2622. { line is hexaddr <symbol+sym_offset at filename:line> assembly }
  2623. pos1:=pos('<',line);
  2624. if pos1>0 then
  2625. begin
  2626. curaddress:=trim(copy(line,1,pos1-1));
  2627. if copy(curaddress,1,2)='0x' then
  2628. curaddress:='$'+copy(curaddress,3,length(curaddress)-2);
  2629. val(curaddress,CurAddr,err);
  2630. if err>0 then
  2631. val(copy(curaddress,1,err-1),CurAddr,err);
  2632. system.delete(line,1,pos1);
  2633. end;
  2634. pos1:=pos(' at ',line);
  2635. pos2:=pos('>',line);
  2636. if (pos1>0) and (pos1 < pos2) then
  2637. begin
  2638. cursymofs:=copy(line,1,pos1-1);
  2639. CurFile:=copy(line,pos1+4,pos2-pos1-4);
  2640. pos1:=pos(':',CurFile);
  2641. if pos1>0 then
  2642. begin
  2643. val(copy(CurFile,pos1+1,high(CurFile)),CurLine,err);
  2644. system.delete(CurFile,pos1,high(CurFile));
  2645. end
  2646. else
  2647. CurLine:=0;
  2648. system.delete(line,1,pos2);
  2649. end
  2650. else { no ' at ' found before '>' }
  2651. begin
  2652. cursymofs:=copy(line,1,pos2-1);
  2653. CurFile:='';
  2654. system.delete(line,1,pos2);
  2655. end;
  2656. if (CurFile<>'') and ((CurFile<>PrevFile) or (CurLine<>PrevLine)) then
  2657. begin
  2658. WriteSourceString(CurFile,CurLine);
  2659. PrevLine:=CurLine;
  2660. PrevFile:=CurFile;
  2661. end;
  2662. WriteDisassemblyString(line,curaddr);
  2663. end;
  2664. StrDispose(p1);
  2665. Editor^.ReleaseSource;
  2666. Editor^.UpdateAttrs(0,attrForceFull);
  2667. If assigned(BreakpointsCollection) then
  2668. BreakpointsCollection^.ShowBreakpoints(@Self);
  2669. Unlock;
  2670. ReDraw;
  2671. end;
  2672. procedure TDisassemblyWindow.HandleEvent(var Event: TEvent);
  2673. begin
  2674. inherited HandleEvent(Event);
  2675. end;
  2676. procedure TDisassemblyWindow.WriteSourceString(Const S : string;line : longint);
  2677. begin
  2678. Editor^.AddSourceLine(S,line);
  2679. end;
  2680. procedure TDisassemblyWindow.WriteDisassemblyString(Const S : string;address : CORE_ADDR);
  2681. begin
  2682. Editor^.AddAssemblyLine(S,address);
  2683. end;
  2684. procedure TDisassemblyWindow.SetCurAddress(address : CORE_ADDR);
  2685. begin
  2686. if (address<Editor^.MinAddress) or (address>Editor^.MaxAddress) then
  2687. LoadAddress(address);
  2688. Editor^.GetCurrentLine(address);
  2689. end;
  2690. procedure TDisassemblyWindow.UpdateCommands;
  2691. var Active: boolean;
  2692. begin
  2693. Active:=GetState(sfActive);
  2694. SetCmdState(SourceCmds+CompileCmds,Active);
  2695. SetCmdState(EditorCmds,Active);
  2696. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmd+RedoCmd,false);
  2697. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  2698. end;
  2699. function TDisassemblyWindow.GetPalette: PPalette;
  2700. const P: string[length(CSourceWindow)] = CSourceWindow;
  2701. begin
  2702. GetPalette:=@P;
  2703. end;
  2704. destructor TDisassemblyWindow.Done;
  2705. begin
  2706. if @Self=DisassemblyWindow then
  2707. DisassemblyWindow:=nil;
  2708. inherited Done;
  2709. end;
  2710. {$endif NODEBUG}
  2711. constructor TClipboardWindow.Init;
  2712. var R: TRect;
  2713. HSB,VSB: PScrollBar;
  2714. begin
  2715. Desktop^.GetExtent(R);
  2716. inherited Init(R, '*');
  2717. SetTitle(dialog_clipboard);
  2718. HelpCtx:=hcClipboardWindow;
  2719. Number:=wnNoNumber;
  2720. AutoNumber:=true;
  2721. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  2722. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2723. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  2724. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2725. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  2726. New(Indicator, Init(R));
  2727. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  2728. Insert(Indicator);
  2729. GetExtent(R); R.Grow(-1,-1);
  2730. New(Editor, Init(R, HSB, VSB, Indicator, ''));
  2731. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2732. Insert(Editor);
  2733. Editor^.SetFlags(Editor^.GetFlags or efUseTabCharacters);
  2734. Hide;
  2735. Clipboard:=Editor;
  2736. end;
  2737. procedure TClipboardWindow.Close;
  2738. begin
  2739. Hide;
  2740. end;
  2741. constructor TClipboardWindow.Load(var S: TStream);
  2742. begin
  2743. inherited Load(S);
  2744. Clipboard:=Editor;
  2745. end;
  2746. procedure TClipboardWindow.Store(var S: TStream);
  2747. begin
  2748. inherited Store(S);
  2749. end;
  2750. destructor TClipboardWindow.Done;
  2751. begin
  2752. inherited Done;
  2753. Clipboard:=nil;
  2754. ClipboardWindow:=nil;
  2755. end;
  2756. constructor TMessageListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  2757. begin
  2758. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  2759. GrowMode:=gfGrowHiX+gfGrowHiY;
  2760. New(ModuleNames, Init(50,100));
  2761. NoSelection:=true;
  2762. end;
  2763. function TMessageListBox.GetLocalMenu: PMenu;
  2764. var M: PMenu;
  2765. begin
  2766. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  2767. M:=NewMenu(
  2768. NewItem(menu_msglocal_clear,'',kbNoKey,cmMsgClear,hcMsgClear,
  2769. NewLine(
  2770. NewItem(menu_msglocal_gotosource,'',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  2771. NewItem(menu_msglocal_tracksource,'',kbNoKey,cmMsgTrackSource,hcMsgTrackSource,
  2772. NewLine(
  2773. NewItem(menu_msglocal_saveas,'',kbNoKey,cmSaveAs,hcSaveAs,
  2774. nil)))))));
  2775. GetLocalMenu:=M;
  2776. end;
  2777. procedure TMessageListBox.SetState(AState: Word; Enable: Boolean);
  2778. var OldState: word;
  2779. begin
  2780. OldState:=State;
  2781. inherited SetState(AState,Enable);
  2782. if ((AState and sfActive)<>0) and (((OldState xor State) and sfActive)<>0) then
  2783. SetCmdState([cmSaveAs],Enable);
  2784. end;
  2785. procedure TMessageListBox.HandleEvent(var Event: TEvent);
  2786. var DontClear: boolean;
  2787. begin
  2788. case Event.What of
  2789. evKeyDown :
  2790. begin
  2791. DontClear:=false;
  2792. case Event.KeyCode of
  2793. kbEnter :
  2794. begin
  2795. Message(@Self,evCommand,cmMsgGotoSource,nil);
  2796. ClearEvent(Event);
  2797. exit;
  2798. end;
  2799. else
  2800. DontClear:=true;
  2801. end;
  2802. if not DontClear then
  2803. ClearEvent(Event);
  2804. end;
  2805. evBroadcast :
  2806. case Event.Command of
  2807. cmListItemSelected :
  2808. if Event.InfoPtr=@Self then
  2809. Message(@Self,evCommand,cmMsgTrackSource,nil);
  2810. end;
  2811. evCommand :
  2812. begin
  2813. DontClear:=false;
  2814. case Event.Command of
  2815. cmMsgGotoSource :
  2816. if Range>0 then
  2817. begin
  2818. GotoSource;
  2819. ClearEvent(Event);
  2820. exit;
  2821. end;
  2822. cmMsgTrackSource :
  2823. if Range>0 then
  2824. TrackSource;
  2825. cmMsgClear :
  2826. Clear;
  2827. cmSaveAs :
  2828. SaveAs;
  2829. else
  2830. DontClear:=true;
  2831. end;
  2832. if not DontClear then
  2833. ClearEvent(Event);
  2834. end;
  2835. end;
  2836. inherited HandleEvent(Event);
  2837. end;
  2838. procedure TMessageListBox.AddItem(P: PMessageItem);
  2839. var W : integer;
  2840. begin
  2841. if List=nil then New(List, Init(500,500));
  2842. W:=length(P^.GetText(255));
  2843. if W>MaxWidth then
  2844. begin
  2845. MaxWidth:=W;
  2846. if HScrollBar<>nil then
  2847. HScrollBar^.SetRange(0,MaxWidth);
  2848. end;
  2849. List^.Insert(P);
  2850. SetRange(List^.Count);
  2851. if Focused=List^.Count-1-1 then
  2852. FocusItem(List^.Count-1);
  2853. DrawView;
  2854. end;
  2855. function TMessageListBox.AddModuleName(const Name: string): PString;
  2856. var P: PString;
  2857. begin
  2858. if ModuleNames<>nil then
  2859. P:=ModuleNames^.Add(Name)
  2860. else
  2861. P:=nil;
  2862. AddModuleName:=P;
  2863. end;
  2864. function TMessageListBox.GetText(Item,MaxLen: Sw_Integer): String;
  2865. var P: PMessageItem;
  2866. S: string;
  2867. begin
  2868. P:=List^.At(Item);
  2869. S:=P^.GetText(MaxLen);
  2870. GetText:=copy(S,1,MaxLen);
  2871. end;
  2872. procedure TMessageListBox.Clear;
  2873. begin
  2874. if assigned(List) then
  2875. Dispose(List, Done);
  2876. List:=nil;
  2877. MaxWidth:=0;
  2878. if assigned(ModuleNames) then
  2879. ModuleNames^.FreeAll;
  2880. SetRange(0); DrawView;
  2881. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2882. end;
  2883. procedure TMessageListBox.TrackSource;
  2884. var W: PSourceWindow;
  2885. P: PMessageItem;
  2886. R: TRect;
  2887. Row,Col: sw_integer;
  2888. Found : boolean;
  2889. begin
  2890. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2891. if Range=0 then Exit;
  2892. P:=List^.At(Focused);
  2893. if P^.Row=0 then Exit;
  2894. Desktop^.Lock;
  2895. GetNextEditorBounds(R);
  2896. R.B.Y:=Owner^.Origin.Y;
  2897. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  2898. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  2899. W:=EditorWindowFile(P^.GetModuleName);
  2900. if assigned(W) then
  2901. begin
  2902. W^.GetExtent(R);
  2903. R.B.Y:=Owner^.Origin.Y;
  2904. W^.ChangeBounds(R);
  2905. W^.Editor^.SetCurPtr(Col,Row);
  2906. end
  2907. else
  2908. W:=TryToOpenFile(@R,P^.GetModuleName,Col,Row,true);
  2909. { Try to find it by browsing }
  2910. if W=nil then
  2911. begin
  2912. Desktop^.UnLock;
  2913. Found:=IDEApp.OpenSearch(P^.GetModuleName+'*');
  2914. if found then
  2915. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2916. Desktop^.Lock;
  2917. end;
  2918. if W<>nil then
  2919. begin
  2920. W^.Select;
  2921. W^.Editor^.TrackCursor(do_centre);
  2922. W^.Editor^.SetLineFlagExclusive(lfHighlightRow,Row);
  2923. end;
  2924. if Assigned(Owner) then
  2925. Owner^.Select;
  2926. Desktop^.UnLock;
  2927. end;
  2928. procedure TMessageListBox.GotoSource;
  2929. var W: PSourceWindow;
  2930. P: PMessageItem;
  2931. R:TRect;
  2932. Row,Col: sw_integer;
  2933. Found : boolean;
  2934. Event : TEvent;
  2935. begin
  2936. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  2937. if Range=0 then Exit;
  2938. P:=List^.At(Focused);
  2939. if P^.Row=0 then Exit;
  2940. Desktop^.Lock;
  2941. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  2942. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  2943. W:=EditorWindowFile(P^.GetModuleName);
  2944. if assigned(W) then
  2945. begin
  2946. W^.GetExtent(R);
  2947. if Owner^.Origin.Y>R.A.Y+4 then
  2948. R.B.Y:=Owner^.Origin.Y;
  2949. W^.ChangeBounds(R);
  2950. W^.Editor^.SetCurPtr(Col,Row);
  2951. end
  2952. else
  2953. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2954. { Try to find it by browsing }
  2955. if W=nil then
  2956. begin
  2957. Desktop^.UnLock;
  2958. Found:=IDEApp.OpenSearch(P^.GetModuleName+'*');
  2959. if found then
  2960. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  2961. Desktop^.Lock;
  2962. end;
  2963. if assigned(W) then
  2964. begin
  2965. { Message(Owner,evCommand,cmClose,nil);
  2966. This calls close on StackWindow
  2967. rendering P invalid
  2968. so postpone it PM }
  2969. W^.GetExtent(R);
  2970. if (P^.TClass<>0) then
  2971. W^.Editor^.SetErrorMessage(P^.GetText(R.B.X-R.A.X));
  2972. W^.Select;
  2973. Owner^.Hide;
  2974. end;
  2975. Desktop^.UnLock;
  2976. if assigned(W) then
  2977. begin
  2978. Event.What:=evCommand;
  2979. Event.command:=cmClose;
  2980. Event.InfoPtr:=nil;
  2981. fpide.PutEvent(Owner,Event);
  2982. end;
  2983. end;
  2984. procedure TMessageListBox.Draw;
  2985. var
  2986. I, J, Item: Sw_Integer;
  2987. NormalColor, SelectedColor, FocusedColor, Color: Word;
  2988. ColWidth, CurCol, Indent: Integer;
  2989. B: TDrawBuffer;
  2990. Text: String;
  2991. SCOff: Byte;
  2992. TC: byte;
  2993. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  2994. begin
  2995. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2996. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2997. begin
  2998. NormalColor := GetColor(1);
  2999. FocusedColor := GetColor(3);
  3000. SelectedColor := GetColor(4);
  3001. end else
  3002. begin
  3003. NormalColor := GetColor(2);
  3004. SelectedColor := GetColor(4);
  3005. end;
  3006. if Transparent then
  3007. begin MT(NormalColor); MT(SelectedColor); end;
  3008. if NoSelection then
  3009. SelectedColor:=NormalColor;
  3010. if HScrollBar <> nil then Indent := HScrollBar^.Value
  3011. else Indent := 0;
  3012. ColWidth := Size.X div NumCols + 1;
  3013. for I := 0 to Size.Y - 1 do
  3014. begin
  3015. for J := 0 to NumCols-1 do
  3016. begin
  3017. Item := J*Size.Y + I + TopItem;
  3018. CurCol := J*ColWidth;
  3019. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  3020. (Focused = Item) and (Range > 0) then
  3021. begin
  3022. Color := FocusedColor;
  3023. SetCursor(CurCol+1,I);
  3024. SCOff := 0;
  3025. end
  3026. else if (Item < Range) and IsSelected(Item) then
  3027. begin
  3028. Color := SelectedColor;
  3029. SCOff := 2;
  3030. end
  3031. else
  3032. begin
  3033. Color := NormalColor;
  3034. SCOff := 4;
  3035. end;
  3036. MoveChar(B[CurCol], ' ', Color, ColWidth);
  3037. if Item < Range then
  3038. begin
  3039. Text := GetText(Item, ColWidth + Indent);
  3040. Text := Copy(Text,Indent,ColWidth);
  3041. MoveStr(B[CurCol+1], Text, Color);
  3042. if ShowMarkers then
  3043. begin
  3044. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  3045. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  3046. end;
  3047. end;
  3048. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  3049. end;
  3050. WriteLine(0, I, Size.X, 1, B);
  3051. end;
  3052. end;
  3053. constructor TMessageListBox.Load(var S: TStream);
  3054. begin
  3055. inherited Load(S);
  3056. New(ModuleNames, Init(50,100));
  3057. NoSelection:=true;
  3058. end;
  3059. procedure TMessageListBox.Store(var S: TStream);
  3060. var OL: PCollection;
  3061. ORV: sw_integer;
  3062. begin
  3063. OL:=List; ORV:=Range;
  3064. New(List, Init(1,1)); Range:=0;
  3065. inherited Store(S);
  3066. Dispose(List, Done);
  3067. List:=OL; Range:=ORV;
  3068. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  3069. collection? Pasting here a modified version of TListBox.Store+
  3070. TAdvancedListBox.Store isn't a better solution, since by eventually
  3071. changing the obj-hierarchy you'll always have to modify this, too - BG }
  3072. end;
  3073. destructor TMessageListBox.Done;
  3074. begin
  3075. inherited Done;
  3076. if List<>nil then Dispose(List, Done);
  3077. if ModuleNames<>nil then Dispose(ModuleNames, Done);
  3078. end;
  3079. constructor TMessageItem.Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  3080. begin
  3081. inherited Init;
  3082. TClass:=AClass;
  3083. Text:=NewStr(AText);
  3084. Module:=AModule;
  3085. Row:=ARow; Col:=ACol;
  3086. end;
  3087. function TMessageItem.GetText(MaxLen: Sw_integer): string;
  3088. var S: string;
  3089. begin
  3090. if Text=nil then S:='' else S:=Text^;
  3091. if (Module<>nil) then
  3092. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+S;
  3093. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  3094. GetText:=S;
  3095. end;
  3096. procedure TMessageItem.Selected;
  3097. begin
  3098. end;
  3099. function TMessageItem.GetModuleName: string;
  3100. begin
  3101. GetModuleName:=GetStr(Module);
  3102. end;
  3103. destructor TMessageItem.Done;
  3104. begin
  3105. inherited Done;
  3106. if Text<>nil then DisposeStr(Text);
  3107. { if Module<>nil then DisposeStr(Module);}
  3108. end;
  3109. procedure TFPDlgWindow.HandleEvent(var Event: TEvent);
  3110. begin
  3111. case Event.What of
  3112. evBroadcast :
  3113. case Event.Command of
  3114. cmSearchWindow+1..cmSearchWindow+99 :
  3115. if (Event.Command-cmSearchWindow=Number) then
  3116. ClearEvent(Event);
  3117. end;
  3118. end;
  3119. inherited HandleEvent(Event);
  3120. end;
  3121. (*
  3122. constructor TTab.Init(var Bounds: TRect; ATabDef: PTabDef);
  3123. begin
  3124. inherited Init(Bounds);
  3125. Options:=Options or ofSelectable or ofFirstClick or ofPreProcess or ofPostProcess;
  3126. GrowMode:=gfGrowHiX+gfGrowHiY+gfGrowRel;
  3127. TabDefs:=ATabDef;
  3128. ActiveDef:=-1;
  3129. SelectTab(0);
  3130. ReDraw;
  3131. end;
  3132. function TTab.TabCount: integer;
  3133. var i: integer;
  3134. P: PTabDef;
  3135. begin
  3136. I:=0; P:=TabDefs;
  3137. while (P<>nil) do
  3138. begin
  3139. Inc(I);
  3140. P:=P^.Next;
  3141. end;
  3142. TabCount:=I;
  3143. end;
  3144. function TTab.AtTab(Index: integer): PTabDef;
  3145. var i: integer;
  3146. P: PTabDef;
  3147. begin
  3148. i:=0; P:=TabDefs;
  3149. while (I<Index) do
  3150. begin
  3151. if P=nil then RunError($AA);
  3152. P:=P^.Next;
  3153. Inc(i);
  3154. end;
  3155. AtTab:=P;
  3156. end;
  3157. procedure TTab.SelectTab(Index: integer);
  3158. var P: PTabItem;
  3159. V: PView;
  3160. begin
  3161. if ActiveDef<>Index then
  3162. begin
  3163. if Owner<>nil then Owner^.Lock;
  3164. Lock;
  3165. { --- Update --- }
  3166. if TabDefs<>nil then
  3167. begin
  3168. DefCount:=1;
  3169. while AtTab(DefCount-1)^.Next<>nil do Inc(DefCount);
  3170. end
  3171. else DefCount:=0;
  3172. if ActiveDef<>-1 then
  3173. begin
  3174. P:=AtTab(ActiveDef)^.Items;
  3175. while P<>nil do
  3176. begin
  3177. if P^.View<>nil then Delete(P^.View);
  3178. P:=P^.Next;
  3179. end;
  3180. end;
  3181. ActiveDef:=Index;
  3182. P:=AtTab(ActiveDef)^.Items;
  3183. while P<>nil do
  3184. begin
  3185. if P^.View<>nil then Insert(P^.View);
  3186. P:=P^.Next;
  3187. end;
  3188. V:=AtTab(ActiveDef)^.DefItem;
  3189. if V<>nil then V^.Select;
  3190. ReDraw;
  3191. { --- Update --- }
  3192. UnLock;
  3193. if Owner<>nil then Owner^.UnLock;
  3194. DrawView;
  3195. end;
  3196. end;
  3197. procedure TTab.ChangeBounds(var Bounds: TRect);
  3198. var D: TPoint;
  3199. procedure DoCalcChange(P: PView);
  3200. var
  3201. R: TRect;
  3202. begin
  3203. if P^.Owner=nil then Exit; { it think this is a bug in TV }
  3204. P^.CalcBounds(R, D);
  3205. P^.ChangeBounds(R);
  3206. end;
  3207. var
  3208. P: PTabItem;
  3209. I: integer;
  3210. begin
  3211. D.X := Bounds.B.X - Bounds.A.X - Size.X;
  3212. D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  3213. inherited ChangeBounds(Bounds);
  3214. for I:=0 to TabCount-1 do
  3215. if I<>ActiveDef then
  3216. begin
  3217. P:=AtTab(I)^.Items;
  3218. while P<>nil do
  3219. begin
  3220. if P^.View<>nil then DoCalcChange(P^.View);
  3221. P:=P^.Next;
  3222. end;
  3223. end;
  3224. end;
  3225. procedure TTab.SelectNextTab(Forwards: boolean);
  3226. var Index: integer;
  3227. begin
  3228. Index:=ActiveDef;
  3229. if Index=-1 then Exit;
  3230. if Forwards then Inc(Index) else Dec(Index);
  3231. if Index<0 then Index:=DefCount-1 else
  3232. if Index>DefCount-1 then Index:=0;
  3233. SelectTab(Index);
  3234. end;
  3235. procedure TTab.HandleEvent(var Event: TEvent);
  3236. var Index : integer;
  3237. I : integer;
  3238. X : integer;
  3239. Len : byte;
  3240. P : TPoint;
  3241. V : PView;
  3242. CallOrig: boolean;
  3243. LastV : PView;
  3244. FirstV: PView;
  3245. function FirstSelectable: PView;
  3246. var
  3247. FV : PView;
  3248. begin
  3249. FV := First;
  3250. while (FV<>nil) and ((FV^.Options and ofSelectable)=0) and (FV<>Last) do
  3251. FV:=FV^.Next;
  3252. if FV<>nil then
  3253. if (FV^.Options and ofSelectable)=0 then FV:=nil;
  3254. FirstSelectable:=FV;
  3255. end;
  3256. function LastSelectable: PView;
  3257. var
  3258. LV : PView;
  3259. begin
  3260. LV := Last;
  3261. while (LV<>nil) and ((LV^.Options and ofSelectable)=0) and (LV<>First) do
  3262. LV:=LV^.Prev;
  3263. if LV<>nil then
  3264. if (LV^.Options and ofSelectable)=0 then LV:=nil;
  3265. LastSelectable:=LV;
  3266. end;
  3267. begin
  3268. if (Event.What and evMouseDown)<>0 then
  3269. begin
  3270. MakeLocal(Event.Where,P);
  3271. if P.Y<3 then
  3272. begin
  3273. Index:=-1; X:=1;
  3274. for i:=0 to DefCount-1 do
  3275. begin
  3276. Len:=CStrLen(AtTab(i)^.Name^);
  3277. if (P.X>=X) and (P.X<=X+Len+1) then Index:=i;
  3278. X:=X+Len+3;
  3279. end;
  3280. if Index<>-1 then
  3281. SelectTab(Index);
  3282. end;
  3283. end;
  3284. if Event.What=evKeyDown then
  3285. begin
  3286. Index:=-1;
  3287. case Event.KeyCode of
  3288. kbCtrlTab :
  3289. begin
  3290. SelectNextTab((Event.KeyShift and kbShift)=0);
  3291. ClearEvent(Event);
  3292. end;
  3293. kbTab,kbShiftTab :
  3294. if GetState(sfSelected) then
  3295. begin
  3296. if Current<>nil then
  3297. begin
  3298. LastV:=LastSelectable; FirstV:=FirstSelectable;
  3299. if ((Current=LastV) or (Current=PLabel(LastV)^.Link)) and (Event.KeyCode=kbShiftTab) then
  3300. begin
  3301. if Owner<>nil then Owner^.SelectNext(true);
  3302. end else
  3303. if ((Current=FirstV) or (Current=PLabel(FirstV)^.Link)) and (Event.KeyCode=kbTab) then
  3304. begin
  3305. Lock;
  3306. if Owner<>nil then Owner^.SelectNext(false);
  3307. UnLock;
  3308. end else
  3309. SelectNext(Event.KeyCode=kbShiftTab);
  3310. ClearEvent(Event);
  3311. end;
  3312. end;
  3313. else
  3314. for I:=0 to DefCount-1 do
  3315. begin
  3316. if Upcase(GetAltChar(Event.KeyCode))=AtTab(I)^.ShortCut
  3317. then begin
  3318. Index:=I;
  3319. ClearEvent(Event);
  3320. Break;
  3321. end;
  3322. end;
  3323. end;
  3324. if Index<>-1 then
  3325. begin
  3326. Select;
  3327. SelectTab(Index);
  3328. V:=AtTab(ActiveDef)^.DefItem;
  3329. if V<>nil then V^.Focus;
  3330. end;
  3331. end;
  3332. CallOrig:=true;
  3333. if Event.What=evKeyDown then
  3334. begin
  3335. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  3336. then
  3337. else CallOrig:=false;
  3338. end;
  3339. if CallOrig then inherited HandleEvent(Event);
  3340. end;
  3341. function TTab.GetPalette: PPalette;
  3342. begin
  3343. GetPalette:=nil;
  3344. end;
  3345. procedure TTab.Draw;
  3346. var B : TDrawBuffer;
  3347. i : integer;
  3348. C1,C2,C3,C : word;
  3349. HeaderLen : integer;
  3350. X,X2 : integer;
  3351. Name : PString;
  3352. ActiveKPos : integer;
  3353. ActiveVPos : integer;
  3354. FC : AnsiChar;
  3355. ClipR : TRect;
  3356. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  3357. var i: integer;
  3358. begin
  3359. if Y+H>Size.Y then H:=Size.Y-Y;
  3360. if X+W>Size.X then W:=Size.X-X;
  3361. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  3362. else for i:=1 to H do
  3363. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  3364. end;
  3365. procedure ClearBuf;
  3366. begin
  3367. MoveChar(B,' ',C1,Size.X);
  3368. end;
  3369. begin
  3370. if InDraw then Exit;
  3371. InDraw:=true;
  3372. { - Start of TGroup.Draw - }
  3373. { if Buffer = nil then
  3374. begin
  3375. GetBuffer;
  3376. end; }
  3377. { - Start of TGroup.Draw - }
  3378. C1:=GetColor(1); C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256; C3:=GetColor(8)+GetColor({9}8)*256;
  3379. HeaderLen:=0; for i:=0 to DefCount-1 do HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3; Dec(HeaderLen);
  3380. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  3381. { --- 1. sor --- }
  3382. ClearBuf; MoveChar(B[0],''#$B3'',C1,1); MoveChar(B[HeaderLen+1],''#$B3'',C1,1);
  3383. X:=1;
  3384. for i:=0 to DefCount-1 do
  3385. begin
  3386. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  3387. if i=ActiveDef
  3388. then begin
  3389. ActiveKPos:=X-1;
  3390. ActiveVPos:=X+X2+2;
  3391. if GetState(sfFocused) then C:=C3 else C:=C2;
  3392. end
  3393. else C:=C2;
  3394. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  3395. MoveChar(B[X-1],''#$B3'',C1,1);
  3396. end;
  3397. SWriteBuf(0,1,Size.X,1,B);
  3398. { --- 0. sor --- }
  3399. ClearBuf; MoveChar(B[0],''#$DA'',C1,1);
  3400. X:=1;
  3401. for i:=0 to DefCount-1 do
  3402. begin
  3403. if I<ActiveDef then FC:=#$DA
  3404. else FC:=#$BF;
  3405. X2:=CStrLen(AtTab(i)^.Name^)+2;
  3406. MoveChar(B[X+X2],{''#$C2''}FC,C1,1);
  3407. if i=DefCount-1 then X2:=X2+1;
  3408. if X2>0 then
  3409. MoveChar(B[X],''#$C4'',C1,X2);
  3410. X:=X+X2+1;
  3411. end;
  3412. MoveChar(B[HeaderLen+1],#$BF,C1,1);
  3413. MoveChar(B[ActiveKPos],#$DA,C1,1); MoveChar(B[ActiveVPos],#$BF,C1,1);
  3414. SWriteBuf(0,0,Size.X,1,B);
  3415. { --- 2. sor --- }
  3416. MoveChar(B[1],#$C4,C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],#$C4,C1,Max(Size.X-HeaderLen-3,0));
  3417. MoveChar(B[Size.X-1],#$BF,C1,1);
  3418. MoveChar(B[ActiveKPos],#$D9,C1,1);
  3419. if ActiveDef=0 then MoveChar(B[0],#$B3,C1,1)
  3420. else MoveChar(B[0],{#$C3}#$DA,C1,1);
  3421. MoveChar(B[HeaderLen+1],#$C4{''#$C1''},C1,1); MoveChar(B[ActiveVPos],#$C0,C1,1);
  3422. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  3423. SWriteBuf(0,2,Size.X,1,B);
  3424. { --- marad#$82k sor --- }
  3425. ClearBuf; MoveChar(B[0],''#$B3'',C1,1); MoveChar(B[Size.X-1],''#$B3'',C1,1);
  3426. for i:=3 to Size.Y-1 do
  3427. SWriteBuf(0,i,Size.X,1,B);
  3428. { SWriteBuf(0,3,Size.X,Size.Y-4,B); this was wrong
  3429. because WriteBuf then expect a buffer of size size.x*(size.y-4)*2 PM }
  3430. { --- Size.X . sor --- }
  3431. MoveChar(B[0],''#$C0'',C1,1); MoveChar(B[1],''#$C4'',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],''#$D9'',C1,1);
  3432. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  3433. { - End of TGroup.Draw - }
  3434. if Buffer <> nil then
  3435. begin
  3436. Lock;
  3437. Redraw;
  3438. UnLock;
  3439. end;
  3440. if Buffer <> nil then WriteBuf(0, 0, Size.X, Size.Y, Buffer^) else
  3441. begin
  3442. GetClipRect(ClipR);
  3443. Redraw;
  3444. GetExtent(ClipR);
  3445. end;
  3446. { - End of TGroup.Draw - }
  3447. InDraw:=false;
  3448. end;
  3449. function TTab.Valid(Command: Word): Boolean;
  3450. var PT : PTabDef;
  3451. PI : PTabItem;
  3452. OK : boolean;
  3453. begin
  3454. OK:=true;
  3455. PT:=TabDefs;
  3456. while (PT<>nil) and (OK=true) do
  3457. begin
  3458. PI:=PT^.Items;
  3459. while (PI<>nil) and (OK=true) do
  3460. begin
  3461. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  3462. PI:=PI^.Next;
  3463. end;
  3464. PT:=PT^.Next;
  3465. end;
  3466. Valid:=OK;
  3467. end;
  3468. procedure TTab.SetState(AState: Word; Enable: Boolean);
  3469. begin
  3470. inherited SetState(AState,Enable);
  3471. if (AState and sfFocused)<>0 then DrawView;
  3472. end;
  3473. destructor TTab.Done;
  3474. var P,X: PTabDef;
  3475. procedure DeleteViews(P: PView);
  3476. begin
  3477. if P<>nil then Delete(P);
  3478. end;
  3479. begin
  3480. ForEach(TCallbackProcParam(@DeleteViews));
  3481. inherited Done;
  3482. P:=TabDefs;
  3483. while P<>nil do
  3484. begin
  3485. X:=P^.Next;
  3486. DisposeTabDef(P);
  3487. P:=X;
  3488. end;
  3489. end;
  3490. *)
  3491. constructor TScreenView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  3492. AScreen: PScreen);
  3493. begin
  3494. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  3495. Screen:=AScreen;
  3496. if Screen=nil then
  3497. Fail;
  3498. SetState(sfCursorVis,true);
  3499. Update;
  3500. end;
  3501. procedure TScreenView.Update;
  3502. begin
  3503. SetLimit(UserScreen^.GetWidth,UserScreen^.GetHeight);
  3504. DrawView;
  3505. end;
  3506. procedure TScreenView.HandleEvent(var Event: TEvent);
  3507. begin
  3508. case Event.What of
  3509. evBroadcast :
  3510. case Event.Command of
  3511. cmUpdate : Update;
  3512. end;
  3513. end;
  3514. inherited HandleEvent(Event);
  3515. end;
  3516. procedure TScreenView.Draw;
  3517. var B: TDrawBuffer;
  3518. X,Y: integer;
  3519. Text,Attr: string;
  3520. P: TPoint;
  3521. begin
  3522. Screen^.GetCursorPos(P);
  3523. for Y:=Delta.Y to Delta.Y+Size.Y-1 do
  3524. begin
  3525. if Y<Screen^.GetHeight then
  3526. Screen^.GetLine(Y,Text,Attr)
  3527. else
  3528. begin Text:=''; Attr:=''; end;
  3529. Text:=copy(Text,Delta.X+1,255); Attr:=copy(Attr,Delta.X+1,255);
  3530. MoveChar(B,' ',GetColor(1),Size.X);
  3531. for X:=1 to length(Text) do
  3532. MoveChar(B[X-1],Text[X],ord(Attr[X]),1);
  3533. WriteLine(0,Y-Delta.Y,Size.X,1,B);
  3534. end;
  3535. SetCursor(P.X-Delta.X,P.Y-Delta.Y);
  3536. end;
  3537. constructor TScreenWindow.Init(AScreen: PScreen; ANumber: integer);
  3538. var R: TRect;
  3539. VSB,HSB: PScrollBar;
  3540. begin
  3541. Desktop^.GetExtent(R);
  3542. inherited Init(R, dialog_userscreen, ANumber);
  3543. Options:=Options or ofTileAble;
  3544. GetExtent(R); R.Grow(-1,-1); R.Move(1,0); R.A.X:=R.B.X-1;
  3545. New(VSB, Init(R)); VSB^.Options:=VSB^.Options or ofPostProcess;
  3546. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  3547. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.A.Y:=R.B.Y-1;
  3548. New(HSB, Init(R)); HSB^.Options:=HSB^.Options or ofPostProcess;
  3549. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  3550. GetExtent(R); R.Grow(-1,-1);
  3551. New(ScreenView, Init(R, HSB, VSB, AScreen));
  3552. ScreenView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  3553. Insert(ScreenView);
  3554. UserScreenWindow:=@Self;
  3555. end;
  3556. destructor TScreenWindow.Done;
  3557. begin
  3558. inherited Done;
  3559. UserScreenWindow:=nil;
  3560. end;
  3561. const InTranslate : boolean = false;
  3562. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  3563. procedure TranslateAction(Action: integer);
  3564. var E: TEvent;
  3565. begin
  3566. if Action<>acNone then
  3567. begin
  3568. E:=Event;
  3569. E.What:=evMouseDown; E.Buttons:=mbLeftButton;
  3570. View^.HandleEvent(E);
  3571. Event.What:=evCommand;
  3572. Event.Command:=ActionCommands[Action];
  3573. end;
  3574. end;
  3575. begin
  3576. if InTranslate then Exit;
  3577. InTranslate:=true;
  3578. case Event.What of
  3579. evMouseDown :
  3580. if (GetShiftState and kbAlt)<>0 then
  3581. TranslateAction(AltMouseAction) else
  3582. if (GetShiftState and kbCtrl)<>0 then
  3583. TranslateAction(CtrlMouseAction);
  3584. end;
  3585. InTranslate:=false;
  3586. end;
  3587. function GetNextEditorBounds(var Bounds: TRect): boolean;
  3588. var P: PView;
  3589. begin
  3590. P:=Desktop^.Current;
  3591. while P<>nil do
  3592. begin
  3593. if P^.HelpCtx=hcSourceWindow then Break;
  3594. P:=P^.NextView;
  3595. if P=Desktop^.Current then
  3596. begin
  3597. P:=nil;
  3598. break;
  3599. end;
  3600. end;
  3601. if P=nil then Desktop^.GetExtent(Bounds) else
  3602. begin
  3603. P^.GetBounds(Bounds);
  3604. Inc(Bounds.A.X); Inc(Bounds.A.Y);
  3605. end;
  3606. GetNextEditorBounds:=P<>nil;
  3607. end;
  3608. function IOpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer; ShowIt: boolean): PSourceWindow;
  3609. var R: TRect;
  3610. W: PSourceWindow;
  3611. begin
  3612. if Assigned(Bounds) then R.Copy(Bounds^) else
  3613. GetNextEditorBounds(R);
  3614. PushStatus(FormatStrStr(msg_openingsourcefile,SmartPath(FileName)));
  3615. New(W, Init(R, FileName));
  3616. if ShowIt=false then
  3617. W^.Hide;
  3618. if W<>nil then
  3619. begin
  3620. if (CurX<>0) or (CurY<>0) then
  3621. with W^.Editor^ do
  3622. begin
  3623. SetCurPtr(CurX,CurY);
  3624. TrackCursor(do_centre);
  3625. end;
  3626. W^.HelpCtx:=hcSourceWindow;
  3627. Desktop^.Insert(W);
  3628. { this makes loading a lot slower and is not needed as far as I can see (FK)
  3629. Message(Application,evBroadcast,cmUpdate,nil);
  3630. }
  3631. if ShowIt then
  3632. W^.SetCmdState([cmTile,cmCascade,cmSaveAll],true)
  3633. else
  3634. W^.SetCmdState([cmSaveAll],true);
  3635. end;
  3636. PopStatus;
  3637. IOpenEditorWindow:=W;
  3638. end;
  3639. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  3640. begin
  3641. OpenEditorWindow:=IOpenEditorWindow(Bounds,FileName,CurX,CurY,true);
  3642. end;
  3643. function LastSourceEditor : PSourceWindow;
  3644. function IsSearchedSource(P: PView) : boolean;
  3645. begin
  3646. if assigned(P) and
  3647. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  3648. IsSearchedSource:=true
  3649. else
  3650. IsSearchedSource:=false;
  3651. end;
  3652. begin
  3653. LastSourceEditor:=PSourceWindow(Desktop^.FirstThat(@IsSearchedSource));
  3654. end;
  3655. function SearchOnDesktop(FileName : string;tryexts:boolean) : PSourceWindow;
  3656. var
  3657. D,DS : DirStr;
  3658. N,NS : NameStr;
  3659. E,ES : ExtStr;
  3660. SName : string;
  3661. function IsSearchedFile(W : PSourceWindow) : boolean;
  3662. var Found: boolean;
  3663. begin
  3664. Found:=false;
  3665. if (W<>nil) and (W^.HelpCtx=hcSourceWindow) then
  3666. begin
  3667. if (D='') then
  3668. SName:=NameAndExtOf(PSourceWindow(W)^.Editor^.FileName)
  3669. else
  3670. SName:=PSourceWindow(W)^.Editor^.FileName;
  3671. FSplit(SName,DS,NS,ES);
  3672. SName:=UpcaseStr(NS+ES);
  3673. if (E<>'') or (not tryexts) then
  3674. begin
  3675. if D<>'' then
  3676. Found:=UpCaseStr(DS)+SName=UpcaseStr(D+N+E)
  3677. else
  3678. Found:=SName=UpcaseStr(N+E);
  3679. end
  3680. else
  3681. begin
  3682. Found:=SName=UpcaseStr(N+'.pp');
  3683. if Found=false then
  3684. Found:=SName=UpcaseStr(N+'.pas');
  3685. end;
  3686. end;
  3687. IsSearchedFile:=found;
  3688. end;
  3689. function IsSearchedSource(P: PView) : boolean;
  3690. begin
  3691. if assigned(P) and
  3692. (TypeOf(P^)=TypeOf(TSourceWindow)) then
  3693. IsSearchedSource:=IsSearchedFile(PSourceWindow(P))
  3694. else
  3695. IsSearchedSource:=false;
  3696. end;
  3697. begin
  3698. FSplit(FileName,D,N,E);
  3699. SearchOnDesktop:=PSourceWindow(Desktop^.FirstThat(@IsSearchedSource));
  3700. end;
  3701. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean): PSourceWindow;
  3702. begin
  3703. TryToOpenFile:=ITryToOpenFile(Bounds,FileName,CurX,CurY,tryexts,true,false);
  3704. end;
  3705. function TryToOpenFileMulti(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean): PSourceWindow;
  3706. var srec:SearchRec;
  3707. dir,name,ext : string;
  3708. begin
  3709. fsplit(filename,dir,name,ext);
  3710. dir:=completedir(dir);
  3711. FindFirst(filename,anyfile,Srec);
  3712. while (DosError=0) do
  3713. begin
  3714. ITryToOpenFile(Bounds,dir+srec.name,CurX,CurY,tryexts,true,false);
  3715. FindNext(srec);
  3716. end;
  3717. FindClose(srec);
  3718. end;
  3719. function LocateSingleSourceFile(const FileName: string; tryexts: boolean): string;
  3720. var D : DirStr;
  3721. N : NameStr;
  3722. E : ExtStr;
  3723. function CheckDir(NewDir: DirStr; NewName: NameStr; NewExt: ExtStr): boolean;
  3724. var OK: boolean;
  3725. begin
  3726. NewDir:=CompleteDir(NewDir);
  3727. OK:=ExistsFile(NewDir+NewName+NewExt);
  3728. if OK then begin D:=NewDir; N:=NewName; E:=NewExt; end;
  3729. CheckDir:=OK;
  3730. end;
  3731. function CheckExt(NewExt: ExtStr): boolean;
  3732. var OK: boolean;
  3733. begin
  3734. OK:=false;
  3735. if D<>'' then OK:=CheckDir(D,N,NewExt) else
  3736. if CheckDir('.'+DirSep,N,NewExt) then OK:=true;
  3737. CheckExt:=OK;
  3738. end;
  3739. function TryToLocateIn(const DD : dirstr): boolean;
  3740. var Found: boolean;
  3741. begin
  3742. D:=CompleteDir(DD);
  3743. Found:=true;
  3744. if (E<>'') or (not tryexts) then
  3745. Found:=CheckExt(E)
  3746. else
  3747. if CheckExt('.pp') then
  3748. Found:=true
  3749. else
  3750. if CheckExt('.pas') then
  3751. Found:=true
  3752. else
  3753. if CheckExt('.inc') then
  3754. Found:=true
  3755. { try also without extension if no other exist }
  3756. else
  3757. if CheckExt('') then
  3758. Found:=true
  3759. else
  3760. Found:=false;
  3761. TryToLocateIn:=Found;
  3762. end;
  3763. var Path,DrStr: string;
  3764. Found: boolean;
  3765. begin
  3766. FSplit(FileName,D,N,E);
  3767. Found:=CheckDir(D,N,E);
  3768. if not found then
  3769. Found:=TryToLocateIn('.');
  3770. DrStr:=GetSourceDirectories;
  3771. if not Found then
  3772. While pos(ListSeparator,DrStr)>0 do
  3773. Begin
  3774. Found:=TryToLocateIn(Copy(DrStr,1,pos(ListSeparator,DrStr)-1));
  3775. if Found then
  3776. break;
  3777. DrStr:=Copy(DrStr,pos(ListSeparator,DrStr)+1,High(DrStr));
  3778. End;
  3779. if Found then Path:=FExpand(D+N+E) else Path:='';
  3780. LocateSingleSourceFile:=Path;
  3781. end;
  3782. function LocateSourceFile(const FileName: string; tryexts: boolean): string;
  3783. var P: integer;
  3784. FN,S: string;
  3785. FFN: string;
  3786. begin
  3787. FN:=FileName;
  3788. repeat
  3789. P:=Pos(ListSeparator,FN); if P=0 then P:=length(FN)+1;
  3790. S:=copy(FN,1,P-1); Delete(FN,1,P);
  3791. FFN:=LocateSingleSourceFile(S,tryexts);
  3792. until (FFN<>'') or (FN='');
  3793. LocateSourceFile:=FFN;
  3794. end;
  3795. function ITryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean;
  3796. ShowIt,ForceNewWindow: boolean): PSourceWindow;
  3797. var
  3798. W : PSourceWindow;
  3799. DrStr: string;
  3800. begin
  3801. W:=nil;
  3802. if ForceNewWindow then
  3803. W:=nil
  3804. else
  3805. W:=SearchOnDesktop(FileName,tryexts);
  3806. if W<>nil then
  3807. begin
  3808. NewEditorOpened:=false;
  3809. { if assigned(Bounds) then
  3810. W^.ChangeBounds(Bounds^);}
  3811. W^.Editor^.SetCurPtr(CurX,CurY);
  3812. end
  3813. else
  3814. begin
  3815. DrStr:=LocateSourceFile(FileName,tryexts);
  3816. if DrStr<>'' then
  3817. W:=IOpenEditorWindow(Bounds,DrStr,CurX,CurY,ShowIt);
  3818. NewEditorOpened:=W<>nil;
  3819. if assigned(W) then
  3820. W^.Editor^.SetCurPtr(CurX,CurY);
  3821. end;
  3822. ITryToOpenFile:=W;
  3823. end;
  3824. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  3825. var OK: boolean;
  3826. E: PFileEditor;
  3827. R: TRect;
  3828. begin
  3829. R.Assign(0,0,0,0);
  3830. New(E, Init(R,nil,nil,nil,nil,FileName));
  3831. OK:=E<>nil;
  3832. if OK then
  3833. begin
  3834. PushStatus(FormatStrStr(msg_readingfileineditor,FileName));
  3835. OK:=E^.LoadFile;
  3836. PopStatus;
  3837. end;
  3838. if OK then
  3839. begin
  3840. Editor^.Lock;
  3841. E^.SelectAll(true);
  3842. Editor^.InsertFrom(E);
  3843. Editor^.SetCurPtr(0,0);
  3844. Editor^.SelectAll(false);
  3845. Editor^.UnLock;
  3846. Dispose(E, Done);
  3847. end;
  3848. StartEditor:=OK;
  3849. end;
  3850. constructor TTextScroller.Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  3851. begin
  3852. inherited Init(Bounds,'');
  3853. EventMask:=EventMask or evIdle;
  3854. Speed:=ASpeed; Lines:=AText;
  3855. end;
  3856. function TTextScroller.GetLineCount: integer;
  3857. var Count: integer;
  3858. begin
  3859. if Lines=nil then Count:=0 else
  3860. Count:=Lines^.Count;
  3861. GetLineCount:=Count;
  3862. end;
  3863. function TTextScroller.GetLine(I: integer): string;
  3864. var S: string;
  3865. begin
  3866. if I<Lines^.Count then
  3867. S:=GetStr(Lines^.At(I))
  3868. else
  3869. S:='';
  3870. GetLine:=S;
  3871. end;
  3872. procedure TTextScroller.HandleEvent(var Event: TEvent);
  3873. begin
  3874. case Event.What of
  3875. evIdle :
  3876. Update;
  3877. end;
  3878. inherited HandleEvent(Event);
  3879. end;
  3880. procedure TTextScroller.Update;
  3881. begin
  3882. if abs(GetDosTicks-LastTT)<Speed then Exit;
  3883. Scroll;
  3884. LastTT:=GetDosTicks;
  3885. end;
  3886. procedure TTextScroller.Reset;
  3887. begin
  3888. TopLine:=0;
  3889. LastTT:=GetDosTicks;
  3890. DrawView;
  3891. end;
  3892. procedure TTextScroller.Scroll;
  3893. begin
  3894. Inc(TopLine);
  3895. if TopLine>=GetLineCount then
  3896. Reset;
  3897. DrawView;
  3898. end;
  3899. procedure TTextScroller.Draw;
  3900. var B: TDrawBuffer;
  3901. C: word;
  3902. Count,Y: integer;
  3903. S: string;
  3904. begin
  3905. C:=GetColor(1);
  3906. Count:=GetLineCount;
  3907. for Y:=0 to Size.Y-1 do
  3908. begin
  3909. if Count=0 then S:='' else
  3910. S:=GetLine((TopLine+Y) mod Count);
  3911. if copy(S,1,1)=^C then
  3912. S:=CharStr(' ',Max(0,(Size.X-(length(S)-1)) div 2))+copy(S,2,255);
  3913. MoveChar(B,' ',C,Size.X);
  3914. MoveStr(B,S,C);
  3915. WriteLine(0,Y,Size.X,1,B);
  3916. end;
  3917. end;
  3918. destructor TTextScroller.Done;
  3919. begin
  3920. inherited Done;
  3921. if Lines<>nil then Dispose(Lines, Done);
  3922. end;
  3923. constructor TFPChDirDialog.Init(AOptions: Word; HistoryId: Sw_Word);
  3924. var
  3925. R: TRect;
  3926. DInput : PEditorInputLine;
  3927. Control : PView;
  3928. History : PHistory;
  3929. S : String;
  3930. begin
  3931. inherited init(AOptions,HistoryId);
  3932. HelpCtx:=hcChangeDir;
  3933. {replace TInputLine with TEditorInputLine in order to be able to use Clipboard in it}
  3934. DirInput^.getData(S);
  3935. R.Assign(3, 3, 30, 4);
  3936. DInput := New(PEditorInputLine, Init(R, FileNameLen+4));
  3937. DInput^.SetData(S);
  3938. InsertBefore(DInput,DirInput); {insert before to preserv order as it was}
  3939. Delete(DirInput);
  3940. Dispose(DirInput,done);
  3941. DirInput:=DInput;
  3942. Control:=DirInput^.Next; {here we make assumption that THistory control will folow}
  3943. while (Control<> nil) do
  3944. begin
  3945. if TypeOf(Control^) = TypeOf(THistory) then
  3946. begin
  3947. History:=PHistory(Control);
  3948. History^.Link:=DirInput;
  3949. break;
  3950. end;
  3951. Control:=Control^.Next;
  3952. end;
  3953. {set focus on the new input line}
  3954. DirInput^.Focus;
  3955. end;
  3956. constructor TFPAboutDialog.Init;
  3957. var R,R2: TRect;
  3958. C: PUnsortedStringCollection;
  3959. I,nblines: integer;
  3960. OSStr: string;
  3961. procedure AddLine(S: string);
  3962. begin
  3963. C^.Insert(NewStr(S));
  3964. end;
  3965. begin
  3966. R.Assign(0,0,58,14{$ifdef USE_GRAPH_SWITCH}+1{$endif});
  3967. inherited Init(R, dialog_about);
  3968. HelpCtx:=hcAbout;
  3969. GetExtent(R); R.Grow(-3,-2);
  3970. R2.Copy(R); R2.B.Y:=R2.A.Y+1;
  3971. Insert(New(PStaticText, Init(R2, ^C'Free Pascal IDE for '+source_info.name)));
  3972. R2.Move(0,1);
  3973. Insert(New(PStaticText, Init(R2, ^C'Target CPU: '+target_cpu_string)));
  3974. R2.Move(0,1);
  3975. Insert(New(PStaticText, Init(R2, ^C'Version '+VersionStr+' '+{$i %date%})));
  3976. R2.Move(0,1);
  3977. {$ifdef USE_GRAPH_SWITCH}
  3978. Insert(New(PStaticText, Init(R2, ^C'With Graphic Support')));
  3979. R2.Move(0,1);
  3980. {$endif USE_GRAPH_SWITCH}
  3981. Insert(New(PStaticText, Init(R2, FormatStrStr2(^C'(%s %s)',label_about_compilerversion,Full_Version_String))));
  3982. {$ifndef NODEBUG}
  3983. if pos('Fake',GDBVersion)=0 then
  3984. begin
  3985. R2.Move(0,1);
  3986. nblines:=1;
  3987. for i:=1 to length(GDBVersion) do
  3988. if GDBVersion[i]=#13 then
  3989. inc(nblines);
  3990. R2.B.Y:=R2.A.Y+nblines;
  3991. if nblines>1 then
  3992. GrowTo(Size.X,Size.Y+nblines-1);
  3993. {$ifdef GDBMI}
  3994. if GDBVersionOK then
  3995. Insert(New(PStaticText, Init(R2, FormatStrStr2(^C'(%s %s, using MI interface)',label_about_debugger,GDBVersion))))
  3996. else
  3997. Insert(New(PStaticText, Init(R2, FormatStrStr(^C'%s',GDBVersion))));
  3998. {$else}
  3999. Insert(New(PStaticText, Init(R2, FormatStrStr2(^C'(%s %s)',label_about_debugger,GDBVersion))));
  4000. {$endif}
  4001. R2.Move(0,nblines);
  4002. R2.B.Y:=R2.A.Y+1;
  4003. end
  4004. else
  4005. {$endif NODEBUG}
  4006. R2.Move(0,2);
  4007. Insert(New(PStaticText, Init(R2, ^C'Copyright (C) 1998-2020 by')));
  4008. R2.Move(0,2);
  4009. Insert(New(PStaticText, Init(R2, ^C'B'#$82'rczi G'#$A0'bor')));
  4010. R2.Move(0,1);
  4011. Insert(New(PStaticText, Init(R2, ^C'Pierre Muller')));
  4012. R2.Move(0,1);
  4013. Insert(New(PStaticText, Init(R2, ^C'and')));
  4014. R2.Move(0,1);
  4015. Insert(New(PStaticText, Init(R2, ^C'Peter Vreman')));
  4016. New(C, Init(50,10));
  4017. for I:=1 to 7 do
  4018. AddLine('');
  4019. AddLine(^C'< Original concept >');
  4020. AddLine(^C'Borland International, Inc.');
  4021. AddLine('');
  4022. AddLine(^C'< Compiler development >');
  4023. AddLine(^C'Carl-Eric Codere');
  4024. AddLine(^C'Daniel Mantione');
  4025. AddLine(^C'Florian Kl'#$84'mpfl');
  4026. AddLine(^C'Jonas Maebe');
  4027. AddLine(^C'Mich'#$84'el Van Canneyt');
  4028. AddLine(^C'Peter Vreman');
  4029. AddLine(^C'Pierre Muller');
  4030. AddLine('');
  4031. AddLine(^C'< IDE development >');
  4032. AddLine(^C'B'#$82'rczi G'#$A0'bor');
  4033. AddLine(^C'Peter Vreman');
  4034. AddLine(^C'Pierre Muller');
  4035. AddLine('');
  4036. AddLine(^C'< GDBMI development >');
  4037. AddLine(^C'Nikolay Nikolov');
  4038. AddLine('');
  4039. GetExtent(R);
  4040. R.Grow(-1,-1); Inc(R.A.Y,3);
  4041. New(Scroller, Init(R, 10, C));
  4042. Scroller^.Hide;
  4043. Insert(Scroller);
  4044. R.Move(0,-1); R.B.Y:=R.A.Y+1;
  4045. New(TitleST, Init(R, ^C'Team'));
  4046. TitleST^.Hide;
  4047. Insert(TitleST);
  4048. InsertOK(@Self);
  4049. end;
  4050. procedure TFPAboutDialog.ToggleInfo;
  4051. begin
  4052. if Scroller=nil then Exit;
  4053. if Scroller^.GetState(sfVisible) then
  4054. begin
  4055. Scroller^.Hide;
  4056. TitleST^.Hide;
  4057. end
  4058. else
  4059. begin
  4060. Scroller^.Reset;
  4061. Scroller^.Show;
  4062. TitleST^.Show;
  4063. end;
  4064. end;
  4065. procedure TFPAboutDialog.HandleEvent(var Event: TEvent);
  4066. begin
  4067. case Event.What of
  4068. evKeyDown :
  4069. case Event.KeyCode of
  4070. kbAltI : { just like in BP }
  4071. begin
  4072. ToggleInfo;
  4073. ClearEvent(Event);
  4074. end;
  4075. end;
  4076. end;
  4077. inherited HandleEvent(Event);
  4078. end;
  4079. constructor TFPASCIIChart.Init;
  4080. begin
  4081. inherited Init;
  4082. HelpCtx:=hcASCIITableWindow;
  4083. Number:=SearchFreeWindowNo;
  4084. ASCIIChart:=@Self;
  4085. end;
  4086. procedure TFPASCIIChart.Store(var S: TStream);
  4087. begin
  4088. inherited Store(S);
  4089. end;
  4090. constructor TFPASCIIChart.Load(var S: TStream);
  4091. begin
  4092. inherited Load(S);
  4093. end;
  4094. procedure TFPASCIIChart.HandleEvent(var Event: TEvent);
  4095. var W: PSourceWindow;
  4096. begin
  4097. {writeln(stderr,'all what=',event.what,' cmd=', event.command);}
  4098. case Event.What of
  4099. evKeyDown :
  4100. case Event.KeyCode of
  4101. kbEsc :
  4102. begin
  4103. Close;
  4104. ClearEvent(Event);
  4105. end;
  4106. end;
  4107. evCommand :
  4108. begin
  4109. {writeln(stderr,'fpascii what=',event.what, ' cmd=', event.command, ' ',cmtransfer,' ',cmsearchwindow);}
  4110. if Event.Command=(AsciiTableCommandBase+1) then // variable
  4111. begin
  4112. W:=FirstEditorWindow;
  4113. if Assigned(W) and Assigned(Report) then
  4114. Message(W,evCommand,cmAddChar,Event.InfoPtr);
  4115. ClearEvent(Event);
  4116. end
  4117. else
  4118. case Event.Command of
  4119. cmTransfer :
  4120. begin
  4121. W:=FirstEditorWindow;
  4122. if Assigned(W) and Assigned(Report) then
  4123. Message(W,evCommand,cmAddChar,pointer(ptrint(ord(Report^.AsciiChar))));
  4124. ClearEvent(Event);
  4125. end;
  4126. cmSearchWindow+1..cmSearchWindow+99 :
  4127. if (Event.Command-cmSearchWindow=Number) then
  4128. ClearEvent(Event);
  4129. end;
  4130. end;
  4131. end;
  4132. inherited HandleEvent(Event);
  4133. end;
  4134. destructor TFPASCIIChart.Done;
  4135. begin
  4136. ASCIIChart:=nil;
  4137. inherited Done;
  4138. end;
  4139. function TVideoModeListBox.GetText(Item: pointer; MaxLen: sw_integer): string;
  4140. var P: PVideoMode;
  4141. S: string;
  4142. begin
  4143. P:=Item;
  4144. S:=IntToStr(P^.Col)+'x'+IntToStr(P^.Row)+' ';
  4145. if P^.Color then
  4146. S:=S+'color'
  4147. else
  4148. S:=S+'mono';
  4149. GetText:=copy(S,1,MaxLen);
  4150. end;
  4151. constructor TFPDesktop.Init(var Bounds: TRect);
  4152. begin
  4153. inherited Init(Bounds);
  4154. end;
  4155. procedure TFPDesktop.InitBackground;
  4156. var AV: PANSIBackground;
  4157. FileName: string;
  4158. R: TRect;
  4159. begin
  4160. AV:=nil;
  4161. FileName:=LocateFile(BackgroundPath);
  4162. if FileName<>'' then
  4163. begin
  4164. GetExtent(R);
  4165. New(AV, Init(R));
  4166. AV^.GrowMode:=gfGrowHiX+gfGrowHiY;
  4167. if AV^.LoadFile(FileName)=false then
  4168. begin
  4169. Dispose(AV, Done); AV:=nil;
  4170. end;
  4171. if Assigned(AV) then
  4172. Insert(AV);
  4173. end;
  4174. Background:=AV;
  4175. if Assigned(Background)=false then
  4176. inherited InitBackground;
  4177. end;
  4178. constructor TFPDesktop.Load(var S: TStream);
  4179. begin
  4180. inherited Load(S);
  4181. end;
  4182. procedure TFPDesktop.Store(var S: TStream);
  4183. begin
  4184. inherited Store(S);
  4185. end;
  4186. constructor TFPToolTip.Init(var Bounds: TRect; const AText: string; AAlign: TAlign);
  4187. begin
  4188. inherited Init(Bounds);
  4189. SetAlign(AAlign);
  4190. SetText(AText);
  4191. end;
  4192. procedure TFPToolTip.Draw;
  4193. var C: word;
  4194. procedure DrawLine(Y: integer; S: string);
  4195. var B: TDrawBuffer;
  4196. begin
  4197. S:=copy(S,1,Size.X-2);
  4198. case Align of
  4199. alLeft : S:=' '+S;
  4200. alRight : S:=LExpand(' '+S,Size.X);
  4201. alCenter : S:=Center(S,Size.X);
  4202. end;
  4203. MoveChar(B,' ',C,Size.X);
  4204. MoveStr(B,S,C);
  4205. WriteLine(0,Y,Size.X,1,B);
  4206. end;
  4207. var S: string;
  4208. Y: integer;
  4209. begin
  4210. C:=GetColor(1);
  4211. S:=GetText;
  4212. for Y:=0 to Size.Y-1 do
  4213. DrawLine(Y,S);
  4214. end;
  4215. function TFPToolTip.GetText: string;
  4216. begin
  4217. GetText:=GetStr(Text);
  4218. end;
  4219. procedure TFPToolTip.SetText(const AText: string);
  4220. begin
  4221. if AText<>GetText then
  4222. begin
  4223. if Assigned(Text) then DisposeStr(Text);
  4224. Text:=NewStr(AText);
  4225. DrawView;
  4226. end;
  4227. end;
  4228. function TFPToolTip.GetAlign: TAlign;
  4229. begin
  4230. GetAlign:=Align;
  4231. end;
  4232. procedure TFPToolTip.SetAlign(AAlign: TAlign);
  4233. begin
  4234. if AAlign<>Align then
  4235. begin
  4236. Align:=AAlign;
  4237. DrawView;
  4238. end;
  4239. end;
  4240. destructor TFPToolTip.Done;
  4241. begin
  4242. if Assigned(Text) then DisposeStr(Text); Text:=nil;
  4243. inherited Done;
  4244. end;
  4245. function TFPToolTip.GetPalette: PPalette;
  4246. const S: string[length(CFPToolTip)] = CFPToolTip;
  4247. begin
  4248. GetPalette:=@S;
  4249. end;
  4250. constructor TFPMemo.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  4251. PScrollBar; AIndicator: PIndicator);
  4252. begin
  4253. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,nil);
  4254. SetFlags(Flags and not (efPersistentBlocks) or efSyntaxHighlight);
  4255. end;
  4256. procedure TFPMemo.HandleEvent(var Event: TEvent);
  4257. var DontClear: boolean;
  4258. S: string;
  4259. begin
  4260. case Event.What of
  4261. evKeyDown :
  4262. begin
  4263. DontClear:=false;
  4264. case Event.KeyCode of
  4265. kbEsc:
  4266. begin
  4267. Event.What:=evCommand;
  4268. Event.Command:=cmCancel;
  4269. PutEvent(Event);
  4270. end;
  4271. else DontClear:=true;
  4272. end;
  4273. if not DontClear then ClearEvent(Event);
  4274. end;
  4275. end;
  4276. inherited HandleEvent(Event);
  4277. end;
  4278. function TFPMemo.GetPalette: PPalette;
  4279. const P: string[length(CFPMemo)] = CFPMemo;
  4280. begin
  4281. GetPalette:=@P;
  4282. end;
  4283. function TFPMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  4284. begin
  4285. GetSpecSymbolCount:=0;
  4286. end;
  4287. function TFPMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  4288. begin
  4289. Abstract;
  4290. GetSpecSymbol:=nil;
  4291. end;
  4292. function TFPMemo.IsReservedWord(const S: string): boolean;
  4293. begin
  4294. IsReservedWord:=false;
  4295. end;
  4296. constructor TFPCodeMemo.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  4297. PScrollBar; AIndicator: PIndicator);
  4298. begin
  4299. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator);
  4300. end;
  4301. function TFPCodeMemo.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  4302. begin
  4303. GetSpecSymbolCount:=FreePascalSpecSymbolCount[SpecClass];
  4304. end;
  4305. function TFPCodeMemo.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): pstring;
  4306. begin
  4307. GetSpecSymbol:=@FreePascalEmptyString;
  4308. case SpecClass of
  4309. ssCommentPrefix :
  4310. case Index of
  4311. 0 : GetSpecSymbol:=@FreePascalCommentPrefix1;
  4312. 1 : GetSpecSymbol:=@FreePascalCommentPrefix2;
  4313. 2 : GetSpecSymbol:=@FreePascalCommentPrefix3;
  4314. end;
  4315. ssCommentSingleLinePrefix :
  4316. case Index of
  4317. 0 : GetSpecSymbol:=@FreePascalCommentSingleLinePrefix;
  4318. end;
  4319. ssCommentSuffix :
  4320. case Index of
  4321. 0 : GetSpecSymbol:=@FreePascalCommentSuffix1;
  4322. 1 : GetSpecSymbol:=@FreePascalCommentSuffix2;
  4323. end;
  4324. ssStringPrefix :
  4325. GetSpecSymbol:=@FreePascalStringPrefix;
  4326. ssStringSuffix :
  4327. GetSpecSymbol:=@FreePascalStringSuffix;
  4328. { must be uppercased to avoid calling UpCaseStr in MatchesAnyAsmSymbol PM }
  4329. ssAsmPrefix :
  4330. GetSpecSymbol:=@FreePascalAsmPrefix;
  4331. ssAsmSuffix :
  4332. GetSpecSymbol:=@FreePascalAsmSuffix;
  4333. ssDirectivePrefix :
  4334. GetSpecSymbol:=@FreePascalDirectivePrefix;
  4335. ssDirectiveSuffix :
  4336. GetSpecSymbol:=@FreePascalDirectiveSuffix;
  4337. end;
  4338. end;
  4339. function TFPCodeMemo.IsReservedWord(const S: string): boolean;
  4340. begin
  4341. IsReservedWord:=IsFPReservedWord(S);
  4342. end;
  4343. {$ifdef VESA}
  4344. function VESASetVideoModeProc(const VideoMode: TVideoMode; Params: Longint): Boolean;
  4345. begin
  4346. VESASetVideoModeProc:=VESASetMode(Params);
  4347. end;
  4348. procedure InitVESAScreenModes;
  4349. var ML: TVESAModeList;
  4350. MI: TVESAModeInfoBlock;
  4351. I: integer;
  4352. begin
  4353. if VESAInit=false then Exit;
  4354. if VESAGetModeList(ML)=false then Exit;
  4355. for I:=1 to ML.Count do
  4356. begin
  4357. if VESAGetModeInfo(ML.Modes[I],MI) then
  4358. with MI do
  4359. {$ifndef DEBUG}
  4360. if (Attributes and vesa_vma_GraphicsMode)=0 then
  4361. {$else DEBUG}
  4362. if ((Attributes and vesa_vma_GraphicsMode)=0) or
  4363. { only allow 4 bit i.e. 16 color modes }
  4364. (((Attributes and vesa_vma_CanBeSetInCurrentConfig)<>0) and
  4365. (BitsPerPixel=8)) then
  4366. {$endif DEBUG}
  4367. RegisterVesaVideoMode(ML.Modes[I]);
  4368. end;
  4369. end;
  4370. procedure DoneVESAScreenModes;
  4371. begin
  4372. FreeVesaModes;
  4373. end;
  4374. {$endif}
  4375. procedure NoDebugger;
  4376. begin
  4377. InformationBox(msg_nodebuggersupportavailable,nil);
  4378. end;
  4379. procedure RegisterFPViews;
  4380. begin
  4381. RegisterType(RSourceEditor);
  4382. RegisterType(RSourceWindow);
  4383. RegisterType(RFPHelpViewer);
  4384. RegisterType(RFPHelpWindow);
  4385. RegisterType(RClipboardWindow);
  4386. RegisterType(RMessageListBox);
  4387. RegisterType(RFPDesktop);
  4388. RegisterType(RFPASCIIChart);
  4389. RegisterType(RFPDlgWindow);
  4390. {$ifndef NODEBUG}
  4391. RegisterType(RGDBWindow);
  4392. RegisterType(RGDBSourceEditor);
  4393. {$endif NODEBUG}
  4394. end;
  4395. END.