fpviews.pas 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399
  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. interface
  14. uses
  15. Dos,Objects,Drivers,Commands,HelpCtx,Views,Menus,Dialogs,App,
  16. {$ifdef EDITORS}
  17. Editors,
  18. {$else}
  19. WEditor,
  20. {$endif}
  21. WHlpView,
  22. Comphook,
  23. FPConst,FPUsrScr;
  24. type
  25. {$IFNDEF EDITORS}
  26. TEditor = TCodeEditor; PEditor = PCodeEditor;
  27. {$ENDIF}
  28. PCenterDialog = ^TCenterDialog;
  29. TCenterDialog = object(TDialog)
  30. constructor Init(var Bounds: TRect; ATitle: TTitleStr);
  31. end;
  32. PIntegerLine = ^TIntegerLine;
  33. TIntegerLine = object(TInputLine)
  34. constructor Init(var Bounds: TRect; AMin, AMax: longint);
  35. end;
  36. TFPWindow = object(TWindow)
  37. procedure HandleEvent(var Event: TEvent); virtual;
  38. end;
  39. PIDEHelpWindow = ^TIDEHelpWindow;
  40. TIDEHelpWindow = object(THelpWindow)
  41. function GetPalette: PPalette; virtual;
  42. end;
  43. PSourceEditor = ^TSourceEditor;
  44. TSourceEditor = object(TFileEditor)
  45. {$ifndef EDITORS}
  46. function IsReservedWord(const S: string): boolean; virtual;
  47. function GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer; virtual;
  48. function GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): string; virtual;
  49. {$endif}
  50. procedure HandleEvent(var Event: TEvent); virtual;
  51. procedure LocalMenu(P: TPoint); virtual;
  52. function GetLocalMenu: PMenu; virtual;
  53. function GetCommandTarget: PView; virtual;
  54. private
  55. LastLocalCmd : word;
  56. end;
  57. PSourceWindow = ^TSourceWindow;
  58. TSourceWindow = object(TFPWindow)
  59. Editor : PSourceEditor;
  60. Indicator : PIndicator;
  61. constructor Init(var Bounds: TRect; AFileName: string);
  62. procedure SetTitle(ATitle: string); virtual;
  63. procedure UpdateTitle; virtual;
  64. procedure HandleEvent(var Event: TEvent); virtual;
  65. procedure SetState(AState: Word; Enable: Boolean); virtual;
  66. procedure Update; virtual;
  67. procedure UpdateCommands; virtual;
  68. function GetPalette: PPalette; virtual;
  69. destructor Done; virtual;
  70. end;
  71. PGDBSourceEditor = ^TGDBSourceEditor;
  72. TGDBSourceEditor = object(TSourceEditor)
  73. function InsertLine : Sw_integer;virtual;
  74. function Valid(Command: Word): Boolean; virtual;
  75. procedure AddLine(const S: string); virtual;
  76. procedure AddErrorLine(const S: string); virtual;
  77. private
  78. Silent,
  79. AutoRepeat,
  80. IgnoreStringAtEnd : boolean;
  81. LastCommand : String;
  82. end;
  83. PGDBWindow = ^TGDBWindow;
  84. TGDBWindow = object(TFPWindow)
  85. Editor : PGDBSourceEditor;
  86. Indicator : PIndicator;
  87. constructor Init(var Bounds: TRect);
  88. procedure WriteText(Buf : pchar;IsError : boolean);
  89. procedure WriteString(Const S : string);
  90. procedure WriteErrorString(Const S : string);
  91. procedure WriteOutputText(Buf : pchar);
  92. procedure WriteErrorText(Buf : pchar);
  93. function GetPalette: PPalette;virtual;
  94. destructor Done; virtual;
  95. end;
  96. PClipboardWindow = ^TClipboardWindow;
  97. TClipboardWindow = object(TSourceWindow)
  98. constructor Init;
  99. procedure Close; virtual;
  100. destructor Done; virtual;
  101. end;
  102. PAdvancedMenuBox = ^TAdvancedMenuBox;
  103. TAdvancedMenuBox = object(TMenuBox)
  104. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  105. AParentMenu: PMenuView): PMenuView; virtual;
  106. function Execute: Word; virtual;
  107. end;
  108. PAdvancedMenuPopUp = ^TAdvancedMenuPopup;
  109. TAdvancedMenuPopUp = object(TMenuPopup)
  110. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  111. AParentMenu: PMenuView): PMenuView; virtual;
  112. function Execute: Word; virtual;
  113. end;
  114. PAdvancedMenuBar = ^TAdvancedMenuBar;
  115. TAdvancedMenuBar = object(TMenuBar)
  116. constructor Init(var Bounds: TRect; AMenu: PMenu);
  117. function NewSubView(var Bounds: TRect; AMenu: PMenu;
  118. AParentMenu: PMenuView): PMenuView; virtual;
  119. procedure Update; virtual;
  120. procedure HandleEvent(var Event: TEvent); virtual;
  121. function Execute: Word; virtual;
  122. end;
  123. PAdvancedStaticText = ^TAdvancedStaticText;
  124. TAdvancedStaticText = object(TStaticText)
  125. procedure SetText(S: string); virtual;
  126. end;
  127. PAdvancedListBox = ^TAdvancedListBox;
  128. TAdvancedListBox = object(TListBox)
  129. Default: boolean;
  130. procedure HandleEvent(var Event: TEvent); virtual;
  131. end;
  132. TLocalMenuListBox = object(TAdvancedListBox)
  133. procedure HandleEvent(var Event: TEvent); virtual;
  134. procedure LocalMenu(P: TPoint); virtual;
  135. function GetLocalMenu: PMenu; virtual;
  136. function GetCommandTarget: PView; virtual;
  137. private
  138. LastLocalCmd: word;
  139. end;
  140. PColorStaticText = ^TColorStaticText;
  141. TColorStaticText = object(TAdvancedStaticText)
  142. Color: word;
  143. DontWrap: boolean;
  144. Delta: TPoint;
  145. constructor Init(var Bounds: TRect; AText: String; AColor: word);
  146. procedure Draw; virtual;
  147. end;
  148. PUnsortedStringCollection = ^TUnsortedStringCollection;
  149. TUnsortedStringCollection = object(TCollection)
  150. function At(Index: Integer): PString;
  151. procedure FreeItem(Item: Pointer); virtual;
  152. end;
  153. PHSListBox = ^THSListBox;
  154. THSListBox = object(TLocalMenuListBox)
  155. constructor Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  156. end;
  157. PDlgWindow = ^TDlgWindow;
  158. TDlgWindow = object(TDialog)
  159. constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  160. end;
  161. PAdvancedStatusLine = ^TAdvancedStatusLine;
  162. TAdvancedStatusLine = object(TStatusLine)
  163. StatusText: PString;
  164. function GetStatusText: string; virtual;
  165. procedure SetStatusText(const S: string); virtual;
  166. procedure ClearStatusText; virtual;
  167. procedure Draw; virtual;
  168. end;
  169. PMessageItem = ^TMessageItem;
  170. TMessageItem = object(TObject)
  171. TClass : longint;
  172. Text : PString;
  173. Module : PString;
  174. ID,Col : longint;
  175. constructor Init(AClass: longint; AText, AModule: string; AID,ACol: longint);
  176. function GetText(MaxLen: integer): string; virtual;
  177. procedure Selected; virtual;
  178. function GetModuleName: string; virtual;
  179. destructor Done; virtual;
  180. end;
  181. PMessageListBox = ^TMessageListBox;
  182. TMessageListBox = object(THSListBox)
  183. Transparent: boolean;
  184. NoSelection: boolean;
  185. MaxWidth: integer;
  186. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  187. procedure AddItem(P: PMessageItem); virtual;
  188. function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  189. procedure Clear; virtual;
  190. procedure TrackSource; virtual;
  191. procedure GotoSource; virtual;
  192. procedure Draw; virtual;
  193. procedure HandleEvent(var Event: TEvent); virtual;
  194. function GetLocalMenu: PMenu; virtual;
  195. destructor Done; virtual;
  196. end;
  197. PCompilerMessage = ^TCompilerMessage;
  198. TCompilerMessage = object(TMessageItem)
  199. function GetText(MaxLen: Integer): String; virtual;
  200. end;
  201. PProgramInfoWindow = ^TProgramInfoWindow;
  202. TProgramInfoWindow = object(TDlgWindow)
  203. InfoST: PColorStaticText;
  204. LogLB : PMessageListBox;
  205. constructor Init;
  206. procedure AddMessage(AClass: longint; Msg, Module: string; Line,Column: longint);
  207. procedure ClearMessages;
  208. procedure SizeLimits(var Min, Max: TPoint); virtual;
  209. procedure Close; virtual;
  210. procedure HandleEvent(var Event: TEvent); virtual;
  211. procedure Update; virtual;
  212. destructor Done; virtual;
  213. end;
  214. PTabItem = ^TTabItem;
  215. TTabItem = record
  216. Next : PTabItem;
  217. View : PView;
  218. Dis : boolean;
  219. end;
  220. PTabDef = ^TTabDef;
  221. TTabDef = record
  222. Next : PTabDef;
  223. Name : PString;
  224. Items : PTabItem;
  225. DefItem : PView;
  226. ShortCut : char;
  227. end;
  228. PTab = ^TTab;
  229. TTab = object(TGroup)
  230. TabDefs : PTabDef;
  231. ActiveDef : integer;
  232. DefCount : word;
  233. constructor Init(var Bounds: TRect; ATabDef: PTabDef);
  234. function AtTab(Index: integer): PTabDef; virtual;
  235. procedure SelectTab(Index: integer); virtual;
  236. function TabCount: integer;
  237. function Valid(Command: Word): Boolean; virtual;
  238. procedure ChangeBounds(var Bounds: TRect); virtual;
  239. procedure HandleEvent(var Event: TEvent); virtual;
  240. function GetPalette: PPalette; virtual;
  241. procedure Draw; virtual;
  242. procedure SetState(AState: Word; Enable: Boolean); virtual;
  243. destructor Done; virtual;
  244. private
  245. InDraw: boolean;
  246. end;
  247. PScreenView = ^TScreenView;
  248. TScreenView = object(TScroller)
  249. Screen: PScreen;
  250. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  251. AScreen: PScreen);
  252. procedure Draw; virtual;
  253. procedure Update; virtual;
  254. procedure HandleEvent(var Event: TEvent); virtual;
  255. end;
  256. PScreenWindow = ^TScreenWindow;
  257. TScreenWindow = object(TFPWindow)
  258. ScreenView : PScreenView;
  259. constructor Init(AScreen: PScreen; ANumber: integer);
  260. destructor Done; virtual;
  261. end;
  262. function SearchFreeWindowNo: integer;
  263. procedure InsertOK(ADialog: PDialog);
  264. procedure InsertButtons(ADialog: PDialog);
  265. procedure ErrorBox(const S: string; Params: pointer);
  266. procedure WarningBox(const S: string; Params: pointer);
  267. procedure InformationBox(const S: string; Params: pointer);
  268. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  269. function IsThereAnyEditor: boolean;
  270. function IsThereAnyWindow: boolean;
  271. function FirstEditorWindow: PSourceWindow;
  272. function EditorWindowFile(const Name : String): PSourceWindow;
  273. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  274. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  275. function IsSubMenu(P: PMenuItem): boolean;
  276. function IsSeparator(P: PMenuItem): boolean;
  277. function UpdateMenu(M: PMenu): boolean;
  278. function SearchSubMenu(M: PMenu; Index: integer): PMenuItem;
  279. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  280. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  281. function GetMenuItemBefore(Menu:PMenu; BeforeOf: PMenuItem): PMenuItem;
  282. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  283. procedure DisposeTabItem(P: PTabItem);
  284. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  285. procedure DisposeTabDef(P: PTabDef);
  286. function GetEditorCurWord(Editor: PEditor): string;
  287. procedure InitReservedWords;
  288. procedure DoneReservedWords;
  289. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  290. function GetNextEditorBounds(var Bounds: TRect): boolean;
  291. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: integer): PSourceWindow;
  292. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: integer): PSourceWindow;
  293. const
  294. SourceCmds : TCommandSet =
  295. ([cmSave,cmSaveAs,cmCompile]);
  296. EditorCmds : TCommandSet =
  297. ([cmFind,cmReplace,cmSearchAgain,cmJumpLine,cmHelpTopicSearch]);
  298. CompileCmds : TCommandSet =
  299. ([cmMake,cmBuild,cmRun]);
  300. CalcClipboard : extended = 0;
  301. OpenFileName : string = '';
  302. NewEditorOpened: boolean = false;
  303. var MsgParms : array[1..10] of
  304. record
  305. case byte of
  306. 0 : (Ptr : pointer);
  307. 1 : (Long: longint);
  308. end;
  309. implementation
  310. uses
  311. Strings,Keyboard,Memory,MsgBox,Validate,
  312. Tokens,FPSwitch,FPSymbol,FPDebug,
  313. FPVars,FPUtils,FPHelp,FPCompile;
  314. const
  315. NoNameCount : integer = 0;
  316. ReservedWords : PUnsortedStringCollection = nil;
  317. function IsThereAnyEditor: boolean;
  318. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  319. begin
  320. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  321. end;
  322. begin
  323. IsThereAnyEditor:=Desktop^.FirstThat(@EditorWindow)<>nil;
  324. end;
  325. function IsThereAnyHelpWindow: boolean;
  326. begin
  327. IsThereAnyHelpWindow:=(HelpWindow<>nil) and (HelpWindow^.GetState(sfVisible));
  328. end;
  329. function IsThereAnyWindow: boolean;
  330. var _Is: boolean;
  331. begin
  332. _Is:=Message(Desktop,evBroadcast,cmSearchWindow,nil)<>nil;
  333. _Is:=_Is or ( (ClipboardWindow<>nil) and ClipboardWindow^.GetState(sfVisible));
  334. IsThereAnyWindow:=_Is;
  335. end;
  336. function FirstEditorWindow: PSourceWindow;
  337. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  338. begin
  339. EditorWindow:=(P^.HelpCtx=hcSourceWindow);
  340. end;
  341. begin
  342. FirstEditorWindow:=pointer(Desktop^.FirstThat(@EditorWindow));
  343. end;
  344. function EditorWindowFile(const Name : String): PSourceWindow;
  345. function EditorWindow(P: PView): boolean; {$ifndef FPC}far;{$endif}
  346. begin
  347. EditorWindow:=(TypeOf(P^)=TypeOf(TSourceWindow)) and
  348. {$ifdef linux}
  349. (PSourceWindow(P)^.Editor^.FileName=Name);
  350. {$else linux}
  351. (UpCaseStr(PSourceWindow(P)^.Editor^.FileName)=UpCaseStr(Name));
  352. {$endif def linux}
  353. end;
  354. begin
  355. EditorWindowFile:=pointer(Desktop^.FirstThat(@EditorWindow));
  356. end;
  357. procedure InsertButtons(ADialog: PDialog);
  358. var R : TRect;
  359. W,H : integer;
  360. X : integer;
  361. X1,X2: Sw_integer;
  362. begin
  363. with ADialog^ do
  364. begin
  365. GetExtent(R);
  366. W:=R.B.X-R.A.X; H:=(R.B.Y-R.A.Y);
  367. R.Assign(0,0,W,H+3); ChangeBounds(R);
  368. X:=W div 2; X1:=X div 2+1; X2:=X+X1-1;
  369. R.Assign(X1-3,H,X1+7,H+2);
  370. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  371. R.Assign(X2-7,H,X2+3,H+2);
  372. Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  373. SelectNext(true);
  374. end;
  375. end;
  376. procedure InsertOK(ADialog: PDialog);
  377. var BW: Sw_integer;
  378. R: TRect;
  379. begin
  380. with ADialog^ do
  381. begin
  382. GetBounds(R); R.Grow(0,1); Inc(R.B.Y);
  383. ChangeBounds(R);
  384. BW:=10;
  385. R.A.Y:=R.B.Y-2; R.B.Y:=R.A.Y+2;
  386. R.A.X:=R.A.X+(R.B.X-R.A.X-BW) div 2; R.B.X:=R.A.X+BW;
  387. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfDefault)));
  388. SelectNext(true);
  389. end;
  390. end;
  391. function GetEditorCurWord(Editor: PEditor): string;
  392. var S: string;
  393. PS,PE: byte;
  394. function Trim(S: string): string;
  395. const TrimChars : set of char = [#0,#9,' ',#255];
  396. begin
  397. while (length(S)>0) and (S[1] in TrimChars) do Delete(S,1,1);
  398. while (length(S)>0) and (S[length(S)] in TrimChars) do Delete(S,length(S),1);
  399. Trim:=S;
  400. end;
  401. const AlphaNum : set of char = ['A'..'Z','0'..'9','_'];
  402. begin
  403. with Editor^ do
  404. begin
  405. {$ifdef EDITORS}
  406. S:='';
  407. {$else}
  408. S:=GetLineText(CurPos.Y);
  409. PS:=CurPos.X; while (PS>0) and (Upcase(S[PS]) in AlphaNum) do Dec(PS);
  410. PE:=CurPos.X; while (PE<length(S)) and (Upcase(S[PE+1]) in AlphaNum) do Inc(PE);
  411. S:=Trim(copy(S,PS+1,PE-PS));
  412. {$endif}
  413. end;
  414. GetEditorCurWord:=S;
  415. end;
  416. {*****************************************************************************
  417. Tab
  418. *****************************************************************************}
  419. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  420. var P: PTabItem;
  421. begin
  422. New(P); FillChar(P^,SizeOf(P^),0);
  423. P^.Next:=ANext; P^.View:=AView;
  424. NewTabItem:=P;
  425. end;
  426. procedure DisposeTabItem(P: PTabItem);
  427. begin
  428. if P<>nil then
  429. begin
  430. if P^.View<>nil then Dispose(P^.View, Done);
  431. Dispose(P);
  432. end;
  433. end;
  434. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  435. var P: PTabDef;
  436. x: byte;
  437. begin
  438. New(P);
  439. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  440. x:=pos('~',AName);
  441. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  442. else P^.ShortCut:=#0;
  443. P^.DefItem:=ADefItem;
  444. NewTabDef:=P;
  445. end;
  446. procedure DisposeTabDef(P: PTabDef);
  447. var PI,X: PTabItem;
  448. begin
  449. DisposeStr(P^.Name);
  450. PI:=P^.Items;
  451. while PI<>nil do
  452. begin
  453. X:=PI^.Next;
  454. DisposeTabItem(PI);
  455. PI:=X;
  456. end;
  457. Dispose(P);
  458. end;
  459. {*****************************************************************************
  460. Reserved Words
  461. *****************************************************************************}
  462. function GetReservedWordCount: integer;
  463. var
  464. Count,I: integer;
  465. begin
  466. Count:=0;
  467. for I:=ord(Low(TokenInfo)) to ord(High(TokenInfo)) do
  468. with TokenInfo[TToken(I)] do
  469. if (str<>'') and (str[1] in['A'..'Z']) then
  470. Inc(Count);
  471. GetReservedWordCount:=Count;
  472. end;
  473. function GetReservedWord(Index: integer): string;
  474. var
  475. Count,Idx,I: integer;
  476. S: string;
  477. begin
  478. Idx:=-1;
  479. Count:=-1;
  480. I:=ord(Low(TokenInfo));
  481. while (I<=ord(High(TokenInfo))) and (Idx=-1) do
  482. with TokenInfo[TToken(I)] do
  483. begin
  484. if (str<>'') and (str[1] in['A'..'Z']) then
  485. begin
  486. Inc(Count);
  487. if Count=Index then
  488. Idx:=I;
  489. end;
  490. Inc(I);
  491. end;
  492. if Idx=-1 then
  493. S:=''
  494. else
  495. S:=TokenInfo[TToken(Idx)].str;
  496. GetReservedWord:=S;
  497. end;
  498. procedure InitReservedWords;
  499. var S,WordS: string;
  500. Idx,I: integer;
  501. begin
  502. New(ReservedWords, Init(50,10));
  503. for I:=1 to GetReservedWordCount do
  504. begin
  505. WordS:=GetReservedWord(I-1); Idx:=length(WordS);
  506. while ReservedWords^.Count<Idx do
  507. ReservedWords^.Insert(NewStr(#0));
  508. S:=ReservedWords^.At(Idx-1)^;
  509. ReservedWords^.AtFree(Idx-1);
  510. ReservedWords^.AtInsert(Idx-1,NewStr(S+WordS+#0));
  511. end;
  512. end;
  513. procedure DoneReservedWords;
  514. begin
  515. if assigned(ReservedWords) then
  516. dispose(ReservedWords,done);
  517. end;
  518. function IsFPReservedWord(S: string): boolean;
  519. var _Is: boolean;
  520. Idx: integer;
  521. P: PString;
  522. begin
  523. Idx:=length(S); _Is:=false;
  524. if (Idx>0) and (ReservedWords<>nil) and (ReservedWords^.Count>=Idx) then
  525. begin
  526. S:=UpcaseStr(S);
  527. P:=ReservedWords^.At(Idx-1);
  528. _Is:=Pos(#0+S+#0,P^)>0;
  529. end;
  530. IsFPReservedWord:=_Is;
  531. end;
  532. {*****************************************************************************
  533. SearchWindow
  534. *****************************************************************************}
  535. function SearchWindowWithNo(No: integer): PWindow;
  536. var P: PSourceWindow;
  537. begin
  538. P:=Message(Desktop,evBroadcast,cmSearchWindow+No,nil);
  539. if pointer(P)=pointer(Desktop) then P:=nil;
  540. SearchWindowWithNo:=P;
  541. end;
  542. function SearchFreeWindowNo: integer;
  543. var No: integer;
  544. begin
  545. No:=1;
  546. while (No<10) and (SearchWindowWithNo(No)<>nil) do
  547. Inc(No);
  548. if No=10 then No:=0;
  549. SearchFreeWindowNo:=No;
  550. end;
  551. {*****************************************************************************
  552. TCenterDialog
  553. *****************************************************************************}
  554. constructor TCenterDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
  555. begin
  556. inherited Init(Bounds,ATitle);
  557. Options:=Options or ofCentered;
  558. end;
  559. {*****************************************************************************
  560. TIntegerLine
  561. *****************************************************************************}
  562. constructor TIntegerLine.Init(var Bounds: TRect; AMin, AMax: longint);
  563. begin
  564. inherited Init(Bounds, Bounds.B.X-Bounds.A.X-1);
  565. Validator:=New(PRangeValidator, Init(AMin, AMax));
  566. end;
  567. {*****************************************************************************
  568. SourceEditor
  569. *****************************************************************************}
  570. {$ifndef EDITORS}
  571. function TSourceEditor.GetSpecSymbolCount(SpecClass: TSpecSymbolClass): integer;
  572. var Count: integer;
  573. begin
  574. case SpecClass of
  575. ssCommentPrefix : Count:=3;
  576. ssCommentSingleLinePrefix : Count:=1;
  577. ssCommentSuffix : Count:=2;
  578. ssStringPrefix : Count:=1;
  579. ssStringSuffix : Count:=1;
  580. ssAsmPrefix : Count:=1;
  581. ssAsmSuffix : Count:=1;
  582. ssDirectivePrefix : Count:=1;
  583. ssDirectiveSuffix : Count:=1;
  584. end;
  585. GetSpecSymbolCount:=Count;
  586. end;
  587. function TSourceEditor.GetSpecSymbol(SpecClass: TSpecSymbolClass; Index: integer): string;
  588. var S: string[20];
  589. begin
  590. case SpecClass of
  591. ssCommentPrefix :
  592. case Index of
  593. 0 : S:='{';
  594. 1 : S:='(*';
  595. 2 : S:='//';
  596. end;
  597. ssCommentSingleLinePrefix :
  598. case Index of
  599. 0 : S:='//';
  600. end;
  601. ssCommentSuffix :
  602. case Index of
  603. 0 : S:='}';
  604. 1 : S:='*)';
  605. end;
  606. ssStringPrefix :
  607. S:='''';
  608. ssStringSuffix :
  609. S:='''';
  610. ssAsmPrefix :
  611. S:='asm';
  612. ssAsmSuffix :
  613. S:='end';
  614. ssDirectivePrefix :
  615. S:='{$';
  616. ssDirectiveSuffix :
  617. S:='}';
  618. end;
  619. GetSpecSymbol:=S;
  620. end;
  621. function TSourceEditor.IsReservedWord(const S: string): boolean;
  622. begin
  623. IsReservedWord:=IsFPReservedWord(S);
  624. end;
  625. {$endif EDITORS}
  626. procedure TSourceEditor.LocalMenu(P: TPoint);
  627. var M: PMenu;
  628. MV: PAdvancedMenuPopUp;
  629. R: TRect;
  630. Re: word;
  631. begin
  632. M:=GetLocalMenu;
  633. if M=nil then Exit;
  634. if LastLocalCmd<>0 then
  635. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  636. Desktop^.GetExtent(R);
  637. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  638. New(MV, Init(R, M));
  639. Re:=Application^.ExecView(MV);
  640. if M^.Default=nil then LastLocalCmd:=0
  641. else LastLocalCmd:=M^.Default^.Command;
  642. Dispose(MV, Done);
  643. if Re<>0 then
  644. Message(GetCommandTarget,evCommand,Re,@Self);
  645. end;
  646. function TSourceEditor.GetLocalMenu: PMenu;
  647. var M: PMenu;
  648. begin
  649. M:=NewMenu(
  650. NewItem('Cu~t~','Shift+Del',kbShiftDel,cmCut,hcCut,
  651. NewItem('~C~opy','Ctrl+Ins',kbCtrlIns,cmCopy,hcCopy,
  652. NewItem('~P~aste','Shift+Ins',kbShiftIns,cmPaste,hcPaste,
  653. NewItem('C~l~ear','Ctrl+Del',kbCtrlDel,cmClear,hcClear,
  654. NewLine(
  655. NewItem('Open ~f~ile at cursor','',kbNoKey,cmOpenAtCursor,hcOpenAtCursor,
  656. NewItem('~B~rowse symbol at cursor','',kbNoKey,cmBrowseAtCursor,hcBrowseAtCursor,
  657. NewItem('Topic ~s~earch','Ctrl+F1',kbCtrlF1,cmHelpTopicSearch,hcHelpTopicSearch,
  658. NewLine(
  659. NewItem('~O~ptions...','',kbNoKey,cmEditorOptions,hcEditorOptions,
  660. nil)))))))))));
  661. GetLocalMenu:=M;
  662. end;
  663. function TSourceEditor.GetCommandTarget: PView;
  664. begin
  665. GetCommandTarget:=@Self;
  666. end;
  667. procedure TSourceEditor.HandleEvent(var Event: TEvent);
  668. var DontClear: boolean;
  669. P: TPoint;
  670. S: string;
  671. begin
  672. TranslateMouseClick(@Self,Event);
  673. case Event.What of
  674. evMouseDown :
  675. if MouseInView(Event.Where) and (Event.Buttons=mbRightButton) then
  676. begin
  677. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  678. LocalMenu(P);
  679. ClearEvent(Event);
  680. end;
  681. evKeyDown :
  682. begin
  683. DontClear:=false;
  684. case Event.KeyCode of
  685. kbAltF10 : Message(@Self,evCommand,cmLocalMenu,@Self);
  686. else DontClear:=true;
  687. end;
  688. if DontClear=false then ClearEvent(Event);
  689. end;
  690. evCommand :
  691. begin
  692. DontClear:=false;
  693. case Event.Command of
  694. cmLocalMenu :
  695. begin
  696. P:=CurPos; Inc(P.X); Inc(P.Y);
  697. LocalMenu(P);
  698. end;
  699. cmBrowseAtCursor:
  700. begin
  701. S:=LowerCaseStr(GetEditorCurWord(@Self));
  702. OpenOneSymbolBrowser(S);
  703. end;
  704. cmOpenAtCursor :
  705. begin
  706. S:=LowerCaseStr(GetEditorCurWord(@Self));
  707. OpenFileName:=S+'.pp'+ListSeparator+
  708. S+'.pas'+ListSeparator+
  709. S+'.inc';
  710. Message(Application,evCommand,cmOpen,nil);
  711. end;
  712. cmEditorOptions :
  713. Message(Application,evCommand,cmEditorOptions,@Self);
  714. cmHelp :
  715. Message(@Self,evCommand,cmHelpTopicSearch,@Self);
  716. cmHelpTopicSearch :
  717. HelpTopicSearch(@Self);
  718. else DontClear:=true;
  719. end;
  720. if not DontClear then ClearEvent(Event);
  721. end;
  722. end;
  723. inherited HandleEvent(Event);
  724. end;
  725. procedure TFPWindow.HandleEvent(var Event: TEvent);
  726. begin
  727. case Event.What of
  728. evBroadcast :
  729. case Event.Command of
  730. cmUpdate :
  731. ReDraw;
  732. cmSearchWindow+1..cmSearchWindow+99 :
  733. if (Event.Command-cmSearchWindow=Number) then
  734. ClearEvent(Event);
  735. end;
  736. end;
  737. inherited HandleEvent(Event);
  738. end;
  739. function TIDEHelpWindow.GetPalette: PPalette;
  740. const P: string[length(CIDEHelpDialog)] = CIDEHelpDialog;
  741. begin
  742. GetPalette:=@P;
  743. end;
  744. constructor TSourceWindow.Init(var Bounds: TRect; AFileName: string);
  745. var HSB,VSB: PScrollBar;
  746. R: TRect;
  747. LoadFile: boolean;
  748. begin
  749. inherited Init(Bounds,AFileName,SearchFreeWindowNo);
  750. Options:=Options or ofTileAble;
  751. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  752. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  753. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  754. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  755. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  756. New(Indicator, Init(R));
  757. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  758. Insert(Indicator);
  759. GetExtent(R); R.Grow(-1,-1);
  760. LoadFile:=AFileName<>'';
  761. if not LoadFile then
  762. begin SetTitle('noname'+IntToStrZ(NonameCount,2)+'.pas'); Inc(NonameCount); end;
  763. New(Editor, Init(R, HSB, VSB, Indicator,AFileName));
  764. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  765. if LoadFile then
  766. if Editor^.LoadFile=false then
  767. ErrorBox(#3'Error reading file.',nil);
  768. Insert(Editor);
  769. UpdateTitle;
  770. end;
  771. procedure TSourceWindow.UpdateTitle;
  772. var Name: string;
  773. begin
  774. if Editor^.FileName<>'' then
  775. begin Name:=SmartPath(Editor^.FileName); SetTitle(Name); end;
  776. end;
  777. procedure TSourceWindow.SetTitle(ATitle: string);
  778. begin
  779. if Title<>nil then DisposeStr(Title);
  780. Title:=NewStr(ATitle);
  781. Frame^.DrawView;
  782. end;
  783. procedure TSourceWindow.HandleEvent(var Event: TEvent);
  784. var DontClear: boolean;
  785. begin
  786. case Event.What of
  787. evBroadcast :
  788. case Event.Command of
  789. cmUpdate :
  790. Update;
  791. cmUpdateTitle :
  792. UpdateTitle;
  793. cmSearchWindow :
  794. if @Self<>ClipboardWindow then
  795. ClearEvent(Event);
  796. end;
  797. evCommand :
  798. begin
  799. DontClear:=false;
  800. case Event.Command of
  801. cmSave :
  802. if Editor^.IsClipboard=false then
  803. Editor^.Save;
  804. cmSaveAs :
  805. if Editor^.IsClipboard=false then
  806. Editor^.SaveAs;
  807. else DontClear:=true;
  808. end;
  809. if DontClear=false then ClearEvent(Event);
  810. end;
  811. end;
  812. inherited HandleEvent(Event);
  813. end;
  814. procedure TSourceWindow.SetState(AState: Word; Enable: Boolean);
  815. var OldState: word;
  816. begin
  817. OldState:=State;
  818. inherited SetState(AState,Enable);
  819. if ((AState xor State) and sfActive)<>0 then
  820. UpdateCommands;
  821. end;
  822. procedure TSourceWindow.UpdateCommands;
  823. var Active: boolean;
  824. begin
  825. Active:=GetState(sfActive);
  826. if Editor^.IsClipboard=false then
  827. begin
  828. SetCmdState(SourceCmds+CompileCmds,Active);
  829. SetCmdState(EditorCmds,Active);
  830. end;
  831. if Active=false then
  832. SetCmdState(ToClipCmds+FromClipCmds+UndoCmds,false);
  833. end;
  834. procedure TSourceWindow.Update;
  835. begin
  836. ReDraw;
  837. end;
  838. function TSourceWindow.GetPalette: PPalette;
  839. const P: string[length(CSourceWindow)] = CSourceWindow;
  840. begin
  841. GetPalette:=@P;
  842. end;
  843. destructor TSourceWindow.Done;
  844. begin
  845. Message(Application,evBroadcast,cmSourceWndClosing,@Self);
  846. inherited Done;
  847. Message(Application,evBroadcast,cmUpdate,@Self);
  848. end;
  849. function TGDBSourceEditor.Valid(Command: Word): Boolean;
  850. var OK: boolean;
  851. begin
  852. OK:=TCodeEditor.Valid(Command);
  853. { do NOT ask for save !!
  854. if OK and ((Command=cmClose) or (Command=cmQuit)) then
  855. if IsClipboard=false then
  856. OK:=SaveAsk; }
  857. Valid:=OK;
  858. end;
  859. procedure TGDBSourceEditor.AddLine(const S: string);
  860. begin
  861. if Silent or (IgnoreStringAtEnd and (S=LastCommand)) then exit;
  862. inherited AddLine(S);
  863. LimitsChanged;
  864. end;
  865. procedure TGDBSourceEditor.AddErrorLine(const S: string);
  866. begin
  867. if Silent then exit;
  868. inherited AddLine(S);
  869. { display like breakpoints in red }
  870. Lines^.At(GetLineCount-1)^.IsBreakpoint:=true;
  871. LimitsChanged;
  872. end;
  873. function TGDBSourceEditor.InsertLine: Sw_integer;
  874. Var
  875. S : string;
  876. begin
  877. if IsReadOnly then begin InsertLine:=-1; Exit; end;
  878. if CurPos.Y<GetLineCount then S:=GetLineText(CurPos.Y) else S:='';
  879. s:=Copy(S,1,CurPos.X);
  880. if assigned(Debugger) then
  881. if S<>'' then
  882. begin
  883. LastCommand:=S;
  884. { should be true only if we are at the end ! }
  885. IgnoreStringAtEnd:=(CurPos.Y=GetLineCount-1) and (CurPos.X=length(GetDisplayText(GetLineCount-1)));
  886. Debugger^.Command(S);
  887. IgnoreStringAtEnd:=false;
  888. end
  889. else if AutoRepeat then
  890. Debugger^.Command(LastCommand);
  891. InsertLine:=inherited InsertLine;
  892. end;
  893. constructor TGDBWindow.Init(var Bounds: TRect);
  894. var HSB,VSB: PScrollBar;
  895. R: TRect;
  896. begin
  897. inherited Init(Bounds,'GDB window',SearchFreeWindowNo);
  898. Options:=Options or ofTileAble;
  899. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  900. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  901. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  902. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  903. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  904. New(Indicator, Init(R));
  905. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  906. Insert(Indicator);
  907. GetExtent(R); R.Grow(-1,-1);
  908. New(Editor, Init(R, HSB, VSB, nil, GDBOutputFile));
  909. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  910. if ExistsFile(GDBOutputFile) then
  911. begin
  912. if Editor^.LoadFile=false then
  913. ErrorBox(#3'Error reading file.',nil);
  914. end
  915. else
  916. { Empty files are buggy !! }
  917. Editor^.AddLine('');
  918. Insert(Editor);
  919. if assigned(Debugger) then
  920. Debugger^.Command('set width '+IntToStr(Size.X-1));
  921. Editor^.silent:=false;
  922. Editor^.AutoRepeat:=true;
  923. end;
  924. destructor TGDBWindow.Done;
  925. begin
  926. if @Self=GDBWindow then
  927. GDBWindow:=nil;
  928. inherited Done;
  929. end;
  930. function TGDBWindow.GetPalette: PPalette;
  931. const P: string[length(CSourceWindow)] = CSourceWindow;
  932. begin
  933. GetPalette:=@P;
  934. end;
  935. procedure TGDBWindow.WriteOutputText(Buf : pchar);
  936. begin
  937. {selected normal color ?}
  938. WriteText(Buf,false);
  939. end;
  940. procedure TGDBWindow.WriteErrorText(Buf : pchar);
  941. begin
  942. {selected normal color ?}
  943. WriteText(Buf,true);
  944. end;
  945. procedure TGDBWindow.WriteString(Const S : string);
  946. begin
  947. Editor^.AddLine(S);
  948. end;
  949. procedure TGDBWindow.WriteErrorString(Const S : string);
  950. begin
  951. Editor^.AddErrorLine(S);
  952. end;
  953. procedure TGDBWindow.WriteText(Buf : pchar;IsError : boolean);
  954. var p,pe : pchar;
  955. s : string;
  956. begin
  957. p:=buf;
  958. DeskTop^.Lock;
  959. While assigned(p) do
  960. begin
  961. pe:=strscan(p,#10);
  962. if pe<>nil then
  963. pe^:=#0;
  964. s:=strpas(p);
  965. If IsError then
  966. Editor^.AddErrorLine(S)
  967. else
  968. Editor^.AddLine(S);
  969. { restore for dispose }
  970. if pe<>nil then
  971. pe^:=#10;
  972. if pe=nil then
  973. p:=nil
  974. else
  975. begin
  976. p:=pe;
  977. inc(p);
  978. end;
  979. end;
  980. DeskTop^.Unlock;
  981. Editor^.Draw;
  982. end;
  983. constructor TClipboardWindow.Init;
  984. var R: TRect;
  985. HSB,VSB: PScrollBar;
  986. begin
  987. Desktop^.GetExtent(R);
  988. inherited Init(R, '');
  989. SetTitle('Clipboard');
  990. HelpCtx:=hcClipboardWindow;
  991. Number:=wnNoNumber;
  992. GetExtent(R); R.A.Y:=R.B.Y-1; R.Grow(-1,0); R.A.X:=14;
  993. New(HSB, Init(R)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  994. GetExtent(R); R.A.X:=R.B.X-1; R.Grow(0,-1);
  995. New(VSB, Init(R)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  996. GetExtent(R); R.A.X:=3; R.B.X:=14; R.A.Y:=R.B.Y-1;
  997. New(Indicator, Init(R));
  998. Indicator^.GrowMode:=gfGrowLoY+gfGrowHiY;
  999. Insert(Indicator);
  1000. GetExtent(R); R.Grow(-1,-1);
  1001. New(Editor, Init(R, HSB, VSB, Indicator, ''));
  1002. Editor^.GrowMode:=gfGrowHiX+gfGrowHiY;
  1003. Insert(Editor);
  1004. Hide;
  1005. Clipboard:=Editor;
  1006. end;
  1007. procedure TClipboardWindow.Close;
  1008. begin
  1009. Hide;
  1010. end;
  1011. destructor TClipboardWindow.Done;
  1012. begin
  1013. inherited Done;
  1014. Clipboard:=nil;
  1015. ClipboardWindow:=nil;
  1016. end;
  1017. function TAdvancedMenuBox.NewSubView(var Bounds: TRect; AMenu: PMenu;
  1018. AParentMenu: PMenuView): PMenuView;
  1019. begin
  1020. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  1021. end;
  1022. function TAdvancedMenuBox.Execute: word;
  1023. type
  1024. MenuAction = (DoNothing, DoSelect, DoReturn);
  1025. var
  1026. AutoSelect: Boolean;
  1027. Action: MenuAction;
  1028. Ch: Char;
  1029. Result: Word;
  1030. ItemShown, P: PMenuItem;
  1031. Target: PMenuView;
  1032. R: TRect;
  1033. E: TEvent;
  1034. MouseActive: Boolean;
  1035. function IsDisabled(Item: PMenuItem): boolean;
  1036. var Found: boolean;
  1037. begin
  1038. Found:=Item^.Disabled or IsSeparator(Item);
  1039. if (Found=false) and (IsSubMenu(Item)=false) then
  1040. Found:=CommandEnabled(Item^.Command)=false;
  1041. IsDisabled:=Found;
  1042. end;
  1043. procedure TrackMouse;
  1044. var
  1045. Mouse: TPoint;
  1046. R: TRect;
  1047. OldC: PMenuItem;
  1048. begin
  1049. MakeLocal(E.Where, Mouse);
  1050. OldC:=Current;
  1051. Current := Menu^.Items;
  1052. while Current <> nil do
  1053. begin
  1054. GetItemRect(Current, R);
  1055. if R.Contains(Mouse) then
  1056. begin
  1057. MouseActive := True;
  1058. Break;
  1059. end;
  1060. Current := Current^.Next;
  1061. end;
  1062. if (Current<>nil) and IsDisabled(Current) then
  1063. begin
  1064. Current:={OldC}nil;
  1065. MouseActive:=false;
  1066. end;
  1067. end;
  1068. procedure TrackKey(FindNext: Boolean);
  1069. procedure NextItem;
  1070. begin
  1071. Current := Current^.Next;
  1072. if Current = nil then Current := Menu^.Items;
  1073. end;
  1074. procedure PrevItem;
  1075. var
  1076. P: PMenuItem;
  1077. begin
  1078. P := Current;
  1079. if P = Menu^.Items then P := nil;
  1080. repeat NextItem until Current^.Next = P;
  1081. end;
  1082. begin
  1083. if Current <> nil then
  1084. repeat
  1085. if FindNext then NextItem else PrevItem;
  1086. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  1087. end;
  1088. function MouseInOwner: Boolean;
  1089. var
  1090. Mouse: TPoint;
  1091. R: TRect;
  1092. begin
  1093. MouseInOwner := False;
  1094. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  1095. begin
  1096. ParentMenu^.MakeLocal(E.Where, Mouse);
  1097. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  1098. MouseInOwner := R.Contains(Mouse);
  1099. end;
  1100. end;
  1101. function MouseInMenus: Boolean;
  1102. var
  1103. P: PMenuView;
  1104. begin
  1105. P := ParentMenu;
  1106. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  1107. P := P^.ParentMenu;
  1108. MouseInMenus := P <> nil;
  1109. end;
  1110. function TopMenu: PMenuView;
  1111. var
  1112. P: PMenuView;
  1113. begin
  1114. P := @Self;
  1115. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  1116. TopMenu := P;
  1117. end;
  1118. begin
  1119. AutoSelect := False; E.What:=evNothing;
  1120. Result := 0;
  1121. ItemShown := nil;
  1122. Current := Menu^.Default;
  1123. MouseActive := False;
  1124. if UpdateMenu(Menu) then
  1125. begin
  1126. if Current<>nil then
  1127. if Current^.Disabled then
  1128. TrackKey(true);
  1129. repeat
  1130. Action := DoNothing;
  1131. GetEvent(E);
  1132. case E.What of
  1133. evMouseDown:
  1134. if MouseInView(E.Where) or MouseInOwner then
  1135. begin
  1136. TrackMouse;
  1137. if Size.Y = 1 then AutoSelect := True;
  1138. end else Action := DoReturn;
  1139. evMouseUp:
  1140. begin
  1141. TrackMouse;
  1142. if MouseInOwner then
  1143. Current := Menu^.Default
  1144. else
  1145. if (Current <> nil) and (Current^.Name <> nil) then
  1146. Action := DoSelect
  1147. else
  1148. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  1149. else
  1150. begin
  1151. Current := Menu^.Default;
  1152. if Current = nil then Current := Menu^.Items;
  1153. Action := DoNothing;
  1154. end;
  1155. end;
  1156. evMouseMove:
  1157. if E.Buttons <> 0 then
  1158. begin
  1159. TrackMouse;
  1160. if not (MouseInView(E.Where) or MouseInOwner) and
  1161. MouseInMenus then Action := DoReturn;
  1162. end;
  1163. evKeyDown:
  1164. case CtrlToArrow(E.KeyCode) of
  1165. kbUp, kbDown:
  1166. if Size.Y <> 1 then
  1167. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  1168. if E.KeyCode = kbDown then AutoSelect := True;
  1169. kbLeft, kbRight:
  1170. if ParentMenu = nil then
  1171. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  1172. Action := DoReturn;
  1173. kbHome, kbEnd:
  1174. if Size.Y <> 1 then
  1175. begin
  1176. Current := Menu^.Items;
  1177. if E.KeyCode = kbEnd then TrackKey(False);
  1178. end;
  1179. kbEnter:
  1180. begin
  1181. if Size.Y = 1 then AutoSelect := True;
  1182. Action := DoSelect;
  1183. end;
  1184. kbEsc:
  1185. begin
  1186. Action := DoReturn;
  1187. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  1188. ClearEvent(E);
  1189. end;
  1190. else
  1191. Target := @Self;
  1192. Ch := GetAltChar(E.KeyCode);
  1193. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  1194. P := Target^.FindItem(Ch);
  1195. if P = nil then
  1196. begin
  1197. P := TopMenu^.HotKey(E.KeyCode);
  1198. if (P <> nil) and CommandEnabled(P^.Command) then
  1199. begin
  1200. Result := P^.Command;
  1201. Action := DoReturn;
  1202. end
  1203. end else
  1204. if Target = @Self then
  1205. begin
  1206. if Size.Y = 1 then AutoSelect := True;
  1207. Action := DoSelect;
  1208. Current := P;
  1209. end else
  1210. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  1211. Action := DoReturn;
  1212. end;
  1213. evCommand:
  1214. if E.Command = cmMenu then
  1215. begin
  1216. AutoSelect := False;
  1217. if ParentMenu <> nil then Action := DoReturn;
  1218. end else Action := DoReturn;
  1219. end;
  1220. if ItemShown <> Current then
  1221. begin
  1222. ItemShown := Current;
  1223. DrawView;
  1224. end;
  1225. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  1226. if Current <> nil then with Current^ do if Name <> nil then
  1227. if Command = 0 then
  1228. begin
  1229. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  1230. GetItemRect(Current, R);
  1231. R.A.X := R.A.X + Origin.X;
  1232. R.A.Y := R.B.Y + Origin.Y;
  1233. R.B := Owner^.Size;
  1234. if Size.Y = 1 then Dec(R.A.X);
  1235. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  1236. Result := Owner^.ExecView(Target);
  1237. Dispose(Target, Done);
  1238. end else if Action = DoSelect then Result := Command;
  1239. if (Result <> 0) and CommandEnabled(Result) then
  1240. begin
  1241. Action := DoReturn;
  1242. ClearEvent(E);
  1243. end
  1244. else
  1245. Result := 0;
  1246. until Action = DoReturn;
  1247. end;
  1248. if E.What <> evNothing then
  1249. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  1250. if Current <> nil then
  1251. begin
  1252. Menu^.Default := Current;
  1253. Current := nil;
  1254. DrawView;
  1255. end;
  1256. Execute := Result;
  1257. end;
  1258. function TAdvancedMenuPopup.NewSubView(var Bounds: TRect; AMenu: PMenu;
  1259. AParentMenu: PMenuView): PMenuView;
  1260. begin
  1261. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  1262. end;
  1263. function TAdvancedMenuPopup.Execute: word;
  1264. type
  1265. MenuAction = (DoNothing, DoSelect, DoReturn);
  1266. var
  1267. AutoSelect: Boolean;
  1268. Action: MenuAction;
  1269. Ch: Char;
  1270. Result: Word;
  1271. ItemShown, P: PMenuItem;
  1272. Target: PMenuView;
  1273. R: TRect;
  1274. E: TEvent;
  1275. MouseActive: Boolean;
  1276. function IsDisabled(Item: PMenuItem): boolean;
  1277. var Found: boolean;
  1278. begin
  1279. Found:=Item^.Disabled or IsSeparator(Item);
  1280. if (Found=false) and (IsSubMenu(Item)=false) then
  1281. Found:=CommandEnabled(Item^.Command)=false;
  1282. IsDisabled:=Found;
  1283. end;
  1284. procedure TrackMouse;
  1285. var
  1286. Mouse: TPoint;
  1287. R: TRect;
  1288. OldC: PMenuItem;
  1289. begin
  1290. MakeLocal(E.Where, Mouse);
  1291. OldC:=Current;
  1292. Current := Menu^.Items;
  1293. while Current <> nil do
  1294. begin
  1295. GetItemRect(Current, R);
  1296. if R.Contains(Mouse) then
  1297. begin
  1298. MouseActive := True;
  1299. Break;
  1300. end;
  1301. Current := Current^.Next;
  1302. end;
  1303. if (Current<>nil) and IsDisabled(Current) then
  1304. begin
  1305. Current:={OldC}nil;
  1306. MouseActive:=false;
  1307. end;
  1308. end;
  1309. procedure TrackKey(FindNext: Boolean);
  1310. procedure NextItem;
  1311. begin
  1312. Current := Current^.Next;
  1313. if Current = nil then Current := Menu^.Items;
  1314. end;
  1315. procedure PrevItem;
  1316. var
  1317. P: PMenuItem;
  1318. begin
  1319. P := Current;
  1320. if P = Menu^.Items then P := nil;
  1321. repeat NextItem until Current^.Next = P;
  1322. end;
  1323. begin
  1324. if Current <> nil then
  1325. repeat
  1326. if FindNext then NextItem else PrevItem;
  1327. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  1328. end;
  1329. function MouseInOwner: Boolean;
  1330. var
  1331. Mouse: TPoint;
  1332. R: TRect;
  1333. begin
  1334. MouseInOwner := False;
  1335. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  1336. begin
  1337. ParentMenu^.MakeLocal(E.Where, Mouse);
  1338. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  1339. MouseInOwner := R.Contains(Mouse);
  1340. end;
  1341. end;
  1342. function MouseInMenus: Boolean;
  1343. var
  1344. P: PMenuView;
  1345. begin
  1346. P := ParentMenu;
  1347. while (P <> nil) and (P^.MouseInView(E.Where)=false) do
  1348. P := P^.ParentMenu;
  1349. MouseInMenus := P <> nil;
  1350. end;
  1351. function TopMenu: PMenuView;
  1352. var
  1353. P: PMenuView;
  1354. begin
  1355. P := @Self;
  1356. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  1357. TopMenu := P;
  1358. end;
  1359. begin
  1360. AutoSelect := False; E.What:=evNothing;
  1361. Result := 0;
  1362. ItemShown := nil;
  1363. Current := Menu^.Default;
  1364. MouseActive := False;
  1365. if UpdateMenu(Menu) then
  1366. begin
  1367. if Current<>nil then
  1368. if Current^.Disabled then
  1369. TrackKey(true);
  1370. repeat
  1371. Action := DoNothing;
  1372. GetEvent(E);
  1373. case E.What of
  1374. evMouseDown:
  1375. if MouseInView(E.Where) or MouseInOwner then
  1376. begin
  1377. TrackMouse;
  1378. if Size.Y = 1 then AutoSelect := True;
  1379. end else Action := DoReturn;
  1380. evMouseUp:
  1381. begin
  1382. TrackMouse;
  1383. if MouseInOwner then
  1384. Current := Menu^.Default
  1385. else
  1386. if (Current <> nil) and (Current^.Name <> nil) then
  1387. Action := DoSelect
  1388. else
  1389. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  1390. else
  1391. begin
  1392. Current := Menu^.Default;
  1393. if Current = nil then Current := Menu^.Items;
  1394. Action := DoNothing;
  1395. end;
  1396. end;
  1397. evMouseMove:
  1398. if E.Buttons <> 0 then
  1399. begin
  1400. TrackMouse;
  1401. if not (MouseInView(E.Where) or MouseInOwner) and
  1402. MouseInMenus then Action := DoReturn;
  1403. end;
  1404. evKeyDown:
  1405. case CtrlToArrow(E.KeyCode) of
  1406. kbUp, kbDown:
  1407. if Size.Y <> 1 then
  1408. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  1409. if E.KeyCode = kbDown then AutoSelect := True;
  1410. kbLeft, kbRight:
  1411. if ParentMenu = nil then
  1412. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  1413. Action := DoReturn;
  1414. kbHome, kbEnd:
  1415. if Size.Y <> 1 then
  1416. begin
  1417. Current := Menu^.Items;
  1418. if E.KeyCode = kbEnd then TrackKey(False);
  1419. end;
  1420. kbEnter:
  1421. begin
  1422. if Size.Y = 1 then AutoSelect := True;
  1423. Action := DoSelect;
  1424. end;
  1425. kbEsc:
  1426. begin
  1427. Action := DoReturn;
  1428. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  1429. ClearEvent(E);
  1430. end;
  1431. else
  1432. Target := @Self;
  1433. Ch := GetAltChar(E.KeyCode);
  1434. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  1435. P := Target^.FindItem(Ch);
  1436. if P = nil then
  1437. begin
  1438. P := TopMenu^.HotKey(E.KeyCode);
  1439. if (P <> nil) and CommandEnabled(P^.Command) then
  1440. begin
  1441. Result := P^.Command;
  1442. Action := DoReturn;
  1443. end
  1444. end else
  1445. if Target = @Self then
  1446. begin
  1447. if Size.Y = 1 then AutoSelect := True;
  1448. Action := DoSelect;
  1449. Current := P;
  1450. end else
  1451. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  1452. Action := DoReturn;
  1453. end;
  1454. evCommand:
  1455. if E.Command = cmMenu then
  1456. begin
  1457. AutoSelect := False;
  1458. if ParentMenu <> nil then Action := DoReturn;
  1459. end else Action := DoReturn;
  1460. end;
  1461. if ItemShown <> Current then
  1462. begin
  1463. ItemShown := Current;
  1464. DrawView;
  1465. end;
  1466. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  1467. if Current <> nil then with Current^ do if Name <> nil then
  1468. if Command = 0 then
  1469. begin
  1470. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  1471. GetItemRect(Current, R);
  1472. R.A.X := R.A.X + Origin.X;
  1473. R.A.Y := R.B.Y + Origin.Y;
  1474. R.B := Owner^.Size;
  1475. if Size.Y = 1 then Dec(R.A.X);
  1476. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  1477. Result := Owner^.ExecView(Target);
  1478. Dispose(Target, Done);
  1479. end else if Action = DoSelect then Result := Command;
  1480. if (Result <> 0) and CommandEnabled(Result) then
  1481. begin
  1482. Action := DoReturn;
  1483. ClearEvent(E);
  1484. end
  1485. else
  1486. Result := 0;
  1487. until Action = DoReturn;
  1488. end;
  1489. if E.What <> evNothing then
  1490. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  1491. if Current <> nil then
  1492. begin
  1493. Menu^.Default := Current;
  1494. Current := nil;
  1495. DrawView;
  1496. end;
  1497. Execute := Result;
  1498. end;
  1499. constructor TAdvancedMenuBar.Init(var Bounds: TRect; AMenu: PMenu);
  1500. begin
  1501. inherited Init(Bounds, AMenu);
  1502. EventMask:=EventMask or evBroadcast;
  1503. end;
  1504. function TAdvancedMenuBar.NewSubView(var Bounds: TRect; AMenu: PMenu;
  1505. AParentMenu: PMenuView): PMenuView;
  1506. begin
  1507. NewSubView := New(PAdvancedMenuBox, Init(Bounds, AMenu, AParentMenu));
  1508. end;
  1509. procedure TAdvancedMenuBar.Update;
  1510. begin
  1511. UpdateMenu(Menu);
  1512. DrawView;
  1513. end;
  1514. procedure TAdvancedMenuBar.HandleEvent(var Event: TEvent);
  1515. begin
  1516. case Event.What of
  1517. evBroadcast :
  1518. case Event.Command of
  1519. cmUpdate : Update;
  1520. end;
  1521. end;
  1522. inherited HandleEvent(Event);
  1523. end;
  1524. function TAdvancedMenuBar.Execute: word;
  1525. type
  1526. MenuAction = (DoNothing, DoSelect, DoReturn);
  1527. var
  1528. AutoSelect: Boolean;
  1529. Action: MenuAction;
  1530. Ch: Char;
  1531. Result: Word;
  1532. ItemShown, P: PMenuItem;
  1533. Target: PMenuView;
  1534. R: TRect;
  1535. E: TEvent;
  1536. MouseActive: Boolean;
  1537. function IsDisabled(Item: PMenuItem): boolean;
  1538. var Dis : boolean;
  1539. begin
  1540. Dis:=Item^.Disabled or IsSeparator(Item);
  1541. if (Dis=false) and (IsSubMenu(Item)=false) then
  1542. Dis:=CommandEnabled(Item^.Command)=false;
  1543. IsDisabled:=Dis;
  1544. end;
  1545. procedure TrackMouse;
  1546. var
  1547. Mouse: TPoint;
  1548. R: TRect;
  1549. OldC: PMenuItem;
  1550. begin
  1551. MakeLocal(E.Where, Mouse);
  1552. OldC:=Current;
  1553. Current := Menu^.Items;
  1554. while Current <> nil do
  1555. begin
  1556. GetItemRect(Current, R);
  1557. if R.Contains(Mouse) then
  1558. begin
  1559. MouseActive := True;
  1560. Break;
  1561. end;
  1562. Current := Current^.Next;
  1563. end;
  1564. if (Current<>nil) and IsDisabled(Current) then
  1565. Current:=nil;
  1566. end;
  1567. procedure TrackKey(FindNext: Boolean);
  1568. procedure NextItem;
  1569. begin
  1570. Current := Current^.Next;
  1571. if Current = nil then Current := Menu^.Items;
  1572. end;
  1573. procedure PrevItem;
  1574. var
  1575. P: PMenuItem;
  1576. begin
  1577. P := Current;
  1578. if P = Menu^.Items then P := nil;
  1579. repeat NextItem until Current^.Next = P;
  1580. end;
  1581. begin
  1582. if Current <> nil then
  1583. repeat
  1584. if FindNext then NextItem else PrevItem;
  1585. until (Current^.Name <> nil) and (IsDisabled(Current)=false);
  1586. end;
  1587. function MouseInOwner: Boolean;
  1588. var
  1589. Mouse: TPoint;
  1590. R: TRect;
  1591. begin
  1592. MouseInOwner := False;
  1593. if (ParentMenu <> nil) and (ParentMenu^.Size.Y = 1) then
  1594. begin
  1595. ParentMenu^.MakeLocal(E.Where, Mouse);
  1596. ParentMenu^.GetItemRect(ParentMenu^.Current, R);
  1597. MouseInOwner := R.Contains(Mouse);
  1598. end;
  1599. end;
  1600. function MouseInMenus: Boolean;
  1601. var
  1602. P: PMenuView;
  1603. begin
  1604. P := ParentMenu;
  1605. while (P <> nil) and not P^.MouseInView(E.Where) do P := P^.ParentMenu;
  1606. MouseInMenus := P <> nil;
  1607. end;
  1608. function TopMenu: PMenuView;
  1609. var
  1610. P: PMenuView;
  1611. begin
  1612. P := @Self;
  1613. while P^.ParentMenu <> nil do P := P^.ParentMenu;
  1614. TopMenu := P;
  1615. end;
  1616. begin
  1617. AutoSelect := False; E.What:=evNothing;
  1618. Result := 0;
  1619. ItemShown := nil;
  1620. Current := Menu^.Default;
  1621. MouseActive := False;
  1622. if UpdateMenu(Menu) then
  1623. begin
  1624. if Current<>nil then
  1625. if Current^.Disabled then
  1626. TrackKey(true);
  1627. repeat
  1628. Action := DoNothing;
  1629. GetEvent(E);
  1630. case E.What of
  1631. evMouseDown:
  1632. if MouseInView(E.Where) or MouseInOwner then
  1633. begin
  1634. TrackMouse;
  1635. if Size.Y = 1 then AutoSelect := True;
  1636. end else Action := DoReturn;
  1637. evMouseUp:
  1638. begin
  1639. TrackMouse;
  1640. if MouseInOwner then
  1641. Current := Menu^.Default
  1642. else
  1643. if (Current <> nil) and (Current^.Name <> nil) then
  1644. Action := DoSelect
  1645. else
  1646. if MouseActive or MouseInView(E.Where) then Action := DoReturn
  1647. else
  1648. begin
  1649. Current := Menu^.Default;
  1650. if Current = nil then Current := Menu^.Items;
  1651. Action := DoNothing;
  1652. end;
  1653. end;
  1654. evMouseMove:
  1655. if E.Buttons <> 0 then
  1656. begin
  1657. TrackMouse;
  1658. if not (MouseInView(E.Where) or MouseInOwner) and
  1659. MouseInMenus then Action := DoReturn;
  1660. end;
  1661. evKeyDown:
  1662. case CtrlToArrow(E.KeyCode) of
  1663. kbUp, kbDown:
  1664. if Size.Y <> 1 then
  1665. TrackKey(CtrlToArrow(E.KeyCode) = kbDown) else
  1666. if E.KeyCode = kbDown then AutoSelect := True;
  1667. kbLeft, kbRight:
  1668. if ParentMenu = nil then
  1669. TrackKey(CtrlToArrow(E.KeyCode) = kbRight) else
  1670. Action := DoReturn;
  1671. kbHome, kbEnd:
  1672. if Size.Y <> 1 then
  1673. begin
  1674. Current := Menu^.Items;
  1675. if E.KeyCode = kbEnd then TrackKey(False);
  1676. end;
  1677. kbEnter:
  1678. begin
  1679. if Size.Y = 1 then AutoSelect := True;
  1680. Action := DoSelect;
  1681. end;
  1682. kbEsc:
  1683. begin
  1684. Action := DoReturn;
  1685. if (ParentMenu = nil) or (ParentMenu^.Size.Y <> 1) then
  1686. ClearEvent(E);
  1687. end;
  1688. else
  1689. Target := @Self;
  1690. Ch := GetAltChar(E.KeyCode);
  1691. if Ch = #0 then Ch := E.CharCode else Target := TopMenu;
  1692. P := Target^.FindItem(Ch);
  1693. if P = nil then
  1694. begin
  1695. P := TopMenu^.HotKey(E.KeyCode);
  1696. if (P <> nil) and CommandEnabled(P^.Command) then
  1697. begin
  1698. Result := P^.Command;
  1699. Action := DoReturn;
  1700. end
  1701. end else
  1702. if Target = @Self then
  1703. begin
  1704. if Size.Y = 1 then AutoSelect := True;
  1705. Action := DoSelect;
  1706. Current := P;
  1707. end else
  1708. if (ParentMenu <> Target) or (ParentMenu^.Current <> P) then
  1709. Action := DoReturn;
  1710. end;
  1711. evCommand:
  1712. if E.Command = cmMenu then
  1713. begin
  1714. AutoSelect := False;
  1715. if ParentMenu <> nil then Action := DoReturn;
  1716. end else Action := DoReturn;
  1717. end;
  1718. if ItemShown <> Current then
  1719. begin
  1720. ItemShown := Current;
  1721. DrawView;
  1722. end;
  1723. if (Action = DoSelect) or ((Action = DoNothing) and AutoSelect) then
  1724. if Current <> nil then with Current^ do if Name <> nil then
  1725. if Command = 0 then
  1726. begin
  1727. if E.What and (evMouseDown + evMouseMove) <> 0 then PutEvent(E);
  1728. GetItemRect(Current, R);
  1729. R.A.X := R.A.X + Origin.X;
  1730. R.A.Y := R.B.Y + Origin.Y;
  1731. R.B := Owner^.Size;
  1732. if Size.Y = 1 then Dec(R.A.X);
  1733. Target := TopMenu^.NewSubView(R, SubMenu, @Self);
  1734. Result := Owner^.ExecView(Target);
  1735. Dispose(Target, Done);
  1736. end else if Action = DoSelect then Result := Command;
  1737. if (Result <> 0) and CommandEnabled(Result) then
  1738. begin
  1739. Action := DoReturn;
  1740. ClearEvent(E);
  1741. end
  1742. else
  1743. Result := 0;
  1744. until Action = DoReturn;
  1745. end;
  1746. if E.What <> evNothing then
  1747. if (ParentMenu <> nil) or (E.What = evCommand) then PutEvent(E);
  1748. if Current <> nil then
  1749. begin
  1750. Menu^.Default := Current;
  1751. Current := nil;
  1752. DrawView;
  1753. end;
  1754. Execute := Result;
  1755. end;
  1756. procedure ErrorBox(const S: string; Params: pointer);
  1757. begin
  1758. MessageBox(S,Params,mfError+mfInsertInApp+mfOKButton);
  1759. end;
  1760. procedure WarningBox(const S: string; Params: pointer);
  1761. begin
  1762. MessageBox(S,Params,mfWarning+mfInsertInApp+mfOKButton);
  1763. end;
  1764. procedure InformationBox(const S: string; Params: pointer);
  1765. begin
  1766. MessageBox(S,Params,mfInformation+mfInsertInApp+mfOKButton);
  1767. end;
  1768. function ConfirmBox(const S: string; Params: pointer; CanCancel: boolean): word;
  1769. begin
  1770. ConfirmBox:=MessageBox(S,Params,mfConfirmation+mfInsertInApp+mfYesButton+mfNoButton+integer(CanCancel)*mfCancelButton);
  1771. end;
  1772. function IsSeparator(P: PMenuItem): boolean;
  1773. begin
  1774. IsSeparator:=(P<>nil) and (P^.Name=nil) and (P^.HelpCtx=hcNoContext);
  1775. end;
  1776. function IsSubMenu(P: PMenuItem): boolean;
  1777. begin
  1778. IsSubMenu:=(P<>nil) and (P^.Name<>nil) and (P^.Command=0) and (P^.SubMenu<>nil);
  1779. end;
  1780. function SearchMenuItem(Menu: PMenu; Cmd: word): PMenuItem;
  1781. var P,I: PMenuItem;
  1782. begin
  1783. I:=nil;
  1784. if Menu=nil then P:=nil else P:=Menu^.Items;
  1785. while (P<>nil) and (I=nil) do
  1786. begin
  1787. if IsSubMenu(P) then
  1788. I:=SearchMenuItem(P^.SubMenu,Cmd);
  1789. if I=nil then
  1790. if P^.Command=Cmd then I:=P else
  1791. P:=P^.Next;
  1792. end;
  1793. SearchMenuItem:=I;
  1794. end;
  1795. procedure SetMenuItemParam(Menu: PMenuItem; Param: string);
  1796. begin
  1797. if Menu=nil then Exit;
  1798. if Menu^.Param<>nil then DisposeStr(Menu^.Param);
  1799. Menu^.Param:=NewStr(Param);
  1800. end;
  1801. function UpdateMenu(M: PMenu): boolean;
  1802. var P: PMenuItem;
  1803. IsEnabled: boolean;
  1804. begin
  1805. if M=nil then begin UpdateMenu:=false; Exit; end;
  1806. P:=M^.Items; IsEnabled:=false;
  1807. while (P<>nil) do
  1808. begin
  1809. if IsSubMenu(P) then
  1810. P^.Disabled:=not UpdateMenu(P^.SubMenu);
  1811. if (IsSeparator(P)=false) and (P^.Disabled=false) and (Application^.CommandEnabled(P^.Command)=true) then
  1812. IsEnabled:=true;
  1813. P:=P^.Next;
  1814. end;
  1815. UpdateMenu:=IsEnabled;
  1816. end;
  1817. function SearchSubMenu(M: PMenu; Index: integer): PMenuItem;
  1818. var P,C: PMenuItem;
  1819. Count: integer;
  1820. begin
  1821. P:=nil; Count:=-1;
  1822. if M<>nil then C:=M^.Items else C:=nil;
  1823. while (C<>nil) and (P=nil) do
  1824. begin
  1825. if IsSubMenu(C) then
  1826. begin
  1827. Inc(Count);
  1828. if Count=Index then P:=C;
  1829. end;
  1830. C:=C^.Next;
  1831. end;
  1832. SearchSubMenu:=P;
  1833. end;
  1834. procedure AppendMenuItem(M: PMenu; I: PMenuItem);
  1835. var P: PMenuItem;
  1836. begin
  1837. if (M=nil) or (I=nil) then Exit;
  1838. I^.Next:=nil;
  1839. if M^.Items=nil then M^.Items:=I else
  1840. begin
  1841. P:=M^.Items;
  1842. while (P^.Next<>nil) do P:=P^.Next;
  1843. P^.Next:=I;
  1844. end;
  1845. end;
  1846. procedure DisposeMenuItem(P: PMenuItem);
  1847. begin
  1848. if P<>nil then
  1849. begin
  1850. if IsSubMenu(P) then DisposeMenu(P^.SubMenu) else
  1851. if IsSeparator(P)=false then
  1852. if P^.Param<>nil then DisposeStr(P^.Param);
  1853. if P^.Name<>nil then DisposeStr(P^.Name);
  1854. Dispose(P);
  1855. end;
  1856. end;
  1857. procedure RemoveMenuItem(Menu: PMenu; I: PMenuItem);
  1858. var P,PrevP: PMenuItem;
  1859. begin
  1860. if (Menu=nil) or (I=nil) then Exit;
  1861. P:=Menu^.Items; PrevP:=nil;
  1862. while (P<>nil) do
  1863. begin
  1864. if P=I then
  1865. begin
  1866. if Menu^.Items<>I then PrevP^.Next:=P^.Next
  1867. else Menu^.Items:=P^.Next;
  1868. DisposeMenuItem(P);
  1869. Break;
  1870. end;
  1871. PrevP:=P; P:=P^.Next;
  1872. end;
  1873. end;
  1874. function GetMenuItemBefore(Menu: PMenu; BeforeOf: PMenuItem): PMenuItem;
  1875. var P,C: PMenuItem;
  1876. begin
  1877. P:=nil;
  1878. if Menu<>nil then C:=Menu^.Items else C:=nil;
  1879. while (C<>nil) do
  1880. begin
  1881. if C^.Next=BeforeOf then begin P:=C; Break; end;
  1882. C:=C^.Next;
  1883. end;
  1884. GetMenuItemBefore:=P;
  1885. end;
  1886. procedure TAdvancedStaticText.SetText(S: string);
  1887. begin
  1888. if Text<>nil then DisposeStr(Text);
  1889. Text:=NewStr(S);
  1890. DrawView;
  1891. end;
  1892. procedure TAdvancedListBox.HandleEvent(var Event: TEvent);
  1893. begin
  1894. case Event.What of
  1895. evMouseDown :
  1896. if MouseInView(Event.Where) and (Event.Double) then
  1897. begin
  1898. inherited HandleEvent(Event);
  1899. if Range>Focused then SelectItem(Focused);
  1900. end;
  1901. evBroadcast :
  1902. case Event.Command of
  1903. cmListItemSelected :
  1904. Message(Owner,evBroadcast,cmDefault,nil);
  1905. end;
  1906. end;
  1907. inherited HandleEvent(Event);
  1908. end;
  1909. constructor TColorStaticText.Init(var Bounds: TRect; AText: String; AColor: word);
  1910. begin
  1911. inherited Init(Bounds,AText);
  1912. Color:=AColor;
  1913. end;
  1914. procedure TColorStaticText.Draw;
  1915. var
  1916. C: word;
  1917. Center: Boolean;
  1918. I, J, L, P, Y: Integer;
  1919. B: TDrawBuffer;
  1920. S: String;
  1921. T: string;
  1922. CurS: string;
  1923. TildeCount,Po: integer;
  1924. TempS: string;
  1925. begin
  1926. if Size.X=0 then Exit;
  1927. if DontWrap=false then
  1928. begin
  1929. C:=Color;
  1930. GetText(S);
  1931. L := Length(S);
  1932. P := 1;
  1933. Y := 0;
  1934. Center := False;
  1935. while Y < Size.Y do
  1936. begin
  1937. MoveChar(B, ' ', Lo(C), Size.X);
  1938. if P <= L then
  1939. begin
  1940. if S[P] = #3 then
  1941. begin
  1942. Center := True;
  1943. Inc(P);
  1944. end;
  1945. I := P;
  1946. repeat
  1947. J := P;
  1948. while (P <= L) and (S[P] = ' ') do Inc(P);
  1949. while (P <= L) and (S[P] <> ' ') and (S[P] <> #13) do Inc(P);
  1950. until (P > L) or (P >= I + Size.X) or (S[P] = #13);
  1951. TildeCount:=0; TempS:=copy(S,I,P-I);
  1952. repeat
  1953. Po:=Pos('~',TempS);
  1954. if Po>0 then begin Inc(TildeCount); Delete(TempS,1,Po); end;
  1955. until Po=0;
  1956. if P > I + Size.X + TildeCount then
  1957. if J > I then P := J else P := I + Size.X;
  1958. T:=copy(S,I,P-I);
  1959. if Center then J := (Size.X - {P + I}CStrLen(T)) div 2 else J := 0;
  1960. MoveCStr(B[J],T,C);
  1961. while (P <= L) and (S[P] = ' ') do Inc(P);
  1962. if (P <= L) and (S[P] = #13) then
  1963. begin
  1964. Center := False;
  1965. Inc(P);
  1966. if (P <= L) and (S[P] = #10) then Inc(P);
  1967. end;
  1968. end;
  1969. WriteLine(0, Y, Size.X, 1, B);
  1970. Inc(Y);
  1971. end;
  1972. end { Wrap=false } else
  1973. begin
  1974. C := Color;
  1975. GetText(S);
  1976. I:=1;
  1977. for Y:=0 to Size.Y-1 do
  1978. begin
  1979. MoveChar(B, ' ', Lo(C), Size.X);
  1980. CurS:='';
  1981. if S<>'' then
  1982. begin
  1983. P:=Pos(#13,S);
  1984. if P=0 then P:=length(S)+1;
  1985. CurS:=copy(S,1,P-1);
  1986. CurS:=copy(CurS,Delta.X+1,255);
  1987. CurS:=copy(CurS,1,MaxViewWidth);
  1988. Delete(S,1,P);
  1989. end;
  1990. if CurS<>'' then MoveCStr(B,CurS,C);
  1991. WriteLine(0,Y,Size.X,1,B);
  1992. end;
  1993. end;
  1994. end;
  1995. function TUnsortedStringCollection.At(Index: Integer): PString;
  1996. begin
  1997. At:=inherited At(Index);
  1998. end;
  1999. procedure TUnsortedStringCollection.FreeItem(Item: Pointer);
  2000. begin
  2001. if Item<>nil then DisposeStr(Item);
  2002. end;
  2003. constructor THSListBox.Init(var Bounds: TRect; ANumCols: Word; AHScrollBar, AVScrollBar: PScrollBar);
  2004. begin
  2005. inherited Init(Bounds,ANumCols,AVScrollBar);
  2006. HScrollBar:=AHScrollBar;
  2007. end;
  2008. constructor TDlgWindow.Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  2009. begin
  2010. inherited Init(Bounds,ATitle);
  2011. Number:=ANumber;
  2012. Flags:=Flags or (wfMove + wfGrow + wfClose + wfZoom);
  2013. end;
  2014. procedure TLocalMenuListBox.LocalMenu(P: TPoint);
  2015. var M: PMenu;
  2016. MV: PAdvancedMenuPopUp;
  2017. R: TRect;
  2018. Re: word;
  2019. begin
  2020. M:=GetLocalMenu;
  2021. if M=nil then Exit;
  2022. if LastLocalCmd<>0 then
  2023. M^.Default:=SearchMenuItem(M,LastLocalCmd);
  2024. Desktop^.GetExtent(R);
  2025. MakeGlobal(P,R.A); {Desktop^.MakeLocal(R.A,R.A);}
  2026. New(MV, Init(R, M));
  2027. Re:=Application^.ExecView(MV);
  2028. if M^.Default=nil then LastLocalCmd:=0
  2029. else LastLocalCmd:=M^.Default^.Command;
  2030. Dispose(MV, Done);
  2031. if Re<>0 then
  2032. Message(GetCommandTarget,evCommand,Re,@Self);
  2033. end;
  2034. function TLocalMenuListBox.GetLocalMenu: PMenu;
  2035. begin
  2036. GetLocalMenu:=nil;
  2037. Abstract;
  2038. end;
  2039. function TLocalMenuListBox.GetCommandTarget: PView;
  2040. begin
  2041. GetCommandTarget:=@Self;
  2042. end;
  2043. procedure TLocalMenuListBox.HandleEvent(var Event: TEvent);
  2044. var DontClear: boolean;
  2045. P: TPoint;
  2046. begin
  2047. case Event.What of
  2048. evMouseDown :
  2049. if MouseInView(Event.Where) and (Event.Buttons=mbRightButton) then
  2050. begin
  2051. MakeLocal(Event.Where,P); Inc(P.X); Inc(P.Y);
  2052. LocalMenu(P);
  2053. ClearEvent(Event);
  2054. end;
  2055. evKeyDown :
  2056. begin
  2057. DontClear:=false;
  2058. case Event.KeyCode of
  2059. kbAltF10 : Message(@Self,evCommand,cmLocalMenu,@Self);
  2060. else DontClear:=true;
  2061. end;
  2062. if DontClear=false then ClearEvent(Event);
  2063. end;
  2064. evCommand :
  2065. begin
  2066. DontClear:=false;
  2067. case Event.Command of
  2068. cmLocalMenu :
  2069. begin
  2070. P:=Cursor; Inc(P.X); Inc(P.Y);
  2071. LocalMenu(P);
  2072. end;
  2073. else DontClear:=true;
  2074. end;
  2075. if not DontClear then ClearEvent(Event);
  2076. end;
  2077. end;
  2078. inherited HandleEvent(Event);
  2079. end;
  2080. constructor TMessageListBox.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  2081. begin
  2082. inherited Init(Bounds,1,AHScrollBar, AVScrollBar);
  2083. NoSelection:=true;
  2084. end;
  2085. function TMessageListBox.GetLocalMenu: PMenu;
  2086. var M: PMenu;
  2087. begin
  2088. if (Owner<>nil) and (Owner^.GetState(sfModal)) then M:=nil else
  2089. M:=NewMenu(
  2090. NewItem('~C~lear','',kbNoKey,cmMsgClear,hcMsgClear,
  2091. NewLine(
  2092. NewItem('~G~oto source','',kbNoKey,cmMsgGotoSource,hcMsgGotoSource,
  2093. NewItem('~T~rack source','',kbNoKey,cmMsgTrackSource,hcMsgTrackSource,
  2094. nil)))));
  2095. GetLocalMenu:=M;
  2096. end;
  2097. procedure TMessageListBox.HandleEvent(var Event: TEvent);
  2098. var DontClear: boolean;
  2099. begin
  2100. case Event.What of
  2101. evKeyDown :
  2102. begin
  2103. DontClear:=false;
  2104. case Event.KeyCode of
  2105. kbEnter :
  2106. if Owner<>pointer(SD) then
  2107. Message(@Self,evCommand,cmMsgGotoSource,nil);
  2108. else DontClear:=true;
  2109. end;
  2110. if DontClear=false then ClearEvent(Event);
  2111. end;
  2112. evBroadcast :
  2113. case Event.Command of
  2114. cmListItemSelected :
  2115. if Event.InfoPtr=@Self then
  2116. Message(@Self,evCommand,cmMsgTrackSource,nil);
  2117. end;
  2118. evCommand :
  2119. begin
  2120. DontClear:=false;
  2121. case Event.Command of
  2122. cmMsgGotoSource :
  2123. if Range>0 then
  2124. GotoSource;
  2125. cmMsgTrackSource :
  2126. if Range>0 then
  2127. TrackSource;
  2128. cmMsgClear :
  2129. Clear;
  2130. else DontClear:=true;
  2131. end;
  2132. if DontClear=false then ClearEvent(Event);
  2133. end;
  2134. end;
  2135. inherited HandleEvent(Event);
  2136. end;
  2137. procedure TMessageListBox.AddItem(P: PMessageItem);
  2138. var W: integer;
  2139. begin
  2140. if List=nil then New(List, Init(500,500));
  2141. W:=length(P^.GetText(255));
  2142. if W>MaxWidth then
  2143. begin
  2144. MaxWidth:=W;
  2145. if HScrollBar<>nil then
  2146. HScrollBar^.SetRange(0,MaxWidth);
  2147. end;
  2148. List^.Insert(P);
  2149. SetRange(List^.Count);
  2150. if Focused=List^.Count-1-1 then
  2151. FocusItem(List^.Count-1);
  2152. DrawView;
  2153. end;
  2154. function TMessageListBox.GetText(Item: Integer; MaxLen: Integer): String;
  2155. var P: PMessageItem;
  2156. S: string;
  2157. begin
  2158. P:=List^.At(Item);
  2159. S:=P^.GetText(MaxLen);
  2160. GetText:=copy(S,1,MaxLen);
  2161. end;
  2162. procedure TMessageListBox.Clear;
  2163. begin
  2164. if List<>nil then Dispose(List, Done); List:=nil; MaxWidth:=0;
  2165. SetRange(0); DrawView;
  2166. end;
  2167. procedure TMessageListBox.TrackSource;
  2168. var W: PSourceWindow;
  2169. P: PMessageItem;
  2170. R: TRect;
  2171. begin
  2172. if Range=0 then Exit;
  2173. P:=List^.At(Focused);
  2174. if P^.ID=0 then Exit;
  2175. Desktop^.Lock;
  2176. GetNextEditorBounds(R);
  2177. if Assigned(Owner) and (Owner=pointer(ProgramInfoWindow)) then
  2178. R.B.Y:=Owner^.Origin.Y;
  2179. W:=EditorWindowFile(P^.GetModuleName);
  2180. if assigned(W) then
  2181. begin
  2182. W^.GetExtent(R);
  2183. if Assigned(Owner) and (Owner=pointer(ProgramInfoWindow)) then
  2184. R.B.Y:=Owner^.Origin.Y;
  2185. W^.ChangeBounds(R);
  2186. W^.Editor^.SetCurPtr(P^.Col-1,P^.ID-1);
  2187. end
  2188. else
  2189. W:=TryToOpenFile(@R,P^.GetModuleName,P^.Col-1,P^.ID-1);
  2190. if W<>nil then
  2191. begin
  2192. W^.Select;
  2193. W^.Editor^.SetHighlightRow(P^.ID-1);
  2194. end;
  2195. if Assigned(Owner) then
  2196. Owner^.Select;
  2197. Desktop^.UnLock;
  2198. end;
  2199. procedure TMessageListBox.GotoSource;
  2200. var W: PSourceWindow;
  2201. P: PMessageItem;
  2202. begin
  2203. if Range=0 then Exit;
  2204. P:=List^.At(Focused);
  2205. if P^.ID=0 then Exit;
  2206. Desktop^.Lock;
  2207. W:=TryToOpenFile(nil,P^.GetModuleName,P^.Col-1,P^.ID-1);
  2208. Message(Owner,evCommand,cmClose,nil);
  2209. Desktop^.UnLock;
  2210. end;
  2211. procedure TMessageListBox.Draw;
  2212. var
  2213. I, J, Item: Integer;
  2214. NormalColor, SelectedColor, FocusedColor, Color: Word;
  2215. ColWidth, CurCol, Indent: Integer;
  2216. B: TDrawBuffer;
  2217. Text: String;
  2218. SCOff: Byte;
  2219. TC: byte;
  2220. procedure MT(var C: word); begin if TC<>0 then C:=(C and $ff0f) or (TC and $f0); end;
  2221. begin
  2222. if (Owner<>nil) then TC:=ord(Owner^.GetColor(6)) else TC:=0;
  2223. if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2224. begin
  2225. NormalColor := GetColor(1);
  2226. FocusedColor := GetColor(3);
  2227. SelectedColor := GetColor(4);
  2228. end else
  2229. begin
  2230. NormalColor := GetColor(2);
  2231. SelectedColor := GetColor(4);
  2232. end;
  2233. if Transparent then
  2234. begin MT(NormalColor); MT(SelectedColor); end;
  2235. if NoSelection then
  2236. SelectedColor:=NormalColor;
  2237. if HScrollBar <> nil then Indent := HScrollBar^.Value
  2238. else Indent := 0;
  2239. ColWidth := Size.X div NumCols + 1;
  2240. for I := 0 to Size.Y - 1 do
  2241. begin
  2242. for J := 0 to NumCols-1 do
  2243. begin
  2244. Item := J*Size.Y + I + TopItem;
  2245. CurCol := J*ColWidth;
  2246. if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2247. (Focused = Item) and (Range > 0) then
  2248. begin
  2249. Color := FocusedColor;
  2250. SetCursor(CurCol+1,I);
  2251. SCOff := 0;
  2252. end
  2253. else if (Item < Range) and IsSelected(Item) then
  2254. begin
  2255. Color := SelectedColor;
  2256. SCOff := 2;
  2257. end
  2258. else
  2259. begin
  2260. Color := NormalColor;
  2261. SCOff := 4;
  2262. end;
  2263. MoveChar(B[CurCol], ' ', Color, ColWidth);
  2264. if Item < Range then
  2265. begin
  2266. Text := GetText(Item, ColWidth + Indent);
  2267. Text := Copy(Text,Indent,ColWidth);
  2268. MoveStr(B[CurCol+1], Text, Color);
  2269. if ShowMarkers then
  2270. begin
  2271. WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2272. WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2273. end;
  2274. end;
  2275. MoveChar(B[CurCol+ColWidth-1], #179, GetColor(5), 1);
  2276. end;
  2277. WriteLine(0, I, Size.X, 1, B);
  2278. end;
  2279. end;
  2280. destructor TMessageListBox.Done;
  2281. begin
  2282. inherited Done;
  2283. if List<>nil then Dispose(List, Done);
  2284. end;
  2285. constructor TMessageItem.Init(AClass: longint; AText, AModule: string; AID,ACol: longint);
  2286. begin
  2287. inherited Init;
  2288. TClass:=AClass;
  2289. Text:=NewStr(AText);
  2290. Module:=NewStr(AModule);
  2291. ID:=AID;
  2292. Col:=ACol;
  2293. end;
  2294. function TMessageItem.GetText(MaxLen: integer): string;
  2295. var S: string;
  2296. begin
  2297. if Text=nil then S:='' else S:=Text^;
  2298. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  2299. GetText:=S;
  2300. end;
  2301. procedure TMessageItem.Selected;
  2302. begin
  2303. end;
  2304. function TMessageItem.GetModuleName: string;
  2305. begin
  2306. GetModuleName:=GetStr(Module);
  2307. end;
  2308. destructor TMessageItem.Done;
  2309. begin
  2310. inherited Done;
  2311. if Text<>nil then DisposeStr(Text);
  2312. if Module<>nil then DisposeStr(Module);
  2313. end;
  2314. function TCompilerMessage.GetText(MaxLen: Integer): String;
  2315. var ClassS: string[20];
  2316. S: string;
  2317. begin
  2318. if TClass=
  2319. V_Fatal then ClassS:='Fatal' else if TClass =
  2320. V_Error then ClassS:='Error' else if TClass =
  2321. V_Normal then ClassS:='' else if TClass =
  2322. V_Warning then ClassS:='Warning' else if TClass =
  2323. V_Note then ClassS:='Note' else if TClass =
  2324. V_Hint then ClassS:='Hint' else if TClass =
  2325. V_Macro then ClassS:='Macro' else if TClass =
  2326. V_Procedure then ClassS:='Procedure' else if TClass =
  2327. V_Conditional then ClassS:='Conditional' else if TClass =
  2328. V_Info then ClassS:='Info' else if TClass =
  2329. V_Status then ClassS:='Status' else if TClass =
  2330. V_Used then ClassS:='Used' else if TClass =
  2331. V_Tried then ClassS:='Tried' else if TClass =
  2332. V_Debug then ClassS:='Debug'
  2333. else
  2334. ClassS:='???';
  2335. if ClassS<>'' then
  2336. ClassS:=RExpand(ClassS,0)+': ';
  2337. S:=ClassS;
  2338. if (Module<>nil) {and (ID<>0)} then
  2339. S:=S+Module^+' ('+IntToStr(ID)+'): ';
  2340. if Text<>nil then S:=ClassS+Text^;
  2341. if length(S)>MaxLen then S:=copy(S,1,MaxLen-2)+'..';
  2342. GetText:=S;
  2343. end;
  2344. constructor TProgramInfoWindow.Init;
  2345. var R,R2: TRect;
  2346. HSB,VSB: PScrollBar;
  2347. ST: PStaticText;
  2348. C: word;
  2349. const White = 15;
  2350. begin
  2351. Desktop^.GetExtent(R); R.A.Y:=R.B.Y-13;
  2352. inherited Init(R, 'Program Information', wnNoNumber);
  2353. HelpCtx:=hcInfoWindow;
  2354. GetExtent(R); R.Grow(-1,-1); R.B.Y:=R.A.Y+3;
  2355. C:=((Desktop^.GetColor(32+6) and $f0) or White)*256+Desktop^.GetColor(32+6);
  2356. New(InfoST, Init(R,'', C)); InfoST^.GrowMode:=gfGrowHiX;
  2357. InfoST^.DontWrap:=true;
  2358. Insert(InfoST);
  2359. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,3); R.B.Y:=R.A.Y+1;
  2360. New(ST, Init(R, CharStr('Ä', MaxViewWidth))); ST^.GrowMode:=gfGrowHiX; Insert(ST);
  2361. GetExtent(R); R.Grow(-1,-1); Inc(R.A.Y,4);
  2362. R2.Copy(R); Inc(R2.B.Y); R2.A.Y:=R2.B.Y-1;
  2363. New(HSB, Init(R2)); HSB^.GrowMode:=gfGrowLoY+gfGrowHiY+gfGrowHiX; Insert(HSB);
  2364. R2.Copy(R); Inc(R2.B.X); R2.A.X:=R2.B.X-1;
  2365. New(VSB, Init(R2)); VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2366. New(LogLB, Init(R,HSB,VSB));
  2367. LogLB^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2368. LogLB^.Transparent:=true;
  2369. Insert(LogLB);
  2370. Update;
  2371. end;
  2372. procedure TProgramInfoWindow.AddMessage(AClass: longint; Msg, Module: string; Line,Column: longint);
  2373. begin
  2374. if AClass>=V_Info then Line:=0;
  2375. LogLB^.AddItem(New(PCompilerMessage, Init(AClass, Msg, Module, Line,Column)));
  2376. end;
  2377. procedure TProgramInfoWindow.ClearMessages;
  2378. begin
  2379. LogLB^.Clear;
  2380. ReDraw;
  2381. end;
  2382. procedure TProgramInfoWindow.SizeLimits(var Min, Max: TPoint);
  2383. begin
  2384. inherited SizeLimits(Min,Max);
  2385. Min.X:=30; Min.Y:=9;
  2386. end;
  2387. procedure TProgramInfoWindow.Close;
  2388. begin
  2389. Hide;
  2390. end;
  2391. procedure TProgramInfoWindow.HandleEvent(var Event: TEvent);
  2392. begin
  2393. case Event.What of
  2394. evBroadcast :
  2395. case Event.Command of
  2396. cmUpdate :
  2397. Update;
  2398. end;
  2399. end;
  2400. inherited HandleEvent(Event);
  2401. end;
  2402. procedure TProgramInfoWindow.Update;
  2403. begin
  2404. InfoST^.SetText(
  2405. {#13+ }
  2406. ' Current module : '+MainFile+#13+
  2407. ' Last exit code : '+IntToStr(LastExitCode)+#13+
  2408. ' Available memory : '+IntToStrL(MemAvail div 1024,5)+'K'+#13+
  2409. ''
  2410. );
  2411. end;
  2412. destructor TProgramInfoWindow.Done;
  2413. begin
  2414. inherited Done;
  2415. ProgramInfoWindow:=nil;
  2416. end;
  2417. function TAdvancedStatusLine.GetStatusText: string;
  2418. var S: string;
  2419. begin
  2420. if StatusText=nil then S:='' else S:=StatusText^;
  2421. GetStatusText:=S;
  2422. end;
  2423. procedure TAdvancedStatusLine.SetStatusText(const S: string);
  2424. begin
  2425. if StatusText<>nil then DisposeStr(StatusText);
  2426. StatusText:=NewStr(S);
  2427. DrawView;
  2428. end;
  2429. procedure TAdvancedStatusLine.ClearStatusText;
  2430. begin
  2431. SetStatusText('');
  2432. end;
  2433. procedure TAdvancedStatusLine.Draw;
  2434. var B: TDrawBuffer;
  2435. C: word;
  2436. S: string;
  2437. begin
  2438. S:=GetStatusText;
  2439. if S='' then inherited Draw else
  2440. begin
  2441. C:=GetColor(1);
  2442. MoveChar(B,' ',C,Size.X);
  2443. MoveStr(B[1],S,C);
  2444. WriteLine(0,0,Size.X,Size.Y,B);
  2445. end;
  2446. end;
  2447. constructor TTab.Init(var Bounds: TRect; ATabDef: PTabDef);
  2448. begin
  2449. inherited Init(Bounds);
  2450. Options:=Options or ofSelectable or ofFirstClick or ofPreProcess or ofPostProcess;
  2451. GrowMode:=gfGrowHiX+gfGrowHiY+gfGrowRel;
  2452. TabDefs:=ATabDef;
  2453. ActiveDef:=-1;
  2454. SelectTab(0);
  2455. ReDraw;
  2456. end;
  2457. function TTab.TabCount: integer;
  2458. var i: integer;
  2459. P: PTabDef;
  2460. begin
  2461. I:=0; P:=TabDefs;
  2462. while (P<>nil) do
  2463. begin
  2464. Inc(I);
  2465. P:=P^.Next;
  2466. end;
  2467. TabCount:=I;
  2468. end;
  2469. function TTab.AtTab(Index: integer): PTabDef;
  2470. var i: integer;
  2471. P: PTabDef;
  2472. begin
  2473. i:=0; P:=TabDefs;
  2474. while (I<Index) do
  2475. begin
  2476. if P=nil then RunError($AA);
  2477. P:=P^.Next;
  2478. Inc(i);
  2479. end;
  2480. AtTab:=P;
  2481. end;
  2482. procedure TTab.SelectTab(Index: integer);
  2483. var P: PTabItem;
  2484. V: PView;
  2485. begin
  2486. if ActiveDef<>Index then
  2487. begin
  2488. if Owner<>nil then Owner^.Lock;
  2489. Lock;
  2490. { --- Update --- }
  2491. if TabDefs<>nil then
  2492. begin
  2493. DefCount:=1;
  2494. while AtTab(DefCount-1)^.Next<>nil do Inc(DefCount);
  2495. end
  2496. else DefCount:=0;
  2497. if ActiveDef<>-1 then
  2498. begin
  2499. P:=AtTab(ActiveDef)^.Items;
  2500. while P<>nil do
  2501. begin
  2502. if P^.View<>nil then Delete(P^.View);
  2503. P:=P^.Next;
  2504. end;
  2505. end;
  2506. ActiveDef:=Index;
  2507. P:=AtTab(ActiveDef)^.Items;
  2508. while P<>nil do
  2509. begin
  2510. if P^.View<>nil then Insert(P^.View);
  2511. P:=P^.Next;
  2512. end;
  2513. V:=AtTab(ActiveDef)^.DefItem;
  2514. if V<>nil then V^.Select;
  2515. ReDraw;
  2516. { --- Update --- }
  2517. UnLock;
  2518. if Owner<>nil then Owner^.UnLock;
  2519. DrawView;
  2520. end;
  2521. end;
  2522. procedure TTab.ChangeBounds(var Bounds: TRect);
  2523. var D: TPoint;
  2524. procedure DoCalcChange(P: PView); {$ifndef FPC}far;{$endif}
  2525. var
  2526. R: TRect;
  2527. begin
  2528. if P^.Owner=nil then Exit; { it think this is a bug in TV }
  2529. P^.CalcBounds(R, D);
  2530. P^.ChangeBounds(R);
  2531. end;
  2532. var
  2533. P: PTabItem;
  2534. I: integer;
  2535. begin
  2536. D.X := Bounds.B.X - Bounds.A.X - Size.X;
  2537. D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  2538. inherited ChangeBounds(Bounds);
  2539. for I:=0 to TabCount-1 do
  2540. if I<>ActiveDef then
  2541. begin
  2542. P:=AtTab(I)^.Items;
  2543. while P<>nil do
  2544. begin
  2545. if P^.View<>nil then DoCalcChange(P^.View);
  2546. P:=P^.Next;
  2547. end;
  2548. end;
  2549. end;
  2550. procedure TTab.HandleEvent(var Event: TEvent);
  2551. var Index : integer;
  2552. I : integer;
  2553. X : integer;
  2554. Len : byte;
  2555. P : TPoint;
  2556. V : PView;
  2557. CallOrig: boolean;
  2558. LastV : PView;
  2559. FirstV: PView;
  2560. function FirstSelectable: PView;
  2561. var
  2562. FV : PView;
  2563. begin
  2564. FV := First;
  2565. while (FV<>nil) and ((FV^.Options and ofSelectable)=0) and (FV<>Last) do
  2566. FV:=FV^.Next;
  2567. if FV<>nil then
  2568. if (FV^.Options and ofSelectable)=0 then FV:=nil;
  2569. FirstSelectable:=FV;
  2570. end;
  2571. function LastSelectable: PView;
  2572. var
  2573. LV : PView;
  2574. begin
  2575. LV := Last;
  2576. while (LV<>nil) and ((LV^.Options and ofSelectable)=0) and (LV<>First) do
  2577. LV:=LV^.Prev;
  2578. if LV<>nil then
  2579. if (LV^.Options and ofSelectable)=0 then LV:=nil;
  2580. LastSelectable:=LV;
  2581. end;
  2582. begin
  2583. if (Event.What and evMouseDown)<>0 then
  2584. begin
  2585. MakeLocal(Event.Where,P);
  2586. if P.Y<3 then
  2587. begin
  2588. Index:=-1; X:=1;
  2589. for i:=0 to DefCount-1 do
  2590. begin
  2591. Len:=CStrLen(AtTab(i)^.Name^);
  2592. if (P.X>=X) and (P.X<=X+Len+1) then Index:=i;
  2593. X:=X+Len+3;
  2594. end;
  2595. if Index<>-1 then
  2596. SelectTab(Index);
  2597. end;
  2598. end;
  2599. if Event.What=evKeyDown then
  2600. begin
  2601. Index:=-1;
  2602. case Event.KeyCode of
  2603. kbTab,kbShiftTab :
  2604. if GetState(sfSelected) then
  2605. begin
  2606. if Current<>nil then
  2607. begin
  2608. LastV:=LastSelectable; FirstV:=FirstSelectable;
  2609. if ((Current=LastV) or (Current=PLabel(LastV)^.Link)) and (Event.KeyCode=kbShiftTab) then
  2610. begin
  2611. if Owner<>nil then Owner^.SelectNext(true);
  2612. end else
  2613. if ((Current=FirstV) or (Current=PLabel(FirstV)^.Link)) and (Event.KeyCode=kbTab) then
  2614. begin
  2615. Lock;
  2616. if Owner<>nil then Owner^.SelectNext(false);
  2617. UnLock;
  2618. end else
  2619. SelectNext(Event.KeyCode=kbShiftTab);
  2620. ClearEvent(Event);
  2621. end;
  2622. end;
  2623. else
  2624. for I:=0 to DefCount-1 do
  2625. begin
  2626. if Upcase(GetAltChar(Event.KeyCode))=AtTab(I)^.ShortCut
  2627. then begin
  2628. Index:=I;
  2629. ClearEvent(Event);
  2630. Break;
  2631. end;
  2632. end;
  2633. end;
  2634. if Index<>-1 then
  2635. begin
  2636. Select;
  2637. SelectTab(Index);
  2638. V:=AtTab(ActiveDef)^.DefItem;
  2639. if V<>nil then V^.Focus;
  2640. end;
  2641. end;
  2642. CallOrig:=true;
  2643. if Event.What=evKeyDown then
  2644. begin
  2645. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  2646. then
  2647. else CallOrig:=false;
  2648. end;
  2649. if CallOrig then inherited HandleEvent(Event);
  2650. end;
  2651. function TTab.GetPalette: PPalette;
  2652. begin
  2653. GetPalette:=nil;
  2654. end;
  2655. procedure TTab.Draw;
  2656. var B : TDrawBuffer;
  2657. i : integer;
  2658. C1,C2,C3,C : word;
  2659. HeaderLen : integer;
  2660. X,X2 : integer;
  2661. Name : PString;
  2662. ActiveKPos : integer;
  2663. ActiveVPos : integer;
  2664. FC : char;
  2665. ClipR : TRect;
  2666. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  2667. var i: integer;
  2668. begin
  2669. if Y+H>Size.Y then H:=Size.Y-Y;
  2670. if X+W>Size.X then W:=Size.X-X;
  2671. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  2672. else for i:=1 to H do
  2673. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  2674. end;
  2675. procedure ClearBuf;
  2676. begin
  2677. MoveChar(B,' ',C1,Size.X);
  2678. end;
  2679. begin
  2680. if InDraw then Exit;
  2681. InDraw:=true;
  2682. { - Start of TGroup.Draw - }
  2683. if Buffer = nil then
  2684. begin
  2685. GetBuffer;
  2686. end;
  2687. { - Start of TGroup.Draw - }
  2688. C1:=GetColor(1); C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256; C3:=GetColor(8)+GetColor({9}8)*256;
  2689. HeaderLen:=0; for i:=0 to DefCount-1 do HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3; Dec(HeaderLen);
  2690. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  2691. { --- 1. sor --- }
  2692. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[HeaderLen+1],'³',C1,1);
  2693. X:=1;
  2694. for i:=0 to DefCount-1 do
  2695. begin
  2696. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  2697. if i=ActiveDef
  2698. then begin
  2699. ActiveKPos:=X-1;
  2700. ActiveVPos:=X+X2+2;
  2701. if GetState(sfFocused) then C:=C3 else C:=C2;
  2702. end
  2703. else C:=C2;
  2704. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  2705. MoveChar(B[X-1],'³',C1,1);
  2706. end;
  2707. SWriteBuf(0,1,Size.X,1,B);
  2708. { --- 0. sor --- }
  2709. ClearBuf; MoveChar(B[0],'Ú',C1,1);
  2710. X:=1;
  2711. for i:=0 to DefCount-1 do
  2712. begin
  2713. if I<ActiveDef then FC:='Ú'
  2714. else FC:='¿';
  2715. X2:=CStrLen(AtTab(i)^.Name^)+2;
  2716. MoveChar(B[X+X2],{'Â'}FC,C1,1);
  2717. if i=DefCount-1 then X2:=X2+1;
  2718. if X2>0 then
  2719. MoveChar(B[X],'Ä',C1,X2);
  2720. X:=X+X2+1;
  2721. end;
  2722. MoveChar(B[HeaderLen+1],'¿',C1,1);
  2723. MoveChar(B[ActiveKPos],'Ú',C1,1); MoveChar(B[ActiveVPos],'¿',C1,1);
  2724. SWriteBuf(0,0,Size.X,1,B);
  2725. { --- 2. sor --- }
  2726. MoveChar(B[1],'Ä',C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],'Ä',C1,Max(Size.X-HeaderLen-3,0));
  2727. MoveChar(B[Size.X-1],'¿',C1,1);
  2728. MoveChar(B[ActiveKPos],'Ù',C1,1);
  2729. if ActiveDef=0 then MoveChar(B[0],'³',C1,1)
  2730. else MoveChar(B[0],{'Ã'}'Ú',C1,1);
  2731. MoveChar(B[HeaderLen+1],'Ä'{'Á'},C1,1); MoveChar(B[ActiveVPos],'À',C1,1);
  2732. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  2733. SWriteBuf(0,2,Size.X,1,B);
  2734. { --- marad‚k sor --- }
  2735. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[Size.X-1],'³',C1,1);
  2736. SWriteBuf(0,3,Size.X,Size.Y-4,B);
  2737. { --- Size.X . sor --- }
  2738. MoveChar(B[0],'À',C1,1); MoveChar(B[1],'Ä',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],'Ù',C1,1);
  2739. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  2740. { - End of TGroup.Draw - }
  2741. if Buffer <> nil then
  2742. begin
  2743. Lock;
  2744. Redraw;
  2745. UnLock;
  2746. end;
  2747. if Buffer <> nil then WriteBuf(0, 0, Size.X, Size.Y, Buffer^) else
  2748. begin
  2749. GetClipRect(ClipR);
  2750. Redraw;
  2751. GetExtent(ClipR);
  2752. end;
  2753. { - End of TGroup.Draw - }
  2754. InDraw:=false;
  2755. end;
  2756. function TTab.Valid(Command: Word): Boolean;
  2757. var PT : PTabDef;
  2758. PI : PTabItem;
  2759. OK : boolean;
  2760. begin
  2761. OK:=true;
  2762. PT:=TabDefs;
  2763. while (PT<>nil) and (OK=true) do
  2764. begin
  2765. PI:=PT^.Items;
  2766. while (PI<>nil) and (OK=true) do
  2767. begin
  2768. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  2769. PI:=PI^.Next;
  2770. end;
  2771. PT:=PT^.Next;
  2772. end;
  2773. Valid:=OK;
  2774. end;
  2775. procedure TTab.SetState(AState: Word; Enable: Boolean);
  2776. begin
  2777. inherited SetState(AState,Enable);
  2778. if (AState and sfFocused)<>0 then DrawView;
  2779. end;
  2780. destructor TTab.Done;
  2781. var P,X: PTabDef;
  2782. procedure DeleteViews(P: PView); {$ifndef FPC}far;{$endif}
  2783. begin
  2784. if P<>nil then Delete(P);
  2785. end;
  2786. begin
  2787. ForEach(@DeleteViews);
  2788. inherited Done;
  2789. P:=TabDefs;
  2790. while P<>nil do
  2791. begin
  2792. X:=P^.Next;
  2793. DisposeTabDef(P);
  2794. P:=X;
  2795. end;
  2796. end;
  2797. constructor TScreenView.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
  2798. AScreen: PScreen);
  2799. begin
  2800. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  2801. Screen:=AScreen;
  2802. if Screen=nil then
  2803. Fail;
  2804. SetState(sfCursorVis,true);
  2805. Update;
  2806. end;
  2807. procedure TScreenView.Update;
  2808. begin
  2809. SetLimit(UserScreen^.GetWidth,UserScreen^.GetHeight);
  2810. DrawView;
  2811. end;
  2812. procedure TScreenView.HandleEvent(var Event: TEvent);
  2813. begin
  2814. case Event.What of
  2815. evBroadcast :
  2816. case Event.Command of
  2817. cmUpdate : Update;
  2818. end;
  2819. end;
  2820. inherited HandleEvent(Event);
  2821. end;
  2822. procedure TScreenView.Draw;
  2823. var B: TDrawBuffer;
  2824. X,Y: integer;
  2825. Text,Attr: string;
  2826. P: TPoint;
  2827. begin
  2828. Screen^.GetCursorPos(P);
  2829. for Y:=Delta.Y to Delta.Y+Size.Y-1 do
  2830. begin
  2831. if Y<Screen^.GetHeight then
  2832. Screen^.GetLine(Y,Text,Attr)
  2833. else
  2834. begin Text:=''; Attr:=''; end;
  2835. Text:=copy(Text,Delta.X+1,255); Attr:=copy(Attr,Delta.X+1,255);
  2836. MoveChar(B,' ',0,Size.X);
  2837. for X:=1 to length(Text) do
  2838. MoveChar(B[X-1],Text[X],ord(Attr[X]),1);
  2839. WriteLine(0,Y-Delta.Y,Size.X,1,B);
  2840. end;
  2841. SetCursor(P.X-Delta.X,P.Y-Delta.Y);
  2842. end;
  2843. constructor TScreenWindow.Init(AScreen: PScreen; ANumber: integer);
  2844. var R: TRect;
  2845. VSB,HSB: PScrollBar;
  2846. begin
  2847. Desktop^.GetExtent(R);
  2848. inherited Init(R, 'User screen', ANumber);
  2849. Options:=Options or ofTileAble;
  2850. GetExtent(R); R.Grow(-1,-1); R.Move(1,0); R.A.X:=R.B.X-1;
  2851. New(VSB, Init(R)); VSB^.Options:=VSB^.Options or ofPostProcess;
  2852. VSB^.GrowMode:=gfGrowLoX+gfGrowHiX+gfGrowHiY; Insert(VSB);
  2853. GetExtent(R); R.Grow(-1,-1); R.Move(0,1); R.A.Y:=R.B.Y-1;
  2854. New(HSB, Init(R)); HSB^.Options:=HSB^.Options or ofPostProcess;
  2855. HSB^.GrowMode:=gfGrowLoY+gfGrowHiX+gfGrowHiY; Insert(HSB);
  2856. GetExtent(R); R.Grow(-1,-1);
  2857. New(ScreenView, Init(R, HSB, VSB, AScreen));
  2858. ScreenView^.GrowMode:=gfGrowHiX+gfGrowHiY;
  2859. Insert(ScreenView);
  2860. UserScreenWindow:=@Self;
  2861. end;
  2862. destructor TScreenWindow.Done;
  2863. begin
  2864. inherited Done;
  2865. UserScreenWindow:=nil;
  2866. end;
  2867. const InTranslate : boolean = false;
  2868. procedure TranslateMouseClick(View: PView; var Event: TEvent);
  2869. procedure TranslateAction(Action: integer);
  2870. var E: TEvent;
  2871. begin
  2872. if Action<>acNone then
  2873. begin
  2874. E:=Event;
  2875. E.What:=evMouseDown; E.Buttons:=mbLeftButton;
  2876. View^.HandleEvent(E);
  2877. Event.What:=evCommand;
  2878. Event.Command:=ActionCommands[Action];
  2879. end;
  2880. end;
  2881. begin
  2882. if InTranslate then Exit;
  2883. InTranslate:=true;
  2884. case Event.What of
  2885. evMouseDown :
  2886. if (GetShiftState and kbAlt)<>0 then
  2887. TranslateAction(AltMouseAction) else
  2888. if (GetShiftState and kbCtrl)<>0 then
  2889. TranslateAction(CtrlMouseAction);
  2890. end;
  2891. InTranslate:=false;
  2892. end;
  2893. function GetNextEditorBounds(var Bounds: TRect): boolean;
  2894. var P: PView;
  2895. begin
  2896. P:=Desktop^.First;
  2897. while P<>nil do
  2898. begin
  2899. if P^.HelpCtx=hcSourceWindow then Break;
  2900. P:=P^.NextView;
  2901. end;
  2902. if P=nil then Desktop^.GetExtent(Bounds) else
  2903. begin
  2904. P^.GetBounds(Bounds);
  2905. Inc(Bounds.A.X); Inc(Bounds.A.Y);
  2906. end;
  2907. GetNextEditorBounds:=P<>nil;
  2908. end;
  2909. function OpenEditorWindow(Bounds: PRect; FileName: string; CurX,CurY: integer): PSourceWindow;
  2910. var R: TRect;
  2911. W: PSourceWindow;
  2912. begin
  2913. if Assigned(Bounds) then R.Copy(Bounds^) else
  2914. GetNextEditorBounds(R);
  2915. PushStatus('Opening source file... ('+SmartPath(FileName)+')');
  2916. New(W, Init(R, FileName));
  2917. if W<>nil then
  2918. begin
  2919. if (CurX<>0) or (CurY<>0) then
  2920. with W^.Editor^ do
  2921. begin
  2922. SetCurPtr(CurX,CurY);
  2923. TrackCursor(true);
  2924. end;
  2925. W^.HelpCtx:=hcSourceWindow;
  2926. Desktop^.Insert(W);
  2927. If assigned(BreakpointCollection) then
  2928. BreakPointCollection^.ShowBreakpoints(W);
  2929. Message(Application,evBroadcast,cmUpdate,nil);
  2930. end;
  2931. PopStatus;
  2932. OpenEditorWindow:=W;
  2933. end;
  2934. function TryToOpenFile(Bounds: PRect; FileName: string; CurX,CurY: integer): PSourceWindow;
  2935. var D : DirStr;
  2936. N : NameStr;
  2937. E : ExtStr;
  2938. DrStr : String;
  2939. function CheckDir(NewDir: DirStr; NewName: NameStr; NewExt: ExtStr): boolean;
  2940. var OK: boolean;
  2941. begin
  2942. NewDir:=CompleteDir(NewDir);
  2943. OK:=ExistsFile(NewDir+NewName+NewExt);
  2944. if OK then begin D:=NewDir; N:=NewName; E:=NewExt; end;
  2945. CheckDir:=OK;
  2946. end;
  2947. function CheckExt(NewExt: ExtStr): boolean;
  2948. var OK: boolean;
  2949. begin
  2950. OK:=false;
  2951. if D<>'' then OK:=CheckDir(D,N,NewExt) else
  2952. if CheckDir('.'+DirSep,N,NewExt) then OK:=true;
  2953. CheckExt:=OK;
  2954. end;
  2955. function TryToOpen(const DD : dirstr): PSourceWindow;
  2956. var Found: boolean;
  2957. W : PSourceWindow;
  2958. begin
  2959. D:=CompleteDir(DD);
  2960. Found:=true;
  2961. if E<>'' then Found:=CheckExt(E) else
  2962. if CheckExt('.pp') then Found:=true else
  2963. if CheckExt('.pas') then Found:=true else
  2964. if CheckExt('.inc')=false then
  2965. Found:=false;
  2966. if Found=false then W:=nil else
  2967. begin
  2968. FileName:=FExpand(D+N+E);
  2969. W:=OpenEditorWindow(Bounds,FileName,CurX,CurY);
  2970. end;
  2971. TryToOpen:=W;
  2972. end;
  2973. function SearchOnDesktop: PSourceWindow;
  2974. var W: PWindow;
  2975. I: integer;
  2976. Found: boolean;
  2977. SName : string;
  2978. begin
  2979. for I:=1 to 100 do
  2980. begin
  2981. W:=SearchWindowWithNo(I);
  2982. if (W<>nil) and (W^.HelpCtx=hcSourceWindow) then
  2983. begin
  2984. if (D='') then
  2985. SName:=NameAndExtOf(PSourceWindow(W)^.Editor^.FileName)
  2986. else
  2987. SName:=PSourceWindow(W)^.Editor^.FileName;
  2988. SName:=UpcaseStr(SName);
  2989. if E<>'' then
  2990. begin
  2991. if D<>'' then
  2992. Found:=SName=UpcaseStr(D+N+E)
  2993. else
  2994. Found:=SName=UpcaseStr(N+E);
  2995. end
  2996. else
  2997. begin
  2998. Found:=SName=UpcaseStr(N+'.pp');
  2999. if Found=false then
  3000. Found:=SName=UpcaseStr(N+'.pas');
  3001. end;
  3002. if Found then Break;
  3003. end;
  3004. end;
  3005. if Found=false then W:=nil;
  3006. SearchOnDesktop:=PSourceWindow(W);
  3007. end;
  3008. var W: PSourceWindow;
  3009. begin
  3010. FSplit(FileName,D,N,E);
  3011. W:=SearchOnDesktop;
  3012. if W<>nil then
  3013. begin
  3014. NewEditorOpened:=false;
  3015. if assigned(Bounds) then
  3016. W^.ChangeBounds(Bounds^);
  3017. W^.Editor^.SetCurPtr(CurX,CurY);
  3018. end
  3019. else
  3020. begin
  3021. DrStr:=GetSourceDirectories;
  3022. While pos(';',DrStr)>0 do
  3023. Begin
  3024. W:=TryToOpen(Copy(DrStr,1,pos(';',DrStr)-1));
  3025. if assigned(W) then
  3026. break;
  3027. DrStr:=Copy(DrStr,pos(';',DrStr)+1,255);
  3028. End;
  3029. if not assigned(W) then
  3030. W:=TryToOpen(DrStr);
  3031. NewEditorOpened:=W<>nil;
  3032. if assigned(W) then
  3033. W^.Editor^.SetCurPtr(CurX,CurY);
  3034. end;
  3035. TryToOpenFile:=W;
  3036. end;
  3037. END.
  3038. {
  3039. $Log$
  3040. Revision 1.19 1999-02-22 11:51:39 peter
  3041. * browser updates from gabor
  3042. Revision 1.18 1999/02/22 11:29:38 pierre
  3043. + added col info in MessageItem
  3044. + grep uses HighLightExts and should work for linux
  3045. Revision 1.17 1999/02/22 02:15:22 peter
  3046. + default extension for save in the editor
  3047. + Separate Text to Find for the grep dialog
  3048. * fixed redir crash with tp7
  3049. Revision 1.16 1999/02/19 18:43:49 peter
  3050. + open dialog supports mask list
  3051. Revision 1.15 1999/02/17 15:04:02 pierre
  3052. + file(line) added in TProgramInfo message list
  3053. Revision 1.14 1999/02/16 12:45:18 pierre
  3054. * GDBWindow size and grow corrected
  3055. Revision 1.13 1999/02/15 09:36:06 pierre
  3056. * // comment ends at end of line !
  3057. GDB window changed !
  3058. now all is in a normal text editor, but pressing
  3059. Enter key will send part of line before cursor to GDB !
  3060. Revision 1.12 1999/02/11 19:07:25 pierre
  3061. * GDBWindow redesigned :
  3062. normal editor apart from
  3063. that any kbEnter will send the line (for begin to cursor)
  3064. to GDB command !
  3065. GDBWindow opened in Debugger Menu
  3066. still buggy :
  3067. -echo should not be present if at end of text
  3068. -GDBWindow becomes First after each step (I don't know why !)
  3069. Revision 1.11 1999/02/11 13:08:39 pierre
  3070. + TGDBWindow : direct gdb input/output
  3071. Revision 1.10 1999/02/10 09:42:52 pierre
  3072. + DoneReservedWords to avoid memory leaks
  3073. * TMessageItem Module field was not disposed
  3074. Revision 1.9 1999/02/05 12:12:02 pierre
  3075. + SourceDir that stores directories for sources that the
  3076. compiler should not know about
  3077. Automatically asked for addition when a new file that
  3078. needed filedialog to be found is in an unknown directory
  3079. Stored and retrieved from INIFile
  3080. + Breakpoints conditions added to INIFile
  3081. * Breakpoints insterted and removed at debin and end of debug session
  3082. Revision 1.8 1999/02/04 17:45:23 pierre
  3083. + BrowserAtCursor started
  3084. * bug in TryToOpenFile removed
  3085. Revision 1.7 1999/02/04 13:32:11 pierre
  3086. * Several things added (I cannot commit them independently !)
  3087. + added TBreakpoint and TBreakpointCollection
  3088. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  3089. + Breakpoint list in INIFile
  3090. * Select items now also depend of SwitchMode
  3091. * Reading of option '-g' was not possible !
  3092. + added search for -Fu args pathes in TryToOpen
  3093. + added code for automatic opening of FileDialog
  3094. if source not found
  3095. Revision 1.6 1999/01/21 11:54:27 peter
  3096. + tools menu
  3097. + speedsearch in symbolbrowser
  3098. * working run command
  3099. Revision 1.5 1999/01/14 21:42:25 peter
  3100. * source tracking from Gabor
  3101. Revision 1.4 1999/01/12 14:29:42 peter
  3102. + Implemented still missing 'switch' entries in Options menu
  3103. + Pressing Ctrl-B sets ASCII mode in editor, after which keypresses (even
  3104. ones with ASCII < 32 ; entered with Alt+<###>) are interpreted always as
  3105. ASCII chars and inserted directly in the text.
  3106. + Added symbol browser
  3107. * splitted fp.pas to fpide.pas
  3108. Revision 1.3 1999/01/04 11:49:53 peter
  3109. * 'Use tab characters' now works correctly
  3110. + Syntax highlight now acts on File|Save As...
  3111. + Added a new class to syntax highlight: 'hex numbers'.
  3112. * There was something very wrong with the palette managment. Now fixed.
  3113. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  3114. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  3115. process revised
  3116. Revision 1.2 1998/12/28 15:47:54 peter
  3117. + Added user screen support, display & window
  3118. + Implemented Editor,Mouse Options dialog
  3119. + Added location of .INI and .CFG file
  3120. + Option (INI) file managment implemented (see bottom of Options Menu)
  3121. + Switches updated
  3122. + Run program
  3123. Revision 1.4 1998/12/22 10:39:53 peter
  3124. + options are now written/read
  3125. + find and replace routines
  3126. }