fpviews.pas 118 KB

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