fpviews.pas 118 KB

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