fpviews.pas 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771
  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,Commands,HelpCtx,Views,Menus,Dialogs,App,Gadgets,
  17. ASCIITAB,
  18. {$ifdef EDITORS}
  19. Editors,
  20. {$else}
  21. WEditor,
  22. {$endif}
  23. WUtils,WHelp,WHlpView,WViews,
  24. Comphook,
  25. FPConst,FPUsrScr;
  26. type
  27. {$IFNDEF EDITORS}
  28. TEditor = TCodeEditor; PEditor = PCodeEditor;
  29. {$ENDIF}
  30. PStoreCollection = ^TStoreCollection;
  31. TStoreCollection = object(TStringCollection)
  32. function Add(const S: string): PString;
  33. end;
  34. PIntegerLine = ^TIntegerLine;
  35. TIntegerLine = object(TInputLine)
  36. constructor Init(var Bounds: TRect; AMin, AMax: longint);
  37. end;
  38. PFPHeapView = ^TFPHeapView;
  39. TFPHeapView = object(THeapView)
  40. constructor Init(var Bounds: TRect);
  41. constructor InitKb(var Bounds: TRect);
  42. procedure HandleEvent(var Event: TEvent); virtual;
  43. end;
  44. TFPWindow = object(TWindow)
  45. procedure HandleEvent(var Event: TEvent); virtual;
  46. end;
  47. PFPHelpViewer = ^TFPHelpViewer;
  48. TFPHelpViewer = object(THelpViewer)
  49. function GetLocalMenu: PMenu; virtual;
  50. function GetCommandTarget: PView; virtual;
  51. end;
  52. PFPHelpWindow = ^TFPHelpWindow;
  53. TFPHelpWindow = object(THelpWindow)
  54. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word; AContext: THelpCtx; ANumber: Integer);
  55. procedure InitHelpView; virtual;
  56. procedure Show; virtual;
  57. procedure Hide; virtual;
  58. procedure HandleEvent(var Event: TEvent); virtual;
  59. function GetPalette: PPalette; virtual;
  60. end;
  61. PTextScroller = ^TTextScroller;
  62. TTextScroller = object(TStaticText)
  63. TopLine: integer;
  64. Speed : integer;
  65. Lines : PUnsortedStringCollection;
  66. constructor Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  67. function GetLineCount: integer; virtual;
  68. function GetLine(I: integer): string; virtual;
  69. procedure HandleEvent(var Event: TEvent); virtual;
  70. procedure Update; virtual;
  71. procedure Reset; virtual;
  72. procedure Scroll; virtual;
  73. procedure Draw; virtual;
  74. destructor Done; virtual;
  75. private
  76. LastTT: longint;
  77. end;
  78. PSourceEditor = ^TSourceEditor;
  79. TSourceEditor = object(TFileEditor)
  80. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  81. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  82. {$ifndef EDITORS}
  83. function IsReservedWord(const S: string): boolean; virtual;
  84. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  85. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): string; virtual;
  86. {$endif}
  87. procedure HandleEvent(var Event: TEvent); virtual;
  88. function GetLocalMenu: PMenu; virtual;
  89. function GetCommandTarget: PView; virtual;
  90. function CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup; virtual;
  91. end;
  92. PSourceWindow = ^TSourceWindow;
  93. TSourceWindow = object(TFPWindow)
  94. Editor : PSourceEditor;
  95. Indicator : PIndicator;
  96. constructor Init(var Bounds: TRect; AFileName: string);
  97. procedure SetTitle(ATitle: string); virtual;
  98. procedure UpdateTitle; virtual;
  99. procedure HandleEvent(var Event: TEvent); virtual;
  100. procedure SetState(AState: Word; Enable: Boolean); virtual;
  101. procedure Update; virtual;
  102. procedure UpdateCommands; virtual;
  103. function GetPalette: PPalette; virtual;
  104. constructor Load(var S: TStream);
  105. procedure Store(var S: TStream);
  106. destructor Done; virtual;
  107. end;
  108. PGDBSourceEditor = ^TGDBSourceEditor;
  109. TGDBSourceEditor = object(TSourceEditor)
  110. function InsertLine : Sw_integer;virtual;
  111. function Valid(Command: Word): Boolean; virtual;
  112. procedure AddLine(const S: string); virtual;
  113. procedure AddErrorLine(const S: string); virtual;
  114. private
  115. Silent,
  116. AutoRepeat,
  117. IgnoreStringAtEnd : boolean;
  118. LastCommand : String;
  119. end;
  120. PGDBWindow = ^TGDBWindow;
  121. TGDBWindow = object(TFPWindow)
  122. Editor : PGDBSourceEditor;
  123. Indicator : PIndicator;
  124. constructor Init(var Bounds: TRect);
  125. procedure WriteText(Buf : pchar;IsError : boolean);
  126. procedure WriteString(Const S : string);
  127. procedure WriteErrorString(Const S : string);
  128. procedure WriteOutputText(Buf : pchar);
  129. procedure WriteErrorText(Buf : pchar);
  130. function GetPalette: PPalette;virtual;
  131. destructor Done; virtual;
  132. end;
  133. PClipboardWindow = ^TClipboardWindow;
  134. TClipboardWindow = object(TSourceWindow)
  135. constructor Init;
  136. procedure Show; virtual;
  137. procedure Hide; virtual;
  138. procedure Close; virtual;
  139. constructor Load(var S: TStream);
  140. procedure Store(var S: TStream);
  141. destructor Done; virtual;
  142. end;
  143. PMessageItem = ^TMessageItem;
  144. TMessageItem = object(TObject)
  145. TClass : longint;
  146. Text : PString;
  147. Module : PString;
  148. Row,Col : sw_integer;
  149. constructor Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  150. function GetText(MaxLen: Sw_integer): string; virtual;
  151. procedure Selected; virtual;
  152. function GetModuleName: string; virtual;
  153. destructor Done; virtual;
  154. end;
  155. PMessageListBox = ^TMessageListBox;
  156. TMessageListBox = object(THSListBox)
  157. Transparent : boolean;
  158. NoSelection : boolean;
  159. MaxWidth : Sw_integer;
  160. ModuleNames : PStoreCollection;
  161. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  162. procedure AddItem(P: PMessageItem); virtual;
  163. function AddModuleName(const Name: string): PString; virtual;
  164. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  165. procedure Clear; virtual;
  166. procedure TrackSource; virtual;
  167. procedure GotoSource; virtual;
  168. procedure Draw; virtual;
  169. procedure HandleEvent(var Event: TEvent); virtual;
  170. function GetLocalMenu: PMenu; virtual;
  171. constructor Load(var S: TStream);
  172. procedure Store(var S: TStream);
  173. destructor Done; virtual;
  174. end;
  175. {$ifdef OLDCOMP}
  176. PCompilerMessage = ^TCompilerMessage;
  177. TCompilerMessage = object(TMessageItem)
  178. function GetText(MaxLen: Sw_Integer): String; virtual;
  179. end;
  180. {$endif}
  181. PProgramInfoWindow = ^TProgramInfoWindow;
  182. TProgramInfoWindow = object(TDlgWindow)
  183. InfoST: PColorStaticText;
  184. LogLB : PMessageListBox;
  185. constructor Init;
  186. procedure AddMessage(AClass: longint; Msg, Module: string; Line, Column: longint);
  187. procedure ClearMessages;
  188. procedure SizeLimits(var Min, Max: TPoint); virtual;
  189. procedure Close; virtual;
  190. procedure HandleEvent(var Event: TEvent); virtual;
  191. procedure Update; virtual;
  192. destructor Done; virtual;
  193. end;
  194. PTabItem = ^TTabItem;
  195. TTabItem = record
  196. Next : PTabItem;
  197. View : PView;
  198. Dis : boolean;
  199. end;
  200. PTabDef = ^TTabDef;
  201. TTabDef = record
  202. Next : PTabDef;
  203. Name : PString;
  204. Items : PTabItem;
  205. DefItem : PView;
  206. ShortCut : char;
  207. end;
  208. PTab = ^TTab;
  209. TTab = object(TGroup)
  210. TabDefs : PTabDef;
  211. ActiveDef : integer;
  212. DefCount : word;
  213. constructor Init(var Bounds: TRect; ATabDef: PTabDef);
  214. function AtTab(Index: integer): PTabDef; virtual;
  215. procedure SelectTab(Index: integer); virtual;
  216. function TabCount: integer;
  217. function Valid(Command: Word): Boolean; virtual;
  218. procedure ChangeBounds(var Bounds: TRect); virtual;
  219. procedure HandleEvent(var Event: TEvent); virtual;
  220. function GetPalette: PPalette; virtual;
  221. procedure Draw; virtual;
  222. procedure SetState(AState: Word; Enable: Boolean); virtual;
  223. destructor Done; virtual;
  224. private
  225. InDraw: boolean;
  226. end;
  227. PScreenView = ^TScreenView;
  228. TScreenView = object(TScroller)
  229. Screen: PScreen;
  230. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  231. AScreen: PScreen);
  232. procedure Draw; virtual;
  233. procedure Update; virtual;
  234. procedure HandleEvent(var Event: TEvent); virtual;
  235. end;
  236. PScreenWindow = ^TScreenWindow;
  237. TScreenWindow = object(TFPWindow)
  238. ScreenView : PScreenView;
  239. constructor Init(AScreen: PScreen; ANumber: integer);
  240. destructor Done; virtual;
  241. end;
  242. PFPAboutDialog = ^TFPAboutDialog;
  243. TFPAboutDialog = object(TCenterDialog)
  244. constructor Init;
  245. procedure ToggleInfo;
  246. procedure HandleEvent(var Event: TEvent); virtual;
  247. private
  248. Scroller: PTextScroller;
  249. TitleST : PStaticText;
  250. end;
  251. PFPASCIIChart = ^TFPASCIIChart;
  252. TFPASCIIChart = object(TASCIIChart)
  253. constructor Init;
  254. procedure HandleEvent(var Event: TEvent); virtual;
  255. destructor Done; virtual;
  256. end;
  257. PVideoModeListBox = ^TVideoModeListBox;
  258. TVideoModeListBox = object(TDropDownListBox)
  259. function GetText(Item: pointer; MaxLen: sw_integer): string; virtual;
  260. end;
  261. function SearchFreeWindowNo: integer;
  262. function IsThereAnyEditor: boolean;
  263. function IsThereAnyWindow: boolean;
  264. function FirstEditorWindow: PSourceWindow;
  265. function EditorWindowFile(const Name : String): PSourceWindow;
  266. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  267. procedure DisposeTabItem(P: PTabItem);
  268. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  269. procedure DisposeTabDef(P: PTabDef);
  270. function GetEditorCurWord(Editor: PEditor): string;
  271. procedure InitReservedWords;
  272. procedure DoneReservedWords;
  273. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  274. function GetNextEditorBounds(var Bounds: TRect): boolean;
  275. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  276. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean): PSourceWindow;
  277. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  278. {$ifdef VESA}
  279. procedure InitVESAScreenModes;
  280. {$endif}
  281. procedure NoDebugger;
  282. const
  283. SourceCmds : TCommandSet =
  284. ([cmSave,cmSaveAs,cmCompile]);
  285. EditorCmds : TCommandSet =
  286. ([cmFind,cmReplace,cmSearchAgain,cmJumpLine,cmHelpTopicSearch]);
  287. CompileCmds : TCommandSet =
  288. ([cmMake,cmBuild,cmRun]);
  289. CalcClipboard : extended = 0;
  290. OpenFileName : string = '';
  291. OpenFileLastExt : string[12] = '*.pas';
  292. NewEditorOpened : boolean = false;
  293. var MsgParms : array[1..10] of
  294. record
  295. case byte of
  296. 0 : (Ptr : pointer);
  297. 1 : (Long: longint);
  298. end;
  299. procedure RegisterFPViews;
  300. implementation
  301. uses
  302. Video,Strings,Keyboard,Memory,MsgBox,Validate,
  303. Tokens,Version,
  304. {$ifdef VESA}Vesa,{$endif}
  305. FPSwitch,FPSymbol,FPDebug,FPVars,FPUtils,FPCompile,FPHelp;
  306. const
  307. RSourceEditor: TStreamRec = (
  308. ObjType: 1500;
  309. VmtLink: Ofs(TypeOf(TSourceEditor)^);
  310. Load: @TSourceEditor.Load;
  311. Store: @TSourceEditor.Store
  312. );
  313. RSourceWindow: TStreamRec = (
  314. ObjType: 1501;
  315. VmtLink: Ofs(TypeOf(TSourceWindow)^);
  316. Load: @TSourceWindow.Load;
  317. Store: @TSourceWindow.Store
  318. );
  319. RFPHelpViewer: TStreamRec = (
  320. ObjType: 1502;
  321. VmtLink: Ofs(TypeOf(TFPHelpViewer)^);
  322. Load: @TFPHelpViewer.Load;
  323. Store: @TFPHelpViewer.Store
  324. );
  325. RFPHelpWindow: TStreamRec = (
  326. ObjType: 1503;
  327. VmtLink: Ofs(TypeOf(TFPHelpWindow)^);
  328. Load: @TFPHelpWindow.Load;
  329. Store: @TFPHelpWindow.Store
  330. );
  331. RClipboardWindow: TStreamRec = (
  332. ObjType: 1504;
  333. VmtLink: Ofs(TypeOf(TClipboardWindow)^);
  334. Load: @TClipboardWindow.Load;
  335. Store: @TClipboardWindow.Store
  336. );
  337. RMessageListBox: TStreamRec = (
  338. ObjType: 1505;
  339. VmtLink: Ofs(TypeOf(TMessageListBox)^);
  340. Load: @TMessageListBox.Load;
  341. Store: @TMessageListBox.Store
  342. );
  343. const
  344. NoNameCount : integer = 0;
  345. ReservedWords : PUnsortedStringCollection = nil;
  346. {****************************************************************************
  347. TStoreCollection
  348. ****************************************************************************}
  349. function TStoreCollection.Add(const S: string): PString;
  350. var P: PString;
  351. Index: Sw_integer;
  352. begin
  353. if S='' then P:=nil else
  354. if Search(@S,Index) then P:=At(Index) else
  355. begin
  356. P:=NewStr(S);
  357. Insert(P);
  358. end;
  359. Add:=P;
  360. end;
  361. function IsThereAnyEditor: boolean;
  362. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  363. begin
  364. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  365. end;
  366. begin
  367. IsThereAnyEditor:=Desktop^.FirstThat(@EditorWindow)<>nil;
  368. end;
  369. function IsThereAnyHelpWindow: boolean;
  370. begin
  371. IsThereAnyHelpWindow:=(HelpWindow<>nil) and (HelpWindow^.GetState(sfVisible));
  372. end;
  373. function IsThereAnyWindow: boolean;
  374. var _Is: boolean;
  375. begin
  376. _Is:=Message(Desktop,evBroadcast,cmSearchWindow,nil)<>nil;
  377. _Is:=_Is or ( (ClipboardWindow<>nil) and ClipboardWindow^.GetState(sfVisible));
  378. IsThereAnyWindow:=_Is;
  379. end;
  380. function FirstEditorWindow: PSourceWindow;
  381. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  382. begin
  383. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  384. end;
  385. begin
  386. FirstEditorWindow:=pointer(Desktop^.FirstThat(@EditorWindow));
  387. end;
  388. function EditorWindowFile(const Name : String): PSourceWindow;
  389. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  390. begin
  391. EditorWindow:=(TypeOf(P^)=TypeOf(TSourceWindow)) and
  392. {$ifdef linux}
  393. (PSourceWindow(P)^.Editor^.FileName=Name);
  394. {$else}
  395. (UpcaseStr(PSourceWindow(P)^.Editor^.FileName)=UpcaseStr(Name));
  396. {$endif def linux}
  397. end;
  398. begin
  399. EditorWindowFile:=pointer(Desktop^.FirstThat(@EditorWindow));
  400. end;
  401. function GetEditorCurWord(Editor: PEditor): string;
  402. var S: string;
  403. PS,PE: byte;
  404. function Trim(S: string): string;
  405. const TrimChars : set of char = [#0,#9,' ',#255];
  406. begin
  407. while (length(S)>0) and (S[1] in TrimChars) do Delete(S,1,1);
  408. while (length(S)>0) and (S[length(S)] in TrimChars) do Delete(S,length(S),1);
  409. Trim:=S;
  410. end;
  411. const AlphaNum : set of char = ['A'..'Z','0'..'9','_'];
  412. begin
  413. with Editor^ do
  414. begin
  415. {$ifdef EDITORS}
  416. S:='';
  417. {$else}
  418. S:=GetLineText(CurPos.Y);
  419. PS:=CurPos.X; while (PS>0) and (Upcase(S[PS]) in AlphaNum) do Dec(PS);
  420. PE:=CurPos.X; while (PE<length(S)) and (Upcase(S[PE+1]) in AlphaNum) do Inc(PE);
  421. S:=Trim(copy(S,PS+1,PE-PS));
  422. {$endif}
  423. end;
  424. GetEditorCurWord:=S;
  425. end;
  426. {*****************************************************************************
  427. Tab
  428. *****************************************************************************}
  429. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  430. var P: PTabItem;
  431. begin
  432. New(P); FillChar(P^,SizeOf(P^),0);
  433. P^.Next:=ANext; P^.View:=AView;
  434. NewTabItem:=P;
  435. end;
  436. procedure DisposeTabItem(P: PTabItem);
  437. begin
  438. if P<>nil then
  439. begin
  440. if P^.View<>nil then Dispose(P^.View, Done);
  441. Dispose(P);
  442. end;
  443. end;
  444. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  445. var P: PTabDef;
  446. x: byte;
  447. begin
  448. New(P);
  449. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  450. x:=pos('~',AName);
  451. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  452. else P^.ShortCut:=#0;
  453. P^.DefItem:=ADefItem;
  454. NewTabDef:=P;
  455. end;
  456. procedure DisposeTabDef(P: PTabDef);
  457. var PI,X: PTabItem;
  458. begin
  459. DisposeStr(P^.Name);
  460. PI:=P^.Items;
  461. while PI<>nil do
  462. begin
  463. X:=PI^.Next;
  464. DisposeTabItem(PI);
  465. PI:=X;
  466. end;
  467. Dispose(P);
  468. end;
  469. {*****************************************************************************
  470. Reserved Words
  471. *****************************************************************************}
  472. function GetReservedWordCount: integer;
  473. var
  474. Count,I: integer;
  475. begin
  476. Count:=0;
  477. for I:=ord(Low(TokenInfo)) to ord(High(TokenInfo)) do
  478. with TokenInfo[TToken(I)] do
  479. if (str<>'') and (str[1] in['A'..'Z']) then
  480. Inc(Count);
  481. GetReservedWordCount:=Count;
  482. end;
  483. function GetReservedWord(Index: integer): string;
  484. var
  485. Count,Idx,I: integer;
  486. S: string;
  487. begin
  488. Idx:=-1;
  489. Count:=-1;
  490. I:=ord(Low(TokenInfo));
  491. while (I<=ord(High(TokenInfo))) and (Idx=-1) do
  492. with TokenInfo[TToken(I)] do
  493. begin
  494. if (str<>'') and (str[1] in['A'..'Z']) then
  495. begin
  496. Inc(Count);
  497. if Count=Index then
  498. Idx:=I;
  499. end;
  500. Inc(I);
  501. end;
  502. if Idx=-1 then
  503. S:=''
  504. else
  505. S:=TokenInfo[TToken(Idx)].str;
  506. GetReservedWord:=S;
  507. end;
  508. procedure InitReservedWords;
  509. var S,WordS: string;
  510. Idx,I: integer;
  511. begin
  512. New(ReservedWords, Init(50,10));
  513. for I:=1 to GetReservedWordCount do
  514. begin
  515. WordS:=GetReservedWord(I-1); Idx:=length(WordS);
  516. while ReservedWords^.Count<Idx do
  517. ReservedWords^.Insert(NewStr(#0));
  518. S:=ReservedWords^.At(Idx-1)^;
  519. ReservedWords^.AtFree(Idx-1);
  520. ReservedWords^.AtInsert(Idx-1,NewStr(S+WordS+#0));
  521. end;
  522. end;
  523. procedure DoneReservedWords;
  524. begin
  525. if assigned(ReservedWords) then
  526. dispose(ReservedWords,done);
  527. end;
  528. function IsFPReservedWord(S: string): boolean;
  529. var _Is: boolean;
  530. Idx: integer;
  531. P: PString;
  532. begin
  533. Idx:=length(S); _Is:=false;
  534. if (Idx>0) and (ReservedWords<>nil) and (ReservedWords^.Count>=Idx) then
  535. begin
  536. S:=UpcaseStr(S);
  537. P:=ReservedWords^.At(Idx-1);
  538. _Is:=Pos(#0+S+#0,P^)>0;
  539. end;
  540. IsFPReservedWord:=_Is;
  541. end;
  542. {*****************************************************************************
  543. SearchWindow
  544. *****************************************************************************}
  545. function SearchWindowWithNo(No: integer): PWindow;
  546. var P: PSourceWindow;
  547. begin
  548. P:=Message(Desktop,evBroadcast,cmSearchWindow+No,nil);
  549. if pointer(P)=pointer(Desktop) then P:=nil;
  550. SearchWindowWithNo:=P;
  551. end;
  552. function SearchFreeWindowNo: integer;
  553. var No: integer;
  554. begin
  555. No:=1;
  556. while (No<10) and (SearchWindowWithNo(No)<>nil) do
  557. Inc(No);
  558. if No=10 then No:=0;
  559. SearchFreeWindowNo:=No;
  560. end;
  561. {*****************************************************************************
  562. TIntegerLine
  563. *****************************************************************************}
  564. constructor TIntegerLine.Init(var Bounds: TRect; AMin, AMax: longint);
  565. begin
  566. inherited Init(Bounds, Bounds.B.X-Bounds.A.X-1);
  567. Validator:=New(PRangeValidator, Init(AMin, AMax));
  568. end;
  569. {*****************************************************************************
  570. SourceEditor
  571. *****************************************************************************}
  572. {$ifndef EDITORS}
  573. function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  574. var Count: integer;
  575. begin
  576. case SpecClass of
  577. ssCommentPrefix : Count:=3;
  578. ssCommentSingleLinePrefix : Count:=1;
  579. ssCommentSuffix : Count:=2;
  580. ssStringPrefix : Count:=1;
  581. ssStringSuffix : Count:=1;
  582. ssAsmPrefix : Count:=1;
  583. ssAsmSuffix : Count:=1;
  584. ssDirectivePrefix : Count:=1;
  585. ssDirectiveSuffix : Count:=1;
  586. end;
  587. GetSpecSymbolCount:=Count;
  588. end;
  589. function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): string;
  590. var S: string[20];
  591. begin
  592. case SpecClass of
  593. ssCommentPrefix :
  594. case Index of
  595. 0 : S:='{';
  596. 1 : S:='(*';
  597. 2 : S:='//';
  598. end;
  599. ssCommentSingleLinePrefix :
  600. case Index of
  601. 0 : S:='//';
  602. end;
  603. ssCommentSuffix :
  604. case Index of
  605. 0 : S:='}';
  606. 1 : S:='*)';
  607. end;
  608. ssStringPrefix :
  609. S:='''';
  610. ssStringSuffix :
  611. S:='''';
  612. ssAsmPrefix :
  613. S:='asm';
  614. ssAsmSuffix :
  615. S:='end';
  616. ssDirectivePrefix :
  617. S:='{$';
  618. ssDirectiveSuffix :
  619. S:='}';
  620. end;
  621. GetSpecSymbol:=S;
  622. end;
  623. constructor TSourceEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  624. PScrollBar; AIndicator: PIndicator;const AFileName: string);
  625. begin
  626. inherited Init(Bounds,AHScrollBar,AVScrollBar,AIndicator,AFileName);
  627. StoreUndo:=true;
  628. end;
  629. function TSourceEditor.IsReservedWord(const S: string): boolean;
  630. begin
  631. IsReservedWord:=IsFPReservedWord(S);
  632. end;
  633. {$endif EDITORS}
  634. function TSourceEditor.GetLocalMenu: PMenu;
  635. var M: PMenu;
  636. begin
  637. M:=NewMenu(
  638. NewItem('Cu~t~','Shift+Del',kbShiftDel,cmCut,hcCut,
  639. NewItem('~C~opy','Ctrl+Ins',kbCtrlIns,cmCopy,hcCopy,
  640. NewItem('~P~aste','Shift+Ins',kbShiftIns,cmPaste,hcPaste,
  641. NewItem('C~l~ear','Ctrl+Del',kbCtrlDel,cmClear,hcClear,
  642. NewLine(
  643. NewItem('Open ~f~ile at cursor','',kbNoKey,cmOpenAtCursor,hcOpenAtCursor,
  644. NewItem('~B~rowse symbol at cursor','',kbNoKey,cmBrowseAtCursor,hcBrowseAtCursor,
  645. NewItem('Topic ~s~earch','Ctrl+F1',kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  646. NewLine(
  647. NewItem('~O~ptions...','',kbNoKey,cmEditorOptions,hcEditorOptions,
  648. nil)))))))))));
  649. GetLocalMenu:=M;
  650. end;
  651. function TSourceEditor.GetCommandTarget: PView;
  652. begin
  653. GetCommandTarget:=@Self;
  654. end;
  655. function TSourceEditor.CreateLocalMenuView(var Bounds: TRect; M: PMenu): PMenuPopup;
  656. var MV: PAdvancedMenuPopup;
  657. begin
  658. New(MV, Init(Bounds,M));
  659. CreateLocalMenuView:=MV;
  660. end;
  661. procedure TSourceEditor.HandleEvent(var Event: TEvent);
  662. var DontClear: boolean;
  663. S: string;
  664. begin
  665. TranslateMouseClick(@Self,Event);
  666. case Event.What of
  667. evCommand :
  668. begin
  669. DontClear:=false;
  670. case Event.Command of
  671. cmBrowseAtCursor:
  672. begin
  673. S:=LowerCaseStr(GetEditorCurWord(@Self));
  674. OpenOneSymbolBrowser(S);
  675. end;
  676. cmOpenAtCursor :
  677. begin
  678. S:=LowerCaseStr(GetEditorCurWord(@Self));
  679. OpenFileName:=S+'.pp'+ListSeparator+
  680. S+'.pas'+ListSeparator+
  681. S+'.inc';
  682. Message(Application,evCommand,cmOpen,nil);
  683. end;
  684. cmEditorOptions :
  685. Message(Application,evCommand,cmEditorOptions,@Self);
  686. cmHelp :
  687. Message(@Self,evCommand,cmHelpTopicSearch,@Self);
  688. cmHelpTopicSearch :
  689. HelpTopicSearch(@Self);
  690. else DontClear:=true;
  691. end;
  692. if not DontClear then ClearEvent(Event);
  693. end;
  694. end;
  695. inherited HandleEvent(Event);
  696. end;
  697. constructor TFPHeapView.Init(var Bounds: TRect);
  698. begin
  699. inherited Init(Bounds);
  700. Options:=Options or gfGrowHiX or gfGrowHiY;
  701. EventMask:=EventMask or evIdle;
  702. GrowMode:=gfGrowAll;
  703. end;
  704. constructor TFPHeapView.InitKb(var Bounds: TRect);
  705. begin
  706. inherited InitKb(Bounds);
  707. Options:=Options or gfGrowHiX or gfGrowHiY;
  708. EventMask:=EventMask or evIdle;
  709. GrowMode:=gfGrowAll;
  710. end;
  711. procedure TFPHeapView.HandleEvent(var Event: TEvent);
  712. begin
  713. case Event.What of
  714. evIdle :
  715. Update;
  716. end;
  717. inherited HandleEvent(Event);
  718. end;
  719. procedure TFPWindow.HandleEvent(var Event: TEvent);
  720. begin
  721. case Event.What of
  722. evBroadcast :
  723. case Event.Command of
  724. cmUpdate :
  725. ReDraw;
  726. cmSearchWindow+1..cmSearchWindow+99 :
  727. if (Event.Command-cmSearchWindow=Number) then
  728. ClearEvent(Event);
  729. end;
  730. end;
  731. inherited HandleEvent(Event);
  732. end;
  733. function TFPHelpViewer.GetLocalMenu: PMenu;
  734. var M: PMenu;
  735. begin
  736. M:=NewMenu(
  737. NewItem('C~o~ntents','',kbNoKey,cmHelpContents,hcHelpContents,
  738. NewItem('~I~ndex','Shift+F1',kbShiftF1,cmHelpIndex,hcHelpIndex,
  739. NewItem('~T~opic search','Ctrl+F1',kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  740. NewItem('~P~revious topic','Alt+F1',kbAltF1,cmHelpPrevTopic,hcHelpPrevTopic,
  741. NewLine(
  742. NewItem('~C~opy','Ctrl+Ins',kbCtrlIns,cmCopy,hcCopy,
  743. nil)))))));
  744. GetLocalMenu:=M;
  745. end;
  746. function TFPHelpViewer.GetCommandTarget: PView;
  747. begin
  748. GetCommandTarget:=Application;
  749. end;
  750. constructor TFPHelpWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ASourceFileID: word;
  751. AContext: THelpCtx; ANumber: Integer);
  752. begin
  753. inherited Init(Bounds,ATitle,ASourceFileID,AContext,ANumber);
  754. HelpCtx:=hcHelpWindow;
  755. HideOnClose:=true;
  756. end;
  757. procedure TFPHelpWindow.InitHelpView;
  758. var R: TRect;
  759. begin
  760. GetExtent(R); R.Grow(-1,-1);
  761. HelpView:=New(PFPHelpViewer, Init(R, HSB, VSB));
  762. HelpView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  763. end;
  764. procedure TFPHelpWindow.Show;
  765. begin
  766. inherited Show;
  767. if GetState(sfVisible) and (Number=0) then
  768. begin
  769. Number:=SearchFreeWindowNo;
  770. ReDraw;
  771. end;
  772. end;
  773. procedure TFPHelpWindow.Hide;
  774. begin
  775. inherited Hide;
  776. if GetState(sfVisible)=false then
  777. Number:=0;
  778. end;
  779. procedure TFPHelpWindow.HandleEvent(var Event: TEvent);
  780. begin
  781. case Event.What of
  782. evBroadcast :
  783. case Event.Command of
  784. cmUpdate :
  785. ReDraw;
  786. cmSearchWindow+1..cmSearchWindow+99 :
  787. if (Event.Command-cmSearchWindow=Number) then
  788. ClearEvent(Event);
  789. end;
  790. end;
  791. inherited HandleEvent(Event);
  792. end;
  793. function TFPHelpWindow.GetPalette: PPalette;
  794. const P: string[length(CIDEHelpDialog)] = CIDEHelpDialog;
  795. begin
  796. GetPalette:=@P;
  797. end;
  798. constructor TSourceWindow.Init(var Bounds: TRect; AFileName: string);
  799. var HSB,VSB: PScrollBar;
  800. R: TRect;
  801. LoadFile: boolean;
  802. begin
  803. inherited Init(Bounds,AFileName,SearchFreeWindowNo);
  804. Options:=Options or ofTileAble;
  805. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  806. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  807. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  808. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  809. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  810. New(Indicator, Init(R));
  811. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  812. Insert(Indicator);
  813. GetExtent(R); R.Grow(-1,-1);
  814. LoadFile:=AFileName<>'';
  815. if not LoadFile then
  816. begin SetTitle('noname'+IntToStrZ(NonameCount,2)+'.pas'); Inc(NonameCount); end;
  817. New(Editor, Init(R, HSB, VSB, Indicator,AFileName));
  818. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  819. if LoadFile then
  820. if Editor^.LoadFile=false then
  821. ErrorBox(#3'Error reading file.',nil);
  822. Insert(Editor);
  823. UpdateTitle;
  824. end;
  825. procedure TSourceWindow.UpdateTitle;
  826. var Name: string;
  827. begin
  828. if Editor^.FileName<>'' then
  829. begin Name:=SmartPath(Editor^.FileName); SetTitle(Name); end;
  830. end;
  831. procedure TSourceWindow.SetTitle(ATitle: string);
  832. begin
  833. if Title<>nil then DisposeStr(Title);
  834. Title:=NewStr(ATitle);
  835. Frame^.DrawView;
  836. end;
  837. procedure TSourceWindow.HandleEvent(var Event: TEvent);
  838. var DontClear: boolean;
  839. begin
  840. case Event.What of
  841. evBroadcast :
  842. case Event.Command of
  843. cmUpdate :
  844. Update;
  845. cmUpdateTitle :
  846. UpdateTitle;
  847. cmSearchWindow :
  848. if @Self<>ClipboardWindow then
  849. ClearEvent(Event);
  850. end;
  851. evCommand :
  852. begin
  853. DontClear:=false;
  854. case Event.Command of
  855. cmSave :
  856. if Editor^.IsClipboard=false then
  857. Editor^.Save;
  858. cmSaveAs :
  859. if Editor^.IsClipboard=false then
  860. Editor^.SaveAs;
  861. else DontClear:=true;
  862. end;
  863. if DontClear=false then ClearEvent(Event);
  864. end;
  865. end;
  866. inherited HandleEvent(Event);
  867. end;
  868. procedure TSourceWindow.SetState(AState: Word; Enable: Boolean);
  869. var OldState: word;
  870. begin
  871. OldState:=State;
  872. inherited SetState(AState,Enable);
  873. if ((AState xor State) and sfActive)<>0 then
  874. UpdateCommands;
  875. end;
  876. procedure TSourceWindow.UpdateCommands;
  877. var Active: boolean;
  878. begin
  879. Active:=GetState(sfActive);
  880. if Editor^.IsClipboard=false then
  881. begin
  882. SetCmdState(SourceCmds+CompileCmds,Active);
  883. SetCmdState(EditorCmds,Active);
  884. end;
  885. if Active=false then
  886. SetCmdState(ToClipCmds+FromClipCmds+NulClipCmds+UndoCmds,false);
  887. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  888. end;
  889. procedure TSourceWindow.Update;
  890. begin
  891. ReDraw;
  892. end;
  893. function TSourceWindow.GetPalette: PPalette;
  894. const P: string[length(CSourceWindow)] = CSourceWindow;
  895. begin
  896. GetPalette:=@P;
  897. end;
  898. constructor TSourceWindow.Load(var S: TStream);
  899. begin
  900. inherited Load(S);
  901. GetSubViewPtr(S,Indicator);
  902. GetSubViewPtr(S,Editor);
  903. end;
  904. procedure TSourceWindow.Store(var S: TStream);
  905. begin
  906. inherited Store(S);
  907. PutSubViewPtr(S,Indicator);
  908. PutSubViewPtr(S,Editor);
  909. end;
  910. destructor TSourceWindow.Done;
  911. begin
  912. Message(Application,evBroadcast,cmSourceWndClosing,@Self);
  913. inherited Done;
  914. Message(Application,evBroadcast,cmUpdate,@Self);
  915. end;
  916. function TGDBSourceEditor.Valid(Command: Word): Boolean;
  917. var OK: boolean;
  918. begin
  919. OK:=TCodeEditor.Valid(Command);
  920. { do NOT ask for save !!
  921. if OK and ((Command=cmClose) or (Command=cmQuit)) then
  922. if IsClipboard=false then
  923. OK:=SaveAsk; }
  924. Valid:=OK;
  925. end;
  926. procedure TGDBSourceEditor.AddLine(const S: string);
  927. begin
  928. if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
  929. inherited AddLine(S);
  930. LimitsChanged;
  931. end;
  932. procedure TGDBSourceEditor.AddErrorLine(const S: string);
  933. begin
  934. if Silent then exit;
  935. inherited AddLine(S);
  936. { display like breakpoints in red }
  937. Lines^.At(GetLineCount-1)^.IsBreakpoint:=true;
  938. LimitsChanged;
  939. end;
  940. function TGDBSourceEditor.InsertLine: Sw_integer;
  941. Var
  942. S : string;
  943. begin
  944. if IsReadOnly then begin InsertLine:=-1; Exit; end;
  945. if CurPos.Y<GetLineCount then S:=GetLineText(CurPos.Y) else S:='';
  946. s:=Copy(S,1,CurPos.X);
  947. if assigned(Debugger) then
  948. if S<>'' then
  949. begin
  950. LastCommand:=S;
  951. { should be true only if we are at the end ! }
  952. IgnoreStringAtEnd:=(CurPos.Y=GetLineCount-1) and (CurPos.X=length(GetDisplayText(GetLineCount-1)));
  953. Debugger^.Command(S);
  954. IgnoreStringAtEnd:=false;
  955. end
  956. else if AutoRepeat then
  957. Debugger^.Command(LastCommand);
  958. InsertLine:=inherited InsertLine;
  959. end;
  960. constructor TGDBWindow.Init(var Bounds: TRect);
  961. var HSB,VSB: PScrollBar;
  962. R: TRect;
  963. begin
  964. inherited Init(Bounds,'GDB window',SearchFreeWindowNo);
  965. Options:=Options or ofTileAble;
  966. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  967. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  968. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  969. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  970. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  971. New(Indicator, Init(R));
  972. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  973. Insert(Indicator);
  974. GetExtent(R); R.Grow(-1,-1);
  975. New(Editor, Init(R, HSB, VSB, nil, GDBOutputFile));
  976. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  977. if ExistsFile(GDBOutputFile) then
  978. begin
  979. if Editor^.LoadFile=false then
  980. ErrorBox(#3'Error reading file.',nil);
  981. end
  982. else
  983. { Empty files are buggy !! }
  984. Editor^.AddLine('');
  985. Insert(Editor);
  986. if assigned(Debugger) then
  987. Debugger^.Command('set width '+IntToStr(Size.X-1));
  988. Editor^.silent:=false;
  989. Editor^.AutoRepeat:=true;
  990. end;
  991. destructor TGDBWindow.Done;
  992. begin
  993. if @Self=GDBWindow then
  994. GDBWindow:=nil;
  995. inherited Done;
  996. end;
  997. function TGDBWindow.GetPalette: PPalette;
  998. const P: string[length(CSourceWindow)] = CSourceWindow;
  999. begin
  1000. GetPalette:=@P;
  1001. end;
  1002. procedure TGDBWindow.WriteOutputText(Buf : pchar);
  1003. begin
  1004. {selected normal color ?}
  1005. WriteText(Buf,false);
  1006. end;
  1007. procedure TGDBWindow.WriteErrorText(Buf : pchar);
  1008. begin
  1009. {selected normal color ?}
  1010. WriteText(Buf,true);
  1011. end;
  1012. procedure TGDBWindow.WriteString(Const S : string);
  1013. begin
  1014. Editor^.AddLine(S);
  1015. end;
  1016. procedure TGDBWindow.WriteErrorString(Const S : string);
  1017. begin
  1018. Editor^.AddErrorLine(S);
  1019. end;
  1020. procedure TGDBWindow.WriteText(Buf : pchar;IsError : boolean);
  1021. var p,pe : pchar;
  1022. s : string;
  1023. begin
  1024. p:=buf;
  1025. DeskTop^.Lock;
  1026. While assigned(p) do
  1027. begin
  1028. pe:=strscan(p,#10);
  1029. if pe<>nil then
  1030. pe^:=#0;
  1031. s:=strpas(p);
  1032. If IsError then
  1033. Editor^.AddErrorLine(S)
  1034. else
  1035. Editor^.AddLine(S);
  1036. { restore for dispose }
  1037. if pe<>nil then
  1038. pe^:=#10;
  1039. if pe=nil then
  1040. p:=nil
  1041. else
  1042. begin
  1043. p:=pe;
  1044. inc(p);
  1045. end;
  1046. end;
  1047. DeskTop^.Unlock;
  1048. Editor^.Draw;
  1049. end;
  1050. constructor TClipboardWindow.Init;
  1051. var R: TRect;
  1052. HSB,VSB: PScrollBar;
  1053. begin
  1054. Desktop^.GetExtent(R);
  1055. inherited Init(R, '');
  1056. SetTitle('Clipboard');
  1057. HelpCtx:=hcClipboardWindow;
  1058. Number:=wnNoNumber;
  1059. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  1060. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  1061. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  1062. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  1063. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  1064. New(Indicator, Init(R));
  1065. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  1066. Insert(Indicator);
  1067. GetExtent(R); R.Grow(-1,-1);
  1068. New(Editor, Init(R, HSB, VSB, Indicator, ''));
  1069. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1070. Insert(Editor);
  1071. Hide;
  1072. Clipboard:=Editor;
  1073. end;
  1074. procedure TClipboardWindow.Show;
  1075. begin
  1076. inherited Show;
  1077. if GetState(sfVisible) and (Number=0) then
  1078. begin
  1079. Number:=SearchFreeWindowNo;
  1080. ReDraw;
  1081. end;
  1082. end;
  1083. procedure TClipboardWindow.Hide;
  1084. begin
  1085. inherited Hide;
  1086. if GetState(sfVisible)=false then Number:=0;
  1087. end;
  1088. procedure TClipboardWindow.Close;
  1089. begin
  1090. Hide;
  1091. end;
  1092. constructor TClipboardWindow.Load(var S: TStream);
  1093. begin
  1094. inherited Load(S);
  1095. Clipboard:=Editor;
  1096. end;
  1097. procedure TClipboardWindow.Store(var S: TStream);
  1098. begin
  1099. inherited Store(S);
  1100. end;
  1101. destructor TClipboardWindow.Done;
  1102. begin
  1103. inherited Done;
  1104. Clipboard:=nil;
  1105. ClipboardWindow:=nil;
  1106. end;
  1107. constructor TMessageListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  1108. begin
  1109. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  1110. GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY;
  1111. New(ModuleNames, Init(50,100));
  1112. NoSelection:=true;
  1113. end;
  1114. function TMessageListBox.GetLocalMenu: PMenu;
  1115. var M: PMenu;
  1116. begin
  1117. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  1118. M:=NewMenu(
  1119. NewItem('~C~lear','',kbNoKey,cmMsgClear,hcMsgClear,
  1120. NewLine(
  1121. NewItem('~G~oto source','',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  1122. NewItem('~T~rack source','',kbNoKey,cmMsgTrackSource,hcMsgTrackSource,
  1123. nil)))));
  1124. GetLocalMenu:=M;
  1125. end;
  1126. procedure TMessageListBox.HandleEvent(var Event: TEvent);
  1127. var DontClear: boolean;
  1128. begin
  1129. case Event.What of
  1130. evKeyDown :
  1131. begin
  1132. DontClear:=false;
  1133. case Event.KeyCode of
  1134. kbEnter :
  1135. Message(@Self,evCommand,cmMsgGotoSource,nil);
  1136. else
  1137. DontClear:=true;
  1138. end;
  1139. if not DontClear then
  1140. ClearEvent(Event);
  1141. end;
  1142. evBroadcast :
  1143. case Event.Command of
  1144. cmListItemSelected :
  1145. if Event.InfoPtr=@Self then
  1146. Message(@Self,evCommand,cmMsgTrackSource,nil);
  1147. end;
  1148. evCommand :
  1149. begin
  1150. DontClear:=false;
  1151. case Event.Command of
  1152. cmMsgGotoSource :
  1153. if Range>0 then
  1154. GotoSource;
  1155. cmMsgTrackSource :
  1156. if Range>0 then
  1157. TrackSource;
  1158. cmMsgClear :
  1159. Clear;
  1160. else
  1161. DontClear:=true;
  1162. end;
  1163. if not DontClear then
  1164. ClearEvent(Event);
  1165. end;
  1166. end;
  1167. inherited HandleEvent(Event);
  1168. end;
  1169. procedure TMessageListBox.AddItem(P: PMessageItem);
  1170. var W : integer;
  1171. begin
  1172. if List=nil then New(List, Init(500,500));
  1173. W:=length(P^.GetText(255));
  1174. if W>MaxWidth then
  1175. begin
  1176. MaxWidth:=W;
  1177. if HScrollBar<>nil then
  1178. HScrollBar^.SetRange(0,MaxWidth);
  1179. end;
  1180. List^.Insert(P);
  1181. SetRange(List^.Count);
  1182. if Focused=List^.Count-1-1 then
  1183. FocusItem(List^.Count-1);
  1184. DrawView;
  1185. end;
  1186. function TMessageListBox.AddModuleName(const Name: string): PString;
  1187. var P: PString;
  1188. begin
  1189. if ModuleNames<>nil then
  1190. P:=ModuleNames^.Add(Name)
  1191. else
  1192. P:=nil;
  1193. AddModuleName:=P;
  1194. end;
  1195. function TMessageListBox.GetText(Item,MaxLen: Sw_Integer): String;
  1196. var P: PMessageItem;
  1197. S: string;
  1198. begin
  1199. P:=List^.At(Item);
  1200. S:=P^.GetText(MaxLen);
  1201. GetText:=copy(S,1,MaxLen);
  1202. end;
  1203. procedure TMessageListBox.Clear;
  1204. begin
  1205. if assigned(List) then
  1206. Dispose(List, Done);
  1207. List:=nil;
  1208. MaxWidth:=0;
  1209. if assigned(ModuleNames) then
  1210. ModuleNames^.FreeAll;
  1211. SetRange(0); DrawView;
  1212. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1213. end;
  1214. procedure TMessageListBox.TrackSource;
  1215. var W: PSourceWindow;
  1216. P: PMessageItem;
  1217. R: TRect;
  1218. Row,Col: sw_integer;
  1219. begin
  1220. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1221. if Range=0 then Exit;
  1222. P:=List^.At(Focused);
  1223. if P^.Row=0 then Exit;
  1224. Desktop^.Lock;
  1225. GetNextEditorBounds(R);
  1226. {$ifdef OLDCOMP}
  1227. if Assigned(Owner) and (Owner=pointer(ProgramInfoWindow)) then
  1228. {$endif}
  1229. R.B.Y:=Owner^.Origin.Y;
  1230. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  1231. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  1232. W:=EditorWindowFile(P^.GetModuleName);
  1233. if assigned(W) then
  1234. begin
  1235. W^.GetExtent(R);
  1236. {$ifdef OLDCOMP}
  1237. if Assigned(Owner) and (Owner=pointer(ProgramInfoWindow)) then
  1238. {$endif}
  1239. R.B.Y:=Owner^.Origin.Y;
  1240. W^.ChangeBounds(R);
  1241. W^.Editor^.SetCurPtr(Col,Row);
  1242. end
  1243. else
  1244. W:=TryToOpenFile(@R,P^.GetModuleName,Col,Row,true);
  1245. if W<>nil then
  1246. begin
  1247. W^.Select;
  1248. W^.Editor^.TrackCursor(true);
  1249. W^.Editor^.SetHighlightRow(Row);
  1250. end;
  1251. if Assigned(Owner) then
  1252. Owner^.Select;
  1253. Desktop^.UnLock;
  1254. end;
  1255. procedure TMessageListBox.GotoSource;
  1256. var W: PSourceWindow;
  1257. P: PMessageItem;
  1258. Row,Col: sw_integer;
  1259. begin
  1260. Message(Application,evBroadcast,cmClearLineHighlights,@Self);
  1261. if Range=0 then Exit;
  1262. P:=List^.At(Focused);
  1263. if P^.Row=0 then Exit;
  1264. Desktop^.Lock;
  1265. if P^.Row>0 then Row:=P^.Row-1 else Row:=0;
  1266. if P^.Col>0 then Col:=P^.Col-1 else Col:=0;
  1267. W:=TryToOpenFile(nil,P^.GetModuleName,Col,Row,true);
  1268. Message(Owner,evCommand,cmClose,nil);
  1269. Desktop^.UnLock;
  1270. end;
  1271. procedure TMessageListBox.Draw;
  1272. var
  1273. I, J, Item: Sw_Integer;
  1274. NormalColor, SelectedColor, FocusedColor, Color: Word;
  1275. ColWidth, CurCol, Indent: Integer;
  1276. B: TDrawBuffer;
  1277. Text: String;
  1278. SCOff: Byte;
  1279. TC: byte;
  1280. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  1281. begin
  1282. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  1283. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  1284. begin
  1285. NormalColor := GetColor(1);
  1286. FocusedColor := GetColor(3);
  1287. SelectedColor := GetColor(4);
  1288. end else
  1289. begin
  1290. NormalColor := GetColor(2);
  1291. SelectedColor := GetColor(4);
  1292. end;
  1293. if Transparent then
  1294. begin MT(NormalColor); MT(SelectedColor); end;
  1295. if NoSelection then
  1296. SelectedColor:=NormalColor;
  1297. if HScrollBar <> nil then Indent := HScrollBar^.Value
  1298. else Indent := 0;
  1299. ColWidth := Size.X div NumCols + 1;
  1300. for I := 0 to Size.Y - 1 do
  1301. begin
  1302. for J := 0 to NumCols-1 do
  1303. begin
  1304. Item := J*Size.Y + I + TopItem;
  1305. CurCol := J*ColWidth;
  1306. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  1307. (Focused = Item) and (Range > 0) then
  1308. begin
  1309. Color := FocusedColor;
  1310. SetCursor(CurCol+1,I);
  1311. SCOff := 0;
  1312. end
  1313. else if (Item < Range) and IsSelected(Item) then
  1314. begin
  1315. Color := SelectedColor;
  1316. SCOff := 2;
  1317. end
  1318. else
  1319. begin
  1320. Color := NormalColor;
  1321. SCOff := 4;
  1322. end;
  1323. MoveChar(B[CurCol], ' ', Color, ColWidth);
  1324. if Item < Range then
  1325. begin
  1326. Text := GetText(Item, ColWidth + Indent);
  1327. Text := Copy(Text,Indent,ColWidth);
  1328. MoveStr(B[CurCol+1], Text, Color);
  1329. if ShowMarkers then
  1330. begin
  1331. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  1332. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  1333. end;
  1334. end;
  1335. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  1336. end;
  1337. WriteLine(0, I, Size.X, 1, B);
  1338. end;
  1339. end;
  1340. constructor TMessageListBox.Load(var S: TStream);
  1341. begin
  1342. inherited Load(S);
  1343. end;
  1344. procedure TMessageListBox.Store(var S: TStream);
  1345. var OL: PCollection;
  1346. begin
  1347. OL:=List;
  1348. New(List, Init(1,1));
  1349. inherited Store(S);
  1350. Dispose(List, Done);
  1351. List:=OL;
  1352. { ^^^ nasty trick - has anyone a better idea how to avoid storing the
  1353. collection? Pasting here a modified version of TListBox.Store+
  1354. TAdvancedListBox.Store isn't a better solution, since by eventually
  1355. changing the obj-hierarchy you'll always have to modify this, too - BG }
  1356. end;
  1357. destructor TMessageListBox.Done;
  1358. begin
  1359. inherited Done;
  1360. if List<>nil then Dispose(List, Done);
  1361. if ModuleNames<>nil then Dispose(ModuleNames, Done);
  1362. end;
  1363. constructor TMessageItem.Init(AClass: longint; const AText: string; AModule: PString; ARow, ACol: sw_integer);
  1364. begin
  1365. inherited Init;
  1366. TClass:=AClass;
  1367. Text:=NewStr(AText);
  1368. Module:=AModule;
  1369. Row:=ARow; Col:=ACol;
  1370. end;
  1371. function TMessageItem.GetText(MaxLen: Sw_integer): string;
  1372. var S: string;
  1373. begin
  1374. if Text=nil then S:='' else S:=Text^;
  1375. if (Module<>nil) then
  1376. S:=NameAndExtOf(Module^)+'('+IntToStr(Row)+') '+S;
  1377. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  1378. GetText:=S;
  1379. end;
  1380. procedure TMessageItem.Selected;
  1381. begin
  1382. end;
  1383. function TMessageItem.GetModuleName: string;
  1384. begin
  1385. GetModuleName:=GetStr(Module);
  1386. end;
  1387. destructor TMessageItem.Done;
  1388. begin
  1389. inherited Done;
  1390. if Text<>nil then DisposeStr(Text);
  1391. { if Module<>nil then DisposeStr(Module);}
  1392. end;
  1393. {$ifdef OLDCOMP}
  1394. function TCompilerMessage.GetText(MaxLen: Integer): String;
  1395. var ClassS: string[20];
  1396. S: string;
  1397. begin
  1398. if TClass=
  1399. V_Fatal then ClassS:='Fatal' else if TClass =
  1400. V_Error then ClassS:='Error' else if TClass =
  1401. V_Normal then ClassS:='' else if TClass =
  1402. V_Warning then ClassS:='Warning' else if TClass =
  1403. V_Note then ClassS:='Note' else if TClass =
  1404. V_Hint then ClassS:='Hint' else if TClass =
  1405. V_Macro then ClassS:='Macro' else if TClass =
  1406. V_Procedure then ClassS:='Procedure' else if TClass =
  1407. V_Conditional then ClassS:='Conditional' else if TClass =
  1408. V_Info then ClassS:='Info' else if TClass =
  1409. V_Status then ClassS:='Status' else if TClass =
  1410. V_Used then ClassS:='Used' else if TClass =
  1411. V_Tried then ClassS:='Tried' else if TClass =
  1412. V_Debug then ClassS:='Debug'
  1413. else
  1414. ClassS:='???';
  1415. if ClassS<>'' then
  1416. ClassS:=RExpand(ClassS,0)+': ';
  1417. S:=ClassS;
  1418. if (Module<>nil) {and (ID<>0)} then
  1419. S:=S+NameAndExtOf(Module^)+'('+IntToStr(Row)+') ';
  1420. if Text<>nil then S:=S+Text^;
  1421. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  1422. GetText:=S;
  1423. end;
  1424. {$endif}
  1425. constructor TProgramInfoWindow.Init;
  1426. var R,R2: TRect;
  1427. HSB,VSB: PScrollBar;
  1428. ST: PStaticText;
  1429. C: word;
  1430. const White = 15;
  1431. begin
  1432. Desktop^.GetExtent(R); R.A.Y:=R.B.Y-13;
  1433. inherited Init(R, 'Program Information', wnNoNumber);
  1434. HelpCtx:=hcInfoWindow;
  1435. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+3;
  1436. C:=((Desktop^.GetColor(32+6) and $f0) or White)*256+Desktop^.GetColor(32+6);
  1437. New(InfoST, Init(R,'', C)); InfoST^.GrowMode:=gfGrowHiX;
  1438. InfoST^.DontWrap:=true;
  1439. Insert(InfoST);
  1440. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,3); R.B.Y:=R.A.Y+1;
  1441. New(ST, Init(R, CharStr('Ä', MaxViewWidth))); ST^.GrowMode:=gfGrowHiX; Insert(ST);
  1442. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,4);
  1443. R2.Copy(R); Inc(R2.B.Y); R2.A.Y:=R2.B.Y-1;
  1444. New(HSB, Init(R2)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX; Insert(HSB);
  1445. R2.Copy(R); Inc(R2.B.X); R2.A.X:=R2.B.X-1;
  1446. New(VSB, Init(R2)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  1447. New(LogLB, Init(R,HSB,VSB));
  1448. LogLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1449. LogLB^.Transparent:=true;
  1450. Insert(LogLB);
  1451. Update;
  1452. end;
  1453. procedure TProgramInfoWindow.AddMessage(AClass: longint; Msg, Module: string; Line, Column: longint);
  1454. begin
  1455. if AClass>=V_Info then Line:=0;
  1456. LogLB^.AddItem(New(PCompilerMessage, Init(AClass, Msg, LogLB^.AddModuleName(Module), Line, Column)));
  1457. end;
  1458. procedure TProgramInfoWindow.ClearMessages;
  1459. begin
  1460. LogLB^.Clear;
  1461. ReDraw;
  1462. end;
  1463. procedure TProgramInfoWindow.SizeLimits(var Min, Max: TPoint);
  1464. begin
  1465. inherited SizeLimits(Min,Max);
  1466. Min.X:=30; Min.Y:=9;
  1467. end;
  1468. procedure TProgramInfoWindow.Close;
  1469. begin
  1470. Hide;
  1471. end;
  1472. procedure TProgramInfoWindow.HandleEvent(var Event: TEvent);
  1473. begin
  1474. case Event.What of
  1475. evBroadcast :
  1476. case Event.Command of
  1477. cmUpdate :
  1478. Update;
  1479. end;
  1480. end;
  1481. inherited HandleEvent(Event);
  1482. end;
  1483. procedure TProgramInfoWindow.Update;
  1484. begin
  1485. InfoST^.SetText(
  1486. {#13+ }
  1487. ' Current module : '+MainFile+#13+
  1488. ' Last exit code : '+IntToStr(LastExitCode)+#13+
  1489. ' Available memory : '+IntToStrL(MemAvail div 1024,5)+'K'+#13+
  1490. ''
  1491. );
  1492. end;
  1493. destructor TProgramInfoWindow.Done;
  1494. begin
  1495. inherited Done;
  1496. ProgramInfoWindow:=nil;
  1497. end;
  1498. constructor TTab.Init(var Bounds: TRect; ATabDef: PTabDef);
  1499. begin
  1500. inherited Init(Bounds);
  1501. Options:=Options or ofSelectable or ofFirstClick or ofPreProcess or ofPostProcess;
  1502. GrowMode:=gfGrowHiX+gfGrowHiY+gfGrowRel;
  1503. TabDefs:=ATabDef;
  1504. ActiveDef:=-1;
  1505. SelectTab(0);
  1506. ReDraw;
  1507. end;
  1508. function TTab.TabCount: integer;
  1509. var i: integer;
  1510. P: PTabDef;
  1511. begin
  1512. I:=0; P:=TabDefs;
  1513. while (P<>nil) do
  1514. begin
  1515. Inc(I);
  1516. P:=P^.Next;
  1517. end;
  1518. TabCount:=I;
  1519. end;
  1520. function TTab.AtTab(Index: integer): PTabDef;
  1521. var i: integer;
  1522. P: PTabDef;
  1523. begin
  1524. i:=0; P:=TabDefs;
  1525. while (I<Index) do
  1526. begin
  1527. if P=nil then RunError($AA);
  1528. P:=P^.Next;
  1529. Inc(i);
  1530. end;
  1531. AtTab:=P;
  1532. end;
  1533. procedure TTab.SelectTab(Index: integer);
  1534. var P: PTabItem;
  1535. V: PView;
  1536. begin
  1537. if ActiveDef<>Index then
  1538. begin
  1539. if Owner<>nil then Owner^.Lock;
  1540. Lock;
  1541. { --- Update --- }
  1542. if TabDefs<>nil then
  1543. begin
  1544. DefCount:=1;
  1545. while AtTab(DefCount-1)^.Next<>nil do Inc(DefCount);
  1546. end
  1547. else DefCount:=0;
  1548. if ActiveDef<>-1 then
  1549. begin
  1550. P:=AtTab(ActiveDef)^.Items;
  1551. while P<>nil do
  1552. begin
  1553. if P^.View<>nil then Delete(P^.View);
  1554. P:=P^.Next;
  1555. end;
  1556. end;
  1557. ActiveDef:=Index;
  1558. P:=AtTab(ActiveDef)^.Items;
  1559. while P<>nil do
  1560. begin
  1561. if P^.View<>nil then Insert(P^.View);
  1562. P:=P^.Next;
  1563. end;
  1564. V:=AtTab(ActiveDef)^.DefItem;
  1565. if V<>nil then V^.Select;
  1566. ReDraw;
  1567. { --- Update --- }
  1568. UnLock;
  1569. if Owner<>nil then Owner^.UnLock;
  1570. DrawView;
  1571. end;
  1572. end;
  1573. procedure TTab.ChangeBounds(var Bounds: TRect);
  1574. var D: TPoint;
  1575. procedure DoCalcChange(P: PView); {$ifndef FPC}far;{$endif}
  1576. var
  1577. R: TRect;
  1578. begin
  1579. if P^.Owner=nil then Exit; { it think this is a bug in TV }
  1580. P^.CalcBounds(R, D);
  1581. P^.ChangeBounds(R);
  1582. end;
  1583. var
  1584. P: PTabItem;
  1585. I: integer;
  1586. begin
  1587. D.X := Bounds.B.X - Bounds.A.X - Size.X;
  1588. D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  1589. inherited ChangeBounds(Bounds);
  1590. for I:=0 to TabCount-1 do
  1591. if I<>ActiveDef then
  1592. begin
  1593. P:=AtTab(I)^.Items;
  1594. while P<>nil do
  1595. begin
  1596. if P^.View<>nil then DoCalcChange(P^.View);
  1597. P:=P^.Next;
  1598. end;
  1599. end;
  1600. end;
  1601. procedure TTab.HandleEvent(var Event: TEvent);
  1602. var Index : integer;
  1603. I : integer;
  1604. X : integer;
  1605. Len : byte;
  1606. P : TPoint;
  1607. V : PView;
  1608. CallOrig: boolean;
  1609. LastV : PView;
  1610. FirstV: PView;
  1611. function FirstSelectable: PView;
  1612. var
  1613. FV : PView;
  1614. begin
  1615. FV := First;
  1616. while (FV<>nil) and ((FV^.Options and ofSelectable)=0) and (FV<>Last) do
  1617. FV:=FV^.Next;
  1618. if FV<>nil then
  1619. if (FV^.Options and ofSelectable)=0 then FV:=nil;
  1620. FirstSelectable:=FV;
  1621. end;
  1622. function LastSelectable: PView;
  1623. var
  1624. LV : PView;
  1625. begin
  1626. LV := Last;
  1627. while (LV<>nil) and ((LV^.Options and ofSelectable)=0) and (LV<>First) do
  1628. LV:=LV^.Prev;
  1629. if LV<>nil then
  1630. if (LV^.Options and ofSelectable)=0 then LV:=nil;
  1631. LastSelectable:=LV;
  1632. end;
  1633. begin
  1634. if (Event.What and evMouseDown)<>0 then
  1635. begin
  1636. MakeLocal(Event.Where,P);
  1637. if P.Y<3 then
  1638. begin
  1639. Index:=-1; X:=1;
  1640. for i:=0 to DefCount-1 do
  1641. begin
  1642. Len:=CStrLen(AtTab(i)^.Name^);
  1643. if (P.X>=X) and (P.X<=X+Len+1) then Index:=i;
  1644. X:=X+Len+3;
  1645. end;
  1646. if Index<>-1 then
  1647. SelectTab(Index);
  1648. end;
  1649. end;
  1650. if Event.What=evKeyDown then
  1651. begin
  1652. Index:=-1;
  1653. case Event.KeyCode of
  1654. kbTab,kbShiftTab :
  1655. if GetState(sfSelected) then
  1656. begin
  1657. if Current<>nil then
  1658. begin
  1659. LastV:=LastSelectable; FirstV:=FirstSelectable;
  1660. if ((Current=LastV) or (Current=PLabel(LastV)^.Link)) and (Event.KeyCode=kbShiftTab) then
  1661. begin
  1662. if Owner<>nil then Owner^.SelectNext(true);
  1663. end else
  1664. if ((Current=FirstV) or (Current=PLabel(FirstV)^.Link)) and (Event.KeyCode=kbTab) then
  1665. begin
  1666. Lock;
  1667. if Owner<>nil then Owner^.SelectNext(false);
  1668. UnLock;
  1669. end else
  1670. SelectNext(Event.KeyCode=kbShiftTab);
  1671. ClearEvent(Event);
  1672. end;
  1673. end;
  1674. else
  1675. for I:=0 to DefCount-1 do
  1676. begin
  1677. if Upcase(GetAltChar(Event.KeyCode))=AtTab(I)^.ShortCut
  1678. then begin
  1679. Index:=I;
  1680. ClearEvent(Event);
  1681. Break;
  1682. end;
  1683. end;
  1684. end;
  1685. if Index<>-1 then
  1686. begin
  1687. Select;
  1688. SelectTab(Index);
  1689. V:=AtTab(ActiveDef)^.DefItem;
  1690. if V<>nil then V^.Focus;
  1691. end;
  1692. end;
  1693. CallOrig:=true;
  1694. if Event.What=evKeyDown then
  1695. begin
  1696. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  1697. then
  1698. else CallOrig:=false;
  1699. end;
  1700. if CallOrig then inherited HandleEvent(Event);
  1701. end;
  1702. function TTab.GetPalette: PPalette;
  1703. begin
  1704. GetPalette:=nil;
  1705. end;
  1706. procedure TTab.Draw;
  1707. var B : TDrawBuffer;
  1708. i : integer;
  1709. C1,C2,C3,C : word;
  1710. HeaderLen : integer;
  1711. X,X2 : integer;
  1712. Name : PString;
  1713. ActiveKPos : integer;
  1714. ActiveVPos : integer;
  1715. FC : char;
  1716. ClipR : TRect;
  1717. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  1718. var i: integer;
  1719. begin
  1720. if Y+H>Size.Y then H:=Size.Y-Y;
  1721. if X+W>Size.X then W:=Size.X-X;
  1722. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  1723. else for i:=1 to H do
  1724. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  1725. end;
  1726. procedure ClearBuf;
  1727. begin
  1728. MoveChar(B,' ',C1,Size.X);
  1729. end;
  1730. begin
  1731. if InDraw then Exit;
  1732. InDraw:=true;
  1733. { - Start of TGroup.Draw - }
  1734. if Buffer = nil then
  1735. begin
  1736. GetBuffer;
  1737. end;
  1738. { - Start of TGroup.Draw - }
  1739. C1:=GetColor(1); C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256; C3:=GetColor(8)+GetColor({9}8)*256;
  1740. HeaderLen:=0; for i:=0 to DefCount-1 do HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3; Dec(HeaderLen);
  1741. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  1742. { --- 1. sor --- }
  1743. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[HeaderLen+1],'³',C1,1);
  1744. X:=1;
  1745. for i:=0 to DefCount-1 do
  1746. begin
  1747. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  1748. if i=ActiveDef
  1749. then begin
  1750. ActiveKPos:=X-1;
  1751. ActiveVPos:=X+X2+2;
  1752. if GetState(sfFocused) then C:=C3 else C:=C2;
  1753. end
  1754. else C:=C2;
  1755. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  1756. MoveChar(B[X-1],'³',C1,1);
  1757. end;
  1758. SWriteBuf(0,1,Size.X,1,B);
  1759. { --- 0. sor --- }
  1760. ClearBuf; MoveChar(B[0],'Ú',C1,1);
  1761. X:=1;
  1762. for i:=0 to DefCount-1 do
  1763. begin
  1764. if I<ActiveDef then FC:='Ú'
  1765. else FC:='¿';
  1766. X2:=CStrLen(AtTab(i)^.Name^)+2;
  1767. MoveChar(B[X+X2],{'Â'}FC,C1,1);
  1768. if i=DefCount-1 then X2:=X2+1;
  1769. if X2>0 then
  1770. MoveChar(B[X],'Ä',C1,X2);
  1771. X:=X+X2+1;
  1772. end;
  1773. MoveChar(B[HeaderLen+1],'¿',C1,1);
  1774. MoveChar(B[ActiveKPos],'Ú',C1,1); MoveChar(B[ActiveVPos],'¿',C1,1);
  1775. SWriteBuf(0,0,Size.X,1,B);
  1776. { --- 2. sor --- }
  1777. MoveChar(B[1],'Ä',C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],'Ä',C1,Max(Size.X-HeaderLen-3,0));
  1778. MoveChar(B[Size.X-1],'¿',C1,1);
  1779. MoveChar(B[ActiveKPos],'Ù',C1,1);
  1780. if ActiveDef=0 then MoveChar(B[0],'³',C1,1)
  1781. else MoveChar(B[0],{'Ã'}'Ú',C1,1);
  1782. MoveChar(B[HeaderLen+1],'Ä'{'Á'},C1,1); MoveChar(B[ActiveVPos],'À',C1,1);
  1783. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  1784. SWriteBuf(0,2,Size.X,1,B);
  1785. { --- marad‚k sor --- }
  1786. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[Size.X-1],'³',C1,1);
  1787. SWriteBuf(0,3,Size.X,Size.Y-4,B);
  1788. { --- Size.X . sor --- }
  1789. MoveChar(B[0],'À',C1,1); MoveChar(B[1],'Ä',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],'Ù',C1,1);
  1790. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  1791. { - End of TGroup.Draw - }
  1792. if Buffer <> nil then
  1793. begin
  1794. Lock;
  1795. Redraw;
  1796. UnLock;
  1797. end;
  1798. if Buffer <> nil then WriteBuf(0, 0, Size.X, Size.Y, Buffer^) else
  1799. begin
  1800. GetClipRect(ClipR);
  1801. Redraw;
  1802. GetExtent(ClipR);
  1803. end;
  1804. { - End of TGroup.Draw - }
  1805. InDraw:=false;
  1806. end;
  1807. function TTab.Valid(Command: Word): Boolean;
  1808. var PT : PTabDef;
  1809. PI : PTabItem;
  1810. OK : boolean;
  1811. begin
  1812. OK:=true;
  1813. PT:=TabDefs;
  1814. while (PT<>nil) and (OK=true) do
  1815. begin
  1816. PI:=PT^.Items;
  1817. while (PI<>nil) and (OK=true) do
  1818. begin
  1819. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  1820. PI:=PI^.Next;
  1821. end;
  1822. PT:=PT^.Next;
  1823. end;
  1824. Valid:=OK;
  1825. end;
  1826. procedure TTab.SetState(AState: Word; Enable: Boolean);
  1827. begin
  1828. inherited SetState(AState,Enable);
  1829. if (AState and sfFocused)<>0 then DrawView;
  1830. end;
  1831. destructor TTab.Done;
  1832. var P,X: PTabDef;
  1833. procedure DeleteViews(P: PView); {$ifndef FPC}far;{$endif}
  1834. begin
  1835. if P<>nil then Delete(P);
  1836. end;
  1837. begin
  1838. ForEach(@DeleteViews);
  1839. inherited Done;
  1840. P:=TabDefs;
  1841. while P<>nil do
  1842. begin
  1843. X:=P^.Next;
  1844. DisposeTabDef(P);
  1845. P:=X;
  1846. end;
  1847. end;
  1848. constructor TScreenView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  1849. AScreen: PScreen);
  1850. begin
  1851. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  1852. Screen:=AScreen;
  1853. if Screen=nil then
  1854. Fail;
  1855. SetState(sfCursorVis,true);
  1856. Update;
  1857. end;
  1858. procedure TScreenView.Update;
  1859. begin
  1860. SetLimit(UserScreen^.GetWidth,UserScreen^.GetHeight);
  1861. DrawView;
  1862. end;
  1863. procedure TScreenView.HandleEvent(var Event: TEvent);
  1864. begin
  1865. case Event.What of
  1866. evBroadcast :
  1867. case Event.Command of
  1868. cmUpdate : Update;
  1869. end;
  1870. end;
  1871. inherited HandleEvent(Event);
  1872. end;
  1873. procedure TScreenView.Draw;
  1874. var B: TDrawBuffer;
  1875. X,Y: integer;
  1876. Text,Attr: string;
  1877. P: TPoint;
  1878. begin
  1879. Screen^.GetCursorPos(P);
  1880. for Y:=Delta.Y to Delta.Y+Size.Y-1 do
  1881. begin
  1882. if Y<Screen^.GetHeight then
  1883. Screen^.GetLine(Y,Text,Attr)
  1884. else
  1885. begin Text:=''; Attr:=''; end;
  1886. Text:=copy(Text,Delta.X+1,255); Attr:=copy(Attr,Delta.X+1,255);
  1887. MoveChar(B,' ',0,Size.X);
  1888. for X:=1 to length(Text) do
  1889. MoveChar(B[X-1],Text[X],ord(Attr[X]),1);
  1890. WriteLine(0,Y-Delta.Y,Size.X,1,B);
  1891. end;
  1892. SetCursor(P.X-Delta.X,P.Y-Delta.Y);
  1893. end;
  1894. constructor TScreenWindow.Init(AScreen: PScreen; ANumber: integer);
  1895. var R: TRect;
  1896. VSB,HSB: PScrollBar;
  1897. begin
  1898. Desktop^.GetExtent(R);
  1899. inherited Init(R, 'User screen', ANumber);
  1900. Options:=Options or ofTileAble;
  1901. GetExtent(R); R.Grow(-1,-1); R.Move(1,0); R.A.X:=R.B.X-1;
  1902. New(VSB, Init(R)); VSB^.Options:=VSB^.Options or ofPostProcess;
  1903. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  1904. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.A.Y:=R.B.Y-1;
  1905. New(HSB, Init(R)); HSB^.Options:=HSB^.Options or ofPostProcess;
  1906. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  1907. GetExtent(R); R.Grow(-1,-1);
  1908. New(ScreenView, Init(R, HSB, VSB, AScreen));
  1909. ScreenView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1910. Insert(ScreenView);
  1911. UserScreenWindow:=@Self;
  1912. end;
  1913. destructor TScreenWindow.Done;
  1914. begin
  1915. inherited Done;
  1916. UserScreenWindow:=nil;
  1917. end;
  1918. const InTranslate : boolean = false;
  1919. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  1920. procedure TranslateAction(Action: integer);
  1921. var E: TEvent;
  1922. begin
  1923. if Action<>acNone then
  1924. begin
  1925. E:=Event;
  1926. E.What:=evMouseDown; E.Buttons:=mbLeftButton;
  1927. View^.HandleEvent(E);
  1928. Event.What:=evCommand;
  1929. Event.Command:=ActionCommands[Action];
  1930. end;
  1931. end;
  1932. begin
  1933. if InTranslate then Exit;
  1934. InTranslate:=true;
  1935. case Event.What of
  1936. evMouseDown :
  1937. if (GetShiftState and kbAlt)<>0 then
  1938. TranslateAction(AltMouseAction) else
  1939. if (GetShiftState and kbCtrl)<>0 then
  1940. TranslateAction(CtrlMouseAction);
  1941. end;
  1942. InTranslate:=false;
  1943. end;
  1944. function GetNextEditorBounds(var Bounds: TRect): boolean;
  1945. var P: PView;
  1946. begin
  1947. P:=Desktop^.First;
  1948. while P<>nil do
  1949. begin
  1950. if P^.HelpCtx=hcSourceWindow then Break;
  1951. P:=P^.NextView;
  1952. end;
  1953. if P=nil then Desktop^.GetExtent(Bounds) else
  1954. begin
  1955. P^.GetBounds(Bounds);
  1956. Inc(Bounds.A.X); Inc(Bounds.A.Y);
  1957. end;
  1958. GetNextEditorBounds:=P<>nil;
  1959. end;
  1960. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: sw_integer): PSourceWindow;
  1961. var R: TRect;
  1962. W: PSourceWindow;
  1963. begin
  1964. if Assigned(Bounds) then R.Copy(Bounds^) else
  1965. GetNextEditorBounds(R);
  1966. PushStatus('Opening source file... ('+SmartPath(FileName)+')');
  1967. New(W, Init(R, FileName));
  1968. if W<>nil then
  1969. begin
  1970. if (CurX<>0) or (CurY<>0) then
  1971. with W^.Editor^ do
  1972. begin
  1973. SetCurPtr(CurX,CurY);
  1974. TrackCursor(true);
  1975. end;
  1976. W^.HelpCtx:=hcSourceWindow;
  1977. Desktop^.Insert(W);
  1978. If assigned(BreakpointCollection) then
  1979. BreakPointCollection^.ShowBreakpoints(W);
  1980. Message(Application,evBroadcast,cmUpdate,nil);
  1981. end;
  1982. PopStatus;
  1983. OpenEditorWindow:=W;
  1984. end;
  1985. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: sw_integer;tryexts:boolean): PSourceWindow;
  1986. var D : DirStr;
  1987. N : NameStr;
  1988. E : ExtStr;
  1989. DrStr : String;
  1990. function CheckDir(NewDir: DirStr; NewName: NameStr; NewExt: ExtStr): boolean;
  1991. var OK: boolean;
  1992. begin
  1993. NewDir:=CompleteDir(NewDir);
  1994. OK:=ExistsFile(NewDir+NewName+NewExt);
  1995. if OK then begin D:=NewDir; N:=NewName; E:=NewExt; end;
  1996. CheckDir:=OK;
  1997. end;
  1998. function CheckExt(NewExt: ExtStr): boolean;
  1999. var OK: boolean;
  2000. begin
  2001. OK:=false;
  2002. if D<>'' then OK:=CheckDir(D,N,NewExt) else
  2003. if CheckDir('.'+DirSep,N,NewExt) then OK:=true;
  2004. CheckExt:=OK;
  2005. end;
  2006. function TryToOpen(const DD : dirstr): PSourceWindow;
  2007. var Found: boolean;
  2008. W : PSourceWindow;
  2009. begin
  2010. D:=CompleteDir(DD);
  2011. Found:=true;
  2012. if (E<>'') or (not tryexts) then
  2013. Found:=CheckExt(E)
  2014. else
  2015. if CheckExt('.pp') then
  2016. Found:=true
  2017. else
  2018. if CheckExt('.pas') then
  2019. Found:=true
  2020. else
  2021. if CheckExt('.inc') then
  2022. Found:=true
  2023. else
  2024. Found:=false;
  2025. if Found=false then
  2026. W:=nil
  2027. else
  2028. begin
  2029. FileName:=FExpand(D+N+E);
  2030. W:=OpenEditorWindow(Bounds,FileName,CurX,CurY);
  2031. end;
  2032. TryToOpen:=W;
  2033. end;
  2034. function SearchOnDesktop: PSourceWindow;
  2035. var W: PWindow;
  2036. I: integer;
  2037. Found: boolean;
  2038. SName : string;
  2039. begin
  2040. for I:=1 to 100 do
  2041. begin
  2042. W:=SearchWindowWithNo(I);
  2043. if (W<>nil) and (W^.HelpCtx=hcSourceWindow) then
  2044. begin
  2045. if (D='') then
  2046. SName:=NameAndExtOf(PSourceWindow(W)^.Editor^.FileName)
  2047. else
  2048. SName:=PSourceWindow(W)^.Editor^.FileName;
  2049. SName:=UpcaseStr(SName);
  2050. if (E<>'') or (not tryexts) then
  2051. begin
  2052. if D<>'' then
  2053. Found:=SName=UpcaseStr(D+N+E)
  2054. else
  2055. Found:=SName=UpcaseStr(N+E);
  2056. end
  2057. else
  2058. begin
  2059. Found:=SName=UpcaseStr(N+'.pp');
  2060. if Found=false then
  2061. Found:=SName=UpcaseStr(N+'.pas');
  2062. end;
  2063. if Found then Break;
  2064. end;
  2065. end;
  2066. if Found=false then W:=nil;
  2067. SearchOnDesktop:=PSourceWindow(W);
  2068. end;
  2069. var
  2070. W : PSourceWindow;
  2071. begin
  2072. FSplit(FileName,D,N,E);
  2073. W:=SearchOnDesktop;
  2074. if W<>nil then
  2075. begin
  2076. NewEditorOpened:=false;
  2077. { if assigned(Bounds) then
  2078. W^.ChangeBounds(Bounds^);}
  2079. W^.Editor^.SetCurPtr(CurX,CurY);
  2080. end
  2081. else
  2082. begin
  2083. DrStr:=GetSourceDirectories;
  2084. While pos(';',DrStr)>0 do
  2085. Begin
  2086. W:=TryToOpen(Copy(DrStr,1,pos(';',DrStr)-1));
  2087. if assigned(W) then
  2088. break;
  2089. DrStr:=Copy(DrStr,pos(';',DrStr)+1,255);
  2090. End;
  2091. if not assigned(W) then
  2092. W:=TryToOpen(DrStr);
  2093. NewEditorOpened:=W<>nil;
  2094. if assigned(W) then
  2095. W^.Editor^.SetCurPtr(CurX,CurY);
  2096. end;
  2097. TryToOpenFile:=W;
  2098. end;
  2099. function StartEditor(Editor: PCodeEditor; FileName: string): boolean;
  2100. var OK: boolean;
  2101. E: PFileEditor;
  2102. R: TRect;
  2103. begin
  2104. R.Assign(0,0,0,0);
  2105. New(E, Init(R,nil,nil,nil,FileName));
  2106. OK:=E<>nil;
  2107. if OK then OK:=E^.LoadFile;
  2108. if OK then
  2109. begin
  2110. E^.SelectAll(true);
  2111. Editor^.InsertFrom(E);
  2112. Editor^.SetCurPtr(0,0);
  2113. Editor^.SelectAll(false);
  2114. Dispose(E, Done);
  2115. end;
  2116. StartEditor:=OK;
  2117. end;
  2118. constructor TTextScroller.Init(var Bounds: TRect; ASpeed: integer; AText: PUnsortedStringCollection);
  2119. begin
  2120. inherited Init(Bounds,'');
  2121. EventMask:=EventMask or evIdle;
  2122. Speed:=ASpeed; Lines:=AText;
  2123. end;
  2124. function TTextScroller.GetLineCount: integer;
  2125. var Count: integer;
  2126. begin
  2127. if Lines=nil then Count:=0 else
  2128. Count:=Lines^.Count;
  2129. GetLineCount:=Count;
  2130. end;
  2131. function TTextScroller.GetLine(I: integer): string;
  2132. var S: string;
  2133. begin
  2134. if I<Lines^.Count then
  2135. S:=GetStr(Lines^.At(I))
  2136. else
  2137. S:='';
  2138. GetLine:=S;
  2139. end;
  2140. procedure TTextScroller.HandleEvent(var Event: TEvent);
  2141. begin
  2142. case Event.What of
  2143. evIdle :
  2144. Update;
  2145. end;
  2146. inherited HandleEvent(Event);
  2147. end;
  2148. procedure TTextScroller.Update;
  2149. begin
  2150. if abs(GetDosTicks-LastTT)<Speed then Exit;
  2151. Scroll;
  2152. LastTT:=GetDosTicks;
  2153. end;
  2154. procedure TTextScroller.Reset;
  2155. begin
  2156. TopLine:=0;
  2157. LastTT:=GetDosTicks;
  2158. DrawView;
  2159. end;
  2160. procedure TTextScroller.Scroll;
  2161. begin
  2162. Inc(TopLine);
  2163. if TopLine>=GetLineCount then
  2164. Reset;
  2165. DrawView;
  2166. end;
  2167. procedure TTextScroller.Draw;
  2168. var B: TDrawBuffer;
  2169. C: word;
  2170. Count,Y: integer;
  2171. S: string;
  2172. begin
  2173. C:=GetColor(1);
  2174. Count:=GetLineCount;
  2175. for Y:=0 to Size.Y-1 do
  2176. begin
  2177. if Count=0 then S:='' else
  2178. S:=GetLine((TopLine+Y) mod Count);
  2179. if copy(S,1,1)=^C then
  2180. S:=CharStr(' ',Max(0,(Size.X-(length(S)-1)) div 2))+copy(S,2,255);
  2181. MoveChar(B,' ',C,Size.X);
  2182. MoveStr(B,S,C);
  2183. WriteLine(0,Y,Size.X,1,B);
  2184. end;
  2185. end;
  2186. destructor TTextScroller.Done;
  2187. begin
  2188. inherited Done;
  2189. if Lines<>nil then Dispose(Lines, Done);
  2190. end;
  2191. constructor TFPAboutDialog.Init;
  2192. var R,R2: TRect;
  2193. C: PUnsortedStringCollection;
  2194. I: integer;
  2195. OSStr: string;
  2196. procedure AddLine(S: string);
  2197. begin
  2198. C^.Insert(NewStr(S));
  2199. end;
  2200. begin
  2201. OSStr:='';
  2202. {$ifdef go32v2}
  2203. OSStr:='Dos';
  2204. {$endif}
  2205. {$ifdef tp}
  2206. OSStr:='Dos';
  2207. {$endif}
  2208. {$ifdef linux}
  2209. OSStr:='Linux';
  2210. {$endif}
  2211. {$ifdef win32}
  2212. OSStr:='Win32';
  2213. {$endif}
  2214. {$ifdef os2}
  2215. OSStr:='OS/2';
  2216. {$endif}
  2217. R.Assign(0,0,38,12);
  2218. inherited Init(R, 'About');
  2219. GetExtent(R); R.Grow(-3,-2);
  2220. R2.Copy(R); R2.B.Y:=R2.A.Y+1;
  2221. Insert(New(PStaticText, Init(R2, ^C'FreePascal IDE for '+OSStr)));
  2222. R2.Move(0,1);
  2223. Insert(New(PStaticText, Init(R2, ^C' Version '+VersionStr)));
  2224. R2.Move(0,1);
  2225. Insert(New(PStaticText, Init(R2, ^C'(Compiler Version '+Version_String+')')));
  2226. R2.Move(0,2);
  2227. Insert(New(PStaticText, Init(R2, ^C'Copyright (C) 1998-99 by')));
  2228. R2.Move(0,2);
  2229. Insert(New(PStaticText, Init(R2, ^C'B‚rczi G bor')));
  2230. R2.Move(0,1);
  2231. Insert(New(PStaticText, Init(R2, ^C'and')));
  2232. R2.Move(0,1);
  2233. Insert(New(PStaticText, Init(R2, ^C'Peter Vreman')));
  2234. New(C, Init(50,10));
  2235. for I:=1 to 7 do
  2236. AddLine('');
  2237. AddLine(^C'< Original concept >');
  2238. AddLine(^C'Borland International, Inc.');
  2239. AddLine('');
  2240. AddLine(^C'< Compiler development >');
  2241. AddLine(^C'Carl-Eric Codere');
  2242. AddLine(^C'Daniel Mantione');
  2243. AddLine(^C'Florian Kl„mpfl');
  2244. AddLine(^C'Jonas Maebe');
  2245. AddLine(^C'Mich„el Van Canneyt');
  2246. AddLine(^C'Peter Vreman');
  2247. AddLine(^C'Pierre Muller');
  2248. AddLine('');
  2249. AddLine(^C'< IDE development >');
  2250. AddLine(^C'B‚rczi G bor');
  2251. AddLine(^C'Peter Vreman');
  2252. AddLine(^C'Pierre Muller');
  2253. AddLine('');
  2254. GetExtent(R);
  2255. R.Grow(-1,-1); Inc(R.A.Y,3);
  2256. New(Scroller, Init(R, 10, C));
  2257. Scroller^.Hide;
  2258. Insert(Scroller);
  2259. R.Move(0,-1); R.B.Y:=R.A.Y+1;
  2260. New(TitleST, Init(R, ^C'Team'));
  2261. TitleST^.Hide;
  2262. Insert(TitleST);
  2263. InsertOK(@Self);
  2264. end;
  2265. procedure TFPAboutDialog.ToggleInfo;
  2266. begin
  2267. if Scroller=nil then Exit;
  2268. if Scroller^.GetState(sfVisible) then
  2269. begin
  2270. Scroller^.Hide;
  2271. TitleST^.Hide;
  2272. end
  2273. else
  2274. begin
  2275. Scroller^.Reset;
  2276. Scroller^.Show;
  2277. TitleST^.Show;
  2278. end;
  2279. end;
  2280. procedure TFPAboutDialog.HandleEvent(var Event: TEvent);
  2281. begin
  2282. case Event.What of
  2283. evKeyDown :
  2284. case Event.KeyCode of
  2285. kbAltI : { just like in BP }
  2286. begin
  2287. ToggleInfo;
  2288. ClearEvent(Event);
  2289. end;
  2290. end;
  2291. end;
  2292. inherited HandleEvent(Event);
  2293. end;
  2294. constructor TFPASCIIChart.Init;
  2295. begin
  2296. inherited Init;
  2297. HelpCtx:=hcASCIITable;
  2298. Number:=SearchFreeWindowNo;
  2299. ASCIIChart:=@Self;
  2300. end;
  2301. procedure TFPASCIIChart.HandleEvent(var Event: TEvent);
  2302. begin
  2303. case Event.What of
  2304. evKeyDown :
  2305. case Event.KeyCode of
  2306. kbEsc :
  2307. begin
  2308. Close;
  2309. ClearEvent(Event);
  2310. end;
  2311. end;
  2312. end;
  2313. inherited HandleEvent(Event);
  2314. end;
  2315. destructor TFPASCIIChart.Done;
  2316. begin
  2317. ASCIIChart:=nil;
  2318. inherited Done;
  2319. end;
  2320. function TVideoModeListBox.GetText(Item: pointer; MaxLen: sw_integer): string;
  2321. var P: PVideoModeList;
  2322. S: string;
  2323. begin
  2324. P:=Item;
  2325. S:=IntToStr(P^.Col)+'x'+IntToStr(P^.Row)+' ';
  2326. if P^.Color then
  2327. S:=S+'color'
  2328. else
  2329. S:=S+'mono';
  2330. GetText:=copy(S,1,MaxLen);
  2331. end;
  2332. {$ifdef VESA}
  2333. function VESASetVideoModeProc(const VideoMode: TVideoMode; Params: Longint): Boolean; {$ifndef FPC}far;{$endif}
  2334. begin
  2335. VESASetMode(Params);
  2336. end;
  2337. procedure InitVESAScreenModes;
  2338. var ML: TVESAModeList;
  2339. MI: TVESAModeInfoBlock;
  2340. I: integer;
  2341. begin
  2342. if VESAInit=false then Exit;
  2343. if VESAGetModeList(ML)=false then Exit;
  2344. for I:=1 to ML.Count do
  2345. begin
  2346. if VESAGetModeInfo(ML.Modes[I],MI) then
  2347. with MI do
  2348. if (Attributes and vesa_vma_GraphicsMode)=0 then
  2349. RegisterVideoMode(XResolution,YResolution,
  2350. (Attributes and vesa_vma_ColorMode)<>0,{$ifdef FPC}@{$endif}VESASetVideoModeProc,ML.Modes[I]);
  2351. end;
  2352. end;
  2353. {$endif}
  2354. procedure NoDebugger;
  2355. begin
  2356. InformationBox('No debugger support available.',nil);
  2357. end;
  2358. procedure RegisterFPViews;
  2359. begin
  2360. RegisterType(RSourceEditor);
  2361. RegisterType(RSourceWindow);
  2362. RegisterType(RFPHelpViewer);
  2363. RegisterType(RFPHelpWindow);
  2364. RegisterType(RClipboardWindow);
  2365. RegisterType(RMessageListBox);
  2366. end;
  2367. END.
  2368. {
  2369. $Log$
  2370. Revision 1.31 1999-06-02 11:19:13 pierre
  2371. * @ is now required for FPC for procedure address passing in functions
  2372. Revision 1.30 1999/05/22 13:44:33 peter
  2373. * fixed couple of bugs
  2374. Revision 1.29 1999/04/15 08:58:08 peter
  2375. * syntax highlight fixes
  2376. * browser updates
  2377. Revision 1.28 1999/04/07 21:55:56 peter
  2378. + object support for browser
  2379. * html help fixes
  2380. * more desktop saving things
  2381. * NODEBUG directive to exclude debugger
  2382. Revision 1.27 1999/04/01 10:27:06 pierre
  2383. + file(line) in start of message added
  2384. Revision 1.26 1999/03/23 16:16:41 peter
  2385. * linux fixes
  2386. Revision 1.25 1999/03/23 15:11:37 peter
  2387. * desktop saving things
  2388. * vesa mode
  2389. * preferences dialog
  2390. Revision 1.24 1999/03/21 22:51:37 florian
  2391. + functional screen mode switching added
  2392. Revision 1.23 1999/03/19 16:04:33 peter
  2393. * new compiler dialog
  2394. Revision 1.22 1999/03/16 00:44:45 peter
  2395. * forgotten in last commit :(
  2396. Revision 1.21 1999/03/08 14:58:16 peter
  2397. + prompt with dialogs for tools
  2398. Revision 1.20 1999/03/01 15:42:08 peter
  2399. + Added dummy entries for functions not yet implemented
  2400. * MenuBar didn't update itself automatically on command-set changes
  2401. * Fixed Debugging/Profiling options dialog
  2402. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is set
  2403. * efBackSpaceUnindents works correctly
  2404. + 'Messages' window implemented
  2405. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  2406. + Added TP message-filter support (for ex. you can call GREP thru
  2407. GREP2MSG and view the result in the messages window - just like in TP)
  2408. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  2409. so topic search didn't work...
  2410. * In FPHELP.PAS there were still context-variables defined as word instead
  2411. of THelpCtx
  2412. * StdStatusKeys() was missing from the statusdef for help windows
  2413. + Topic-title for index-table can be specified when adding a HTML-files
  2414. Revision 1.19 1999/02/22 11:51:39 peter
  2415. * browser updates from gabor
  2416. Revision 1.18 1999/02/22 11:29:38 pierre
  2417. + added col info in MessageItem
  2418. + grep uses HighLightExts and should work for linux
  2419. Revision 1.17 1999/02/22 02:15:22 peter
  2420. + default extension for save in the editor
  2421. + Separate Text to Find for the grep dialog
  2422. * fixed redir crash with tp7
  2423. Revision 1.16 1999/02/19 18:43:49 peter
  2424. + open dialog supports mask list
  2425. Revision 1.15 1999/02/17 15:04:02 pierre
  2426. + file(line) added in TProgramInfo message list
  2427. Revision 1.14 1999/02/16 12:45:18 pierre
  2428. * GDBWindow size and grow corrected
  2429. Revision 1.13 1999/02/15 09:36:06 pierre
  2430. * // comment ends at end of line !
  2431. GDB window changed !
  2432. now all is in a normal text editor, but pressing
  2433. Enter key will send part of line before cursor to GDB !
  2434. Revision 1.12 1999/02/11 19:07:25 pierre
  2435. * GDBWindow redesigned :
  2436. normal editor apart from
  2437. that any kbEnter will send the line (for begin to cursor)
  2438. to GDB command !
  2439. GDBWindow opened in Debugger Menu
  2440. still buggy :
  2441. -echo should not be present if at end of text
  2442. -GDBWindow becomes First after each step (I don't know why !)
  2443. Revision 1.11 1999/02/11 13:08:39 pierre
  2444. + TGDBWindow : direct gdb input/output
  2445. Revision 1.10 1999/02/10 09:42:52 pierre
  2446. + DoneReservedWords to avoid memory leaks
  2447. * TMessageItem Module field was not disposed
  2448. Revision 1.9 1999/02/05 12:12:02 pierre
  2449. + SourceDir that stores directories for sources that the
  2450. compiler should not know about
  2451. Automatically asked for addition when a new file that
  2452. needed filedialog to be found is in an unknown directory
  2453. Stored and retrieved from INIFile
  2454. + Breakpoints conditions added to INIFile
  2455. * Breakpoints insterted and removed at debin and end of debug session
  2456. Revision 1.8 1999/02/04 17:45:23 pierre
  2457. + BrowserAtCursor started
  2458. * bug in TryToOpenFile removed
  2459. Revision 1.7 1999/02/04 13:32:11 pierre
  2460. * Several things added (I cannot commit them independently !)
  2461. + added TBreakpoint and TBreakpointCollection
  2462. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  2463. + Breakpoint list in INIFile
  2464. * Select items now also depend of SwitchMode
  2465. * Reading of option '-g' was not possible !
  2466. + added search for -Fu args pathes in TryToOpen
  2467. + added code for automatic opening of FileDialog
  2468. if source not found
  2469. Revision 1.6 1999/01/21 11:54:27 peter
  2470. + tools menu
  2471. + speedsearch in symbolbrowser
  2472. * working run command
  2473. Revision 1.5 1999/01/14 21:42:25 peter
  2474. * source tracking from Gabor
  2475. Revision 1.4 1999/01/12 14:29:42 peter
  2476. + Implemented still missing 'switch' entries in Options menu
  2477. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  2478. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  2479. ASCII chars and inserted directly in the text.
  2480. + Added symbol browser
  2481. * splitted fp.pas to fpide.pas
  2482. Revision 1.3 1999/01/04 11:49:53 peter
  2483. * 'Use tab characters' now works correctly
  2484. + Syntax highlight now acts on File|Save As...
  2485. + Added a new class to syntax highlight: 'hex numbers'.
  2486. * There was something very wrong with the palette managment. Now fixed.
  2487. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  2488. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  2489. process revised
  2490. Revision 1.2 1998/12/28 15:47:54 peter
  2491. + Added user screen support, display & window
  2492. + Implemented Editor,Mouse Options dialog
  2493. + Added location of .INI and .CFG file
  2494. + Option (INI) file managment implemented (see bottom of Options Menu)
  2495. + Switches updated
  2496. + Run program
  2497. Revision 1.4 1998/12/22 10:39:53 peter
  2498. + options are now written/read
  2499. + find and replace routines
  2500. }