fpdesk.pas 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Desktop loading/saving routines
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit FPDesk;
  12. {$H-}
  13. interface
  14. const
  15. MinDesktopVersion = $000A;
  16. DesktopVersion = $000A; { <- if you change any Load&Store methods,
  17. default object properties (Options,State)
  18. then you should also change this }
  19. ResDesktopFlags = 'FLAGS';
  20. ResVideo = 'VIDEOMODE';
  21. ResHistory = 'HISTORY';
  22. ResClipboard = 'CLIPBOARD';
  23. ResWatches = 'WATCHES';
  24. ResBreakpoints = 'BREAKPOINTS';
  25. ResDesktop = 'DESKTOP';
  26. ResSymbols = 'SYMBOLS';
  27. ResCodeComplete = 'CODECOMPLETE';
  28. ResCodeTemplates = 'CODETEMPLATES';
  29. ResLastDirectory = 'LASTDIRECTORY';
  30. ResKeys = 'KEYS';
  31. procedure InitDesktopFile;
  32. function LoadDesktop: boolean;
  33. function SaveDesktop: boolean;
  34. procedure DoneDesktopFile;
  35. function WriteSymbolsFile(const filename : string): boolean;
  36. function ReadSymbolsFile(const filename : string): boolean;
  37. implementation
  38. uses Dos,
  39. Objects,Drivers,
  40. Video,
  41. Views,App,HistList,BrowCol,
  42. WUtils,WResourc,WViews,WEditor,
  43. fpdebug, wcedit,
  44. {$ifdef Unix}
  45. FPKeys,
  46. {$endif Unix}
  47. FPConst,FPVars,FPTools,FPUtils,FPViews,FPHelp,
  48. FPCompil,FPCodCmp,FPCodTmp;
  49. type
  50. TWindowInfo =
  51. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  52. packed
  53. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  54. record
  55. HelpCtx : word;
  56. Bounds : TRect;
  57. Visible : boolean;
  58. WinNb : byte;
  59. ExtraDataSize : word;
  60. TitleLen : word;
  61. Title : packed record end;
  62. end;
  63. {$ifdef useresstrings}
  64. resourcestring
  65. {$else}
  66. const
  67. {$endif}
  68. { Desktop file messages }
  69. msg_readingdesktopfile = 'Reading desktop file...';
  70. msg_writingdesktopfile = 'Writing desktop file...';
  71. msg_readingdesktopcontents = 'Reading desktop contents...';
  72. msg_storingdesktopcontents = 'Storing desktop contents...';
  73. msg_readinghistory = 'Reading history...';
  74. msg_storinghistory = 'Storing history...';
  75. msg_readingwatches = 'Reading watches...';
  76. msg_storingwatches = 'Storing watches...';
  77. msg_readingbreakpoints = 'Reading breakpoints...';
  78. msg_storingbreakpoints = 'Storing breakpoints...';
  79. msg_readingcodecompletewordlist = 'Reading CodeComplete wordlist...';
  80. msg_storingcodecompletewordlist = 'Writing CodeComplete wordlist...';
  81. msg_readingcodetemplates = 'Reading CodeTemplates...';
  82. msg_storingcodetemplates = 'Writing CodeTemplates...';
  83. msg_readingreturntolastdir = 'Reading Last directory to return...';
  84. msg_storingreturntolastdir = 'Writing Last directory to return...';
  85. msg_readingsymbolinformation = 'Reading symbol information...';
  86. msg_storingsymbolinformation = 'Storing symbol information...';
  87. msg_failedtoreplacedesktopfile = 'Failed to replace desktop file.';
  88. msg_errorloadinghistory = 'Error loading history';
  89. msg_errorstoringhistory = 'Error storing history';
  90. msg_errorloadingkeys = 'Error loading custom keys';
  91. msg_errorstoringkeys = 'Error storing custom keys';
  92. msg_errorloadingwatches = 'Error loading watches';
  93. msg_errorstoringwatches = 'Error storing watches';
  94. msg_errorloadingbreakpoints = 'Error loading breakpoints';
  95. msg_errorstoringbreakpoints = 'Error storing breakpoints';
  96. msg_errorloadingdesktop = 'Error loading desktop';
  97. msg_errorstoringdesktop = 'Error storing desktop';
  98. msg_errorreadingflags = 'Error loading flags';
  99. msg_errorwritingflags = 'Error writing flags';
  100. msg_errorreadingvideomode = 'Error reading video mode';
  101. msg_errorstoringvideomode = 'Error storing video mode';
  102. msg_errorloadingcodetemplates = 'Error loading CodeTemplates';
  103. msg_errorstoringcodetemplates = 'Error writing CodeTemplates';
  104. msg_errorloadingreturntolastdir = 'Error loading Last directory to return';
  105. msg_errorstoringreturntolastdir = 'Error writing Last directory to return';
  106. msg_errorloadingsymbolinformation = 'Error loading symbol information';
  107. msg_errorstoringsymbolinformation = 'Error storing symbol information';
  108. msg_errorloadingcodecompletewordlist = 'Error loading CodeComplete wordlist';
  109. msg_errorstoringcodecompletewordlist = 'Error writing CodeComplete wordlist';
  110. msg_invaliddesktopversionlayoutlost = 'Invalid desktop version. Desktop layout lost.';
  111. msg_saveansifile = 'Save previous screen as Ansi File';
  112. msg_click_upper_left = 'Click to select upper left corner; Escape to cancel; Enter to select (0,0)';
  113. msg_click_lower_right = 'Click to select lower right corner; Escape to cancel; Enter to select (maxX,maxY)';
  114. msg_cantopenfile = 'Can''t open %s';
  115. msg_cantcreatefile = 'Can''t create %s';
  116. msg_cantfindfile = 'Can''t find %s';
  117. msg_errorreadingfile = 'Error reading file %s';
  118. msg_loadingfile = 'Loading %s';
  119. msg_storingfile = 'Storing %s';
  120. msg_closingfile = 'Closing %s';
  121. msg_openingsourcefile = 'Opening source file... (%s)';
  122. msg_readingfileineditor = 'Reading %s into editor...';
  123. procedure InitDesktopFile;
  124. begin
  125. if DesktopLocation=dlCurrentDir then
  126. DesktopPath:=FExpand(DesktopFileName)
  127. else
  128. DesktopPath:=FExpand(DirOf(IniFilePath)+DesktopFileName);
  129. end;
  130. procedure DoneDesktopFile;
  131. begin
  132. end;
  133. function ReadHistory(F: PResourceFile): boolean;
  134. var S: PMemoryStream;
  135. OK: boolean;
  136. begin
  137. PushStatus(msg_readinghistory);
  138. New(S, Init(32*1024,4096));
  139. OK:=F^.ReadResourceEntryToStream(resHistory,langDefault,S^);
  140. S^.Seek(0);
  141. if OK then
  142. LoadHistory(S^);
  143. Dispose(S, Done);
  144. if OK=false then
  145. ErrorBox(msg_errorloadinghistory,nil);
  146. PopStatus;
  147. ReadHistory:=OK;
  148. end;
  149. function WriteHistory(F: PResourceFile): boolean;
  150. var S: PMemoryStream;
  151. OK: boolean;
  152. begin
  153. PushStatus(msg_storinghistory);
  154. New(S, Init(10*1024,4096));
  155. StoreHistory(S^);
  156. S^.Seek(0);
  157. F^.CreateResource(resHistory,rcBinary,0);
  158. OK:=F^.AddResourceEntryFromStream(resHistory,langDefault,0,S^,S^.GetSize);
  159. Dispose(S, Done);
  160. if OK=false then
  161. ErrorBox(msg_errorstoringhistory,nil);
  162. PopStatus;
  163. WriteHistory:=OK;
  164. end;
  165. {$ifdef Unix}
  166. function ReadKeys(F: PResourceFile): boolean;
  167. var S: PMemoryStream;
  168. OK: boolean;
  169. begin
  170. New(S, Init(32*1024,4096));
  171. OK:=F^.ReadResourceEntryToStream(resKeys,langDefault,S^);
  172. S^.Seek(0);
  173. if OK then
  174. LoadKeys(S^);
  175. Dispose(S, Done);
  176. if OK=false then
  177. ErrorBox(msg_errorloadingkeys,nil);
  178. ReadKeys:=OK;
  179. end;
  180. function WriteKeys(F: PResourceFile): boolean;
  181. var S: PMemoryStream;
  182. OK: boolean;
  183. begin
  184. New(S, Init(10*1024,4096));
  185. StoreKeys(S^);
  186. S^.Seek(0);
  187. F^.CreateResource(resKeys,rcBinary,0);
  188. OK:=F^.AddResourceEntryFromStream(resKeys,langDefault,0,S^,S^.GetSize);
  189. Dispose(S, Done);
  190. if OK=false then
  191. ErrorBox(msg_errorstoringkeys,nil);
  192. WriteKeys:=OK;
  193. end;
  194. {$endif Unix}
  195. (*function ReadClipboard(F: PResourceFile): boolean;
  196. begin
  197. ReadClipboard:=true;
  198. end;
  199. function WriteClipboard(F: PResourceFile): boolean;
  200. var S: PMemoryStream;
  201. begin
  202. if Assigned(Clipboard) then
  203. begin
  204. PushStatus('Storing clipboard content...');
  205. New(S, Init(10*1024,4096));
  206. Clipboard^.SaveToStream(S^);
  207. S^.Seek(0);
  208. F^.CreateResource(resClipboard,rcBinary,0);
  209. F^.AddResourceEntryFromStream(resClipboard,langDefault,0,S^,S^.GetSize);
  210. Dispose(S, Done);
  211. PopStatus;
  212. end;
  213. WriteClipboard:=true;
  214. end;*)
  215. function ReadWatches(F: PResourceFile): boolean;
  216. {$ifndef NODEBUG}
  217. var S: PMemoryStream;
  218. OK: boolean;
  219. OWC : PWatchesCollection;
  220. {$endif}
  221. begin
  222. {$ifndef NODEBUG}
  223. PushStatus(msg_readingwatches);
  224. New(S, Init(32*1024,4096));
  225. OK:=F^.ReadResourceEntryToStream(resWatches,langDefault,S^);
  226. S^.Seek(0);
  227. if OK then
  228. begin
  229. OWC:=WatchesCollection;
  230. WatchesCollection:=PWatchesCollection(S^.Get);
  231. OK:=(S^.Status=stOK);
  232. if OK and assigned(OWC) and assigned(WatchesCollection) then
  233. Dispose(OWC,Done)
  234. else if assigned(OWC) then
  235. WatchesCollection:=OWC;
  236. end;
  237. if OK=false then
  238. ErrorBox(msg_errorloadingwatches,nil);
  239. ReadWatches:=OK;
  240. Dispose(S, Done);
  241. PopStatus;
  242. {$else NODEBUG}
  243. ReadWatches:=true;
  244. {$endif NODEBUG}
  245. end;
  246. function WriteWatches(F: PResourceFile): boolean;
  247. var
  248. S : PMemoryStream;
  249. OK : boolean;
  250. begin
  251. {$ifndef NODEBUG}
  252. if not assigned(WatchesCollection) then
  253. {$endif NODEBUG}
  254. WriteWatches:=true
  255. {$ifndef NODEBUG}
  256. else
  257. begin
  258. PushStatus(msg_storingwatches);
  259. New(S, Init(30*1024,4096));
  260. S^.Put(WatchesCollection);
  261. S^.Seek(0);
  262. F^.CreateResource(resWatches,rcBinary,0);
  263. OK:=F^.AddResourceEntryFromStream(resWatches,langDefault,0,S^,S^.GetSize);
  264. Dispose(S, Done);
  265. if OK=false then
  266. ErrorBox(msg_errorstoringwatches,nil);
  267. PopStatus;
  268. WriteWatches:=OK;
  269. end;
  270. {$endif NODEBUG}
  271. end;
  272. function ReadBreakpoints(F: PResourceFile): boolean;
  273. {$ifndef NODEBUG}
  274. var S: PMemoryStream;
  275. OK: boolean;
  276. OBC : PBreakpointCollection;
  277. {$endif}
  278. begin
  279. {$ifndef NODEBUG}
  280. PushStatus(msg_readingbreakpoints);
  281. New(S, Init(32*1024,4096));
  282. OK:=F^.ReadResourceEntryToStream(resBreakpoints,langDefault,S^);
  283. S^.Seek(0);
  284. if OK then
  285. begin
  286. OBC:=BreakpointsCollection;
  287. BreakpointsCollection:=PBreakpointCollection(S^.get);
  288. OK:=(S^.Status=stOK);
  289. If OK and assigned(OBC) and assigned(BreakpointsCollection) then
  290. Begin
  291. Dispose(OBC,Done);
  292. BreakpointsCollection^.ShowAllBreakpoints;
  293. end
  294. else if assigned(OBC) then
  295. BreakpointsCollection:=OBC;
  296. end;
  297. if OK=false then
  298. ErrorBox(msg_errorloadingbreakpoints,nil);
  299. ReadBreakpoints:=OK;
  300. Dispose(S, Done);
  301. PopStatus;
  302. {$else NODEBUG}
  303. ReadBreakpoints:=true;
  304. {$endif NODEBUG}
  305. end;
  306. function WriteBreakpoints(F: PResourceFile): boolean;
  307. var
  308. S : PMemoryStream;
  309. OK : boolean;
  310. begin
  311. {$ifndef NODEBUG}
  312. if not assigned(BreakpointsCollection) then
  313. {$endif NODEBUG}
  314. WriteBreakPoints:=true
  315. {$ifndef NODEBUG}
  316. else
  317. begin
  318. PushStatus(msg_storingbreakpoints);
  319. New(S, Init(30*1024,4096));
  320. S^.Put(BreakpointsCollection);
  321. S^.Seek(0);
  322. F^.CreateResource(resBreakpoints,rcBinary,0);
  323. OK:=F^.AddResourceEntryFromStream(resBreakpoints,langDefault,0,S^,S^.GetSize);
  324. Dispose(S, Done);
  325. if OK=false then
  326. ErrorBox(msg_errorstoringbreakpoints,nil);
  327. WriteBreakPoints:=OK;
  328. PopStatus;
  329. end;
  330. {$endif NODEBUG}
  331. end;
  332. function DeskUseSyntaxHighlight(Editor: PFileEditor): boolean;
  333. var b : boolean;
  334. begin
  335. b:= (*(Editor^.IsFlagSet(efSyntaxHighlight)) and *) ((Editor^.FileName='') or
  336. MatchesMaskList(NameAndExtOf(Editor^.FileName),HighlightExts));
  337. DeskUseSyntaxHighlight:=b;
  338. end;
  339. function ReadOpenWindows(F: PResourceFile): boolean;
  340. var S: PMemoryStream;
  341. OK: boolean;
  342. DV: word;
  343. WI: TWindowInfo;
  344. Title: string;
  345. XDataOfs: word;
  346. XData: array[0..1024] of byte;
  347. procedure GetData(var B; Size: word);
  348. begin
  349. if Size>0 Then
  350. Begin
  351. Move(XData[XDataOfs],B,Size);
  352. Inc(XDataOfs,Size);
  353. End;
  354. end;
  355. procedure ProcessWindowInfo;
  356. var W: PWindow;
  357. SW: PSourceWindow absolute W;
  358. St: string;
  359. Ch: AnsiChar;
  360. TP,TP2: TPoint;
  361. L: longint;
  362. R: TRect;
  363. ZZ: byte;
  364. Z: TRect;
  365. Len : Byte;
  366. BM: TEditorBookMark;
  367. begin
  368. XDataOfs:=0;
  369. Desktop^.Lock;
  370. W:=SearchWindow(Title);
  371. case WI.HelpCtx of
  372. hcSourceWindow :
  373. begin
  374. GetData(len,1);
  375. SetLength(St,Len);
  376. GetData(St[1],Len);
  377. W:=ITryToOpenFile(@WI.Bounds,St,0,0,false,false,true);
  378. if Assigned(W)=false then
  379. begin
  380. ClearFormatParams;
  381. AddFormatParamStr(St);
  382. Desktop^.Unlock;
  383. ErrorBox(msg_cantopenfile,@FormatParams);
  384. Desktop^.Lock;
  385. end
  386. else
  387. begin
  388. GetData(L,sizeof(L));
  389. If DeskUseSyntaxHighlight(SW^.Editor) Then
  390. L:=L or efSyntaxHighlight
  391. else
  392. L:=L and not efSyntaxHighlight;
  393. SW^.Editor^.SetFlags(L);
  394. GetData(TP,sizeof(TP)); GetData(TP2,sizeof(TP2));
  395. SW^.Editor^.SetSelection(TP,TP2);
  396. GetData(TP,sizeof(TP)); SW^.Editor^.SetCurPtr(TP.X,TP.Y);
  397. GetData(TP,sizeof(TP)); SW^.Editor^.ScrollTo(TP.X,TP.Y);
  398. for L:=0 to 9 do begin
  399. GetData(BM,Sizeof(BM));
  400. SW^.Editor^.SetBookmark(L,BM); {restore bookmarks}
  401. end;
  402. end;
  403. end;
  404. hcClipboardWindow:
  405. W:=ClipboardWindow;
  406. hcCalcWindow:
  407. W:=CalcWindow;
  408. hcMessagesWindow:
  409. begin
  410. if MessagesWindow=nil then
  411. Desktop^.Insert(New(PMessagesWindow, Init));
  412. W:=MessagesWindow;
  413. end;
  414. hcCompilerMessagesWindow:
  415. W:=CompilerMessageWindow;
  416. {$ifndef NODEBUG}
  417. hcGDBWindow:
  418. begin
  419. InitGDBWindow;
  420. W:=GDBWindow;
  421. end;
  422. hcDisassemblyWindow:
  423. begin
  424. InitDisassemblyWindow;
  425. W:=DisassemblyWindow;
  426. end;
  427. hcWatchesWindow:
  428. begin
  429. if WatchesWindow=nil then
  430. begin
  431. New(WatchesWindow,Init);
  432. Desktop^.Insert(WatchesWindow);
  433. end;
  434. W:=WatchesWindow;
  435. end;
  436. hcStackWindow:
  437. begin
  438. if StackWindow=nil then
  439. begin
  440. New(StackWindow,Init);
  441. Desktop^.Insert(StackWindow);
  442. end;
  443. W:=StackWindow;
  444. end;
  445. hcFPURegisters:
  446. begin
  447. if FPUWindow=nil then
  448. begin
  449. New(FPUWindow,Init);
  450. Desktop^.Insert(FPUWindow);
  451. end;
  452. W:=FPUWindow;
  453. end;
  454. hcVectorRegisters:
  455. begin
  456. if VectorWindow=nil then
  457. begin
  458. New(VectorWindow,Init);
  459. Desktop^.Insert(VectorWindow);
  460. end;
  461. W:=VectorWindow;
  462. end;
  463. hcRegistersWindow:
  464. begin
  465. if RegistersWindow=nil then
  466. begin
  467. New(RegistersWindow,Init);
  468. Desktop^.Insert(RegistersWindow);
  469. end;
  470. W:=RegistersWindow;
  471. end;
  472. hcBreakpointListWindow:
  473. begin
  474. if BreakpointsWindow=nil then
  475. begin
  476. New(BreakpointsWindow,Init);
  477. Desktop^.Insert(BreakpointsWindow);
  478. end;
  479. W:=BreakpointsWindow;
  480. end;
  481. {$endif NODEBUG}
  482. hcASCIITableWindow:
  483. begin
  484. if ASCIIChart=nil then
  485. begin
  486. New(ASCIIChart, Init);
  487. Desktop^.Insert(ASCIIChart);
  488. end;
  489. W:=ASCIIChart;
  490. if DV>=$A then
  491. begin
  492. GetData(ch,sizeof(AnsiChar));
  493. AsciiChart^.Report^.AsciiChar:=ord(ch);
  494. AsciiChart^.Table^.SetCursor(
  495. ord(ch) mod AsciiChart^.Table^.Size.X,
  496. ord(ch) div AsciiChart^.Table^.Size.X);
  497. end;
  498. end;
  499. end;
  500. if W=nil then
  501. begin
  502. Desktop^.Unlock;
  503. Exit;
  504. end;
  505. W^.GetBounds(R);
  506. if (R.A.X<>WI.Bounds.A.X) or (R.A.Y<>WI.Bounds.A.Y) then
  507. R.Move(WI.Bounds.A.X-R.A.X,WI.Bounds.A.Y-R.A.Y);
  508. if (W^.Flags and wfGrow)<>0 then
  509. begin
  510. R.B.X:=R.A.X+(WI.Bounds.B.X-WI.Bounds.A.X);
  511. R.B.Y:=R.A.Y+(WI.Bounds.B.Y-WI.Bounds.A.Y);
  512. end;
  513. W^.Locate(R);
  514. if W^.GetState(sfVisible)<>WI.Visible then
  515. if WI.Visible then
  516. begin
  517. W^.Show;
  518. W^.MakeFirst;
  519. end
  520. else
  521. W^.Hide;
  522. ZZ:=0;
  523. Desktop^.GetExtent(Z);
  524. if R.A.Y>Z.B.Y-7 then
  525. begin
  526. R.A.Y:=Z.B.Y-7;
  527. ZZ:=1;
  528. end;
  529. if R.A.X>Z.B.X-4 then
  530. begin
  531. R.A.X:=Z.B.X-4;
  532. ZZ:=1;
  533. end;
  534. if R.A.Y<0 then
  535. begin
  536. R.A.Y:=0;
  537. ZZ:=1;
  538. end;
  539. if R.A.X<0 then
  540. begin
  541. R.A.X:=0;
  542. ZZ:=1;
  543. end;
  544. if ZZ<>0 then W^.MoveTo(R.A.X,R.A.Y);
  545. W^.Number:=WI.WinNb;
  546. Desktop^.Unlock;
  547. end;
  548. begin
  549. PushStatus(msg_readingdesktopcontents);
  550. New(S, Init(32*1024,4096));
  551. OK:=F^.ReadResourceEntryToStream(resDesktop,langDefault,S^);
  552. S^.Seek(0);
  553. if OK then
  554. begin
  555. S^.Read(DV,SizeOf(DV));
  556. OK:=(DV=DesktopVersion) or (DV>=MinDesktopVersion);
  557. if OK=false then
  558. ErrorBox(msg_invaliddesktopversionlayoutlost,nil);
  559. end;
  560. if OK then
  561. begin
  562. XDataOfs:=0;
  563. repeat
  564. S^.Read(WI,sizeof(WI));
  565. if S^.Status=stOK then
  566. begin
  567. SetLength(Title,WI.TitleLen);
  568. S^.Read(Title[1],WI.TitleLen);
  569. FillChar(XData,SizeOf(XData),0);
  570. if WI.ExtraDataSize>0 then
  571. S^.Read(XData,WI.ExtraDataSize);
  572. ProcessWindowInfo;
  573. end;
  574. until (S^.Status<>stOK) or (S^.GetPos=S^.GetSize);
  575. (* TempDesk:=PFPDesktop(S^.Get);
  576. OK:=Assigned(TempDesk);
  577. if OK then
  578. begin
  579. Dispose(Desktop, Done);
  580. Desktop:=TempDesk;
  581. with Desktop^ do
  582. begin
  583. GetSubViewPtr(S^,CompilerMessageWindow);
  584. GetSubViewPtr(S^,CompilerStatusDialog);
  585. GetSubViewPtr(S^,ClipboardWindow);
  586. if Assigned(ClipboardWindow) then Clipboard:=ClipboardWindow^.Editor;
  587. GetSubViewPtr(S^,CalcWindow);
  588. GetSubViewPtr(S^,GDBWindow);
  589. GetSubViewPtr(S^,BreakpointsWindow);
  590. GetSubViewPtr(S^,WatchesWindow);
  591. GetSubViewPtr(S^,UserScreenWindow);
  592. GetSubViewPtr(S^,ASCIIChart);
  593. GetSubViewPtr(S^,MessagesWindow); LastToolMessageFocused:=nil;
  594. end;
  595. Application^.GetExtent(R);
  596. Inc(R.A.Y);Dec(R.B.Y);
  597. DeskTop^.Locate(R);
  598. Application^.Insert(Desktop);
  599. Desktop^.ReDraw;
  600. Message(Application,evBroadcast,cmUpdate,nil);
  601. end;*)
  602. if OK=false then
  603. ErrorBox(msg_errorloadingdesktop,nil);
  604. end;
  605. Dispose(S, Done);
  606. PopStatus;
  607. ReadOpenWindows:=OK;
  608. end;
  609. function WriteOpenWindows(F: PResourceFile): boolean;
  610. var S: PMemoryStream;
  611. procedure CollectInfo(P: PView);
  612. var W: PWindow;
  613. SW: PSourceWindow absolute W;
  614. WI: TWindowInfo;
  615. Title: string;
  616. XDataOfs: word;
  617. XData: array[0..1024] of byte;
  618. St: string;
  619. Ch: AnsiChar;
  620. TP: TPoint;
  621. BM: TEditorBookMark;
  622. L: longint;
  623. procedure AddData(const B; Size: word);
  624. begin
  625. Move(B,XData[XDataOfs],Size);
  626. Inc(XDataOfs,Size);
  627. end;
  628. begin
  629. XDataOfs:=0;
  630. W:=nil;
  631. if (P^.HelpCtx=hcSourceWindow) or
  632. (P^.HelpCtx=hcHelpWindow) or
  633. (P^.HelpCtx=hcClipboardWindow) or
  634. (P^.HelpCtx=hcCalcWindow) or
  635. (P^.HelpCtx=hcInfoWindow) or
  636. (P^.HelpCtx=hcBrowserWindow) or
  637. (P^.HelpCtx=hcMessagesWindow) or
  638. (P^.HelpCtx=hcCompilerMessagesWindow) or
  639. (P^.HelpCtx=hcGDBWindow) or
  640. (P^.HelpCtx=hcDisassemblyWindow) or
  641. (P^.HelpCtx=hcStackWindow) or
  642. (P^.HelpCtx=hcRegistersWindow) or
  643. (P^.HelpCtx=hcFPURegisters) or
  644. (P^.HelpCtx=hcVectorRegisters) or
  645. (P^.HelpCtx=hcWatchesWindow) or
  646. (P^.HelpCtx=hcBreakpointListWindow) or
  647. (P^.HelpCtx=hcASCIITableWindow)
  648. then
  649. W:=PWindow(P);
  650. if Assigned(W) and (P^.HelpCtx=hcSourceWindow) then
  651. if SW^.Editor^.FileName='' then
  652. W:=nil;
  653. if W=nil then Exit;
  654. FillChar(WI,sizeof(WI),0);
  655. Title:=W^.GetTitle(255);
  656. WI.HelpCtx:=W^.HelpCtx;
  657. W^.GetBounds(WI.Bounds);
  658. WI.Visible:=W^.GetState(sfVisible);
  659. WI.WinNb:=W^.Number;
  660. case WI.HelpCtx of
  661. hcSourceWindow :
  662. begin
  663. St:=SW^.Editor^.FileName; AddData(St,length(St)+1);
  664. L:=SW^.Editor^.GetFlags; AddData(L,sizeof(L));
  665. TP:=SW^.Editor^.SelStart; AddData(TP,sizeof(TP));
  666. TP:=SW^.Editor^.SelEnd; AddData(TP,sizeof(TP));
  667. TP:=SW^.Editor^.CurPos; AddData(TP,sizeof(TP));
  668. TP:=SW^.Editor^.Delta; AddData(TP,sizeof(TP));
  669. for L:=0 to 9 do begin
  670. BM:=SW^.Editor^.GetBookmark(L); AddData(BM,Sizeof(BM)); {save bookmarks}
  671. end;
  672. end;
  673. hcAsciiTableWindow :
  674. begin
  675. ch:=chr(PFPAsciiChart(P)^.Report^.AsciiChar);
  676. AddData(ch,sizeof(AnsiChar));
  677. end;
  678. end;
  679. WI.TitleLen:=length(Title);
  680. WI.ExtraDataSize:=XDataOfs;
  681. S^.Write(WI,sizeof(WI));
  682. S^.Write(Title[1],WI.TitleLen);
  683. if WI.ExtraDataSize>0 then
  684. S^.Write(XData,WI.ExtraDataSize);
  685. end;
  686. var W: word;
  687. OK: boolean;
  688. PV: PView;
  689. begin
  690. PushStatus(msg_storingdesktopcontents);
  691. New(S, Init(30*1024,4096));
  692. OK:=Assigned(S);
  693. if OK then
  694. begin
  695. W:=DesktopVersion;
  696. S^.Write(W,SizeOf(W));
  697. { S^.Put(Desktop);
  698. with Desktop^ do
  699. begin
  700. PutSubViewPtr(S^,CompilerMessageWindow);
  701. PutSubViewPtr(S^,CompilerStatusDialog);
  702. PutSubViewPtr(S^,ClipboardWindow);
  703. PutSubViewPtr(S^,CalcWindow);
  704. PutSubViewPtr(S^,GDBWindow);
  705. PutSubViewPtr(S^,BreakpointsWindow);
  706. PutSubViewPtr(S^,WatchesWindow);
  707. PutSubViewPtr(S^,UserScreenWindow);
  708. PutSubViewPtr(S^,ASCIIChart);
  709. PutSubViewPtr(S^,MessagesWindow);
  710. end;}
  711. { PV:=Application^.Last;
  712. while PV<>nil do
  713. begin
  714. CollectInfo(PV);
  715. PV:=PV^.PrevView;
  716. end;}
  717. PV:=Desktop^.Last;
  718. while PV<>nil do
  719. begin
  720. CollectInfo(PV);
  721. PV:=PV^.PrevView;
  722. end;
  723. OK:=(S^.Status=stOK);
  724. if OK then
  725. begin
  726. S^.Seek(0);
  727. OK:=F^.CreateResource(resDesktop,rcBinary,0);
  728. OK:=OK and F^.AddResourceEntryFromStream(resDesktop,langDefault,0,S^,S^.GetSize);
  729. end;
  730. Dispose(S, Done);
  731. end;
  732. if OK=false then
  733. ErrorBox(msg_errorstoringdesktop,nil);
  734. PopStatus;
  735. WriteOpenWindows:=OK;
  736. end;
  737. function WriteFlags(F: PResourceFile): boolean;
  738. var
  739. OK: boolean;
  740. begin
  741. F^.CreateResource(resDesktopFlags,rcBinary,0);
  742. OK:=F^.AddResourceEntry(resDesktopFlags,langDefault,0,DesktopFileFlags,
  743. SizeOf(DesktopFileFlags));
  744. if OK=false then
  745. ErrorBox(msg_errorwritingflags,nil);
  746. WriteFlags:=OK;
  747. end;
  748. function ReadCodeComplete(F: PResourceFile): boolean;
  749. var S: PMemoryStream;
  750. OK: boolean;
  751. begin
  752. PushStatus(msg_readingcodecompletewordlist);
  753. New(S, Init(1024,1024));
  754. OK:=F^.ReadResourceEntryToStream(resCodeComplete,langDefault,S^);
  755. S^.Seek(0);
  756. if OK then
  757. OK:=LoadCodeComplete(S^);
  758. Dispose(S, Done);
  759. if OK=false then
  760. ErrorBox(msg_errorloadingcodecompletewordlist,nil);
  761. PopStatus;
  762. ReadCodeComplete:=OK;
  763. end;
  764. function WriteCodeComplete(F: PResourceFile): boolean;
  765. var OK: boolean;
  766. S: PMemoryStream;
  767. begin
  768. PushStatus(msg_storingcodecompletewordlist);
  769. New(S, Init(1024,1024));
  770. OK:=StoreCodeComplete(S^);
  771. if OK then
  772. begin
  773. S^.Seek(0);
  774. F^.CreateResource(resCodeComplete,rcBinary,0);
  775. OK:=F^.AddResourceEntryFromStream(resCodeComplete,langDefault,0,S^,S^.GetSize);
  776. end;
  777. Dispose(S, Done);
  778. if OK=false then
  779. ErrorBox(msg_errorstoringcodecompletewordlist,nil);
  780. PopStatus;
  781. WriteCodeComplete:=OK;
  782. end;
  783. function ReadCodeTemplates(F: PResourceFile): boolean;
  784. var S: PMemoryStream;
  785. OK: boolean;
  786. begin
  787. PushStatus(msg_readingcodetemplates);
  788. New(S, Init(1024,4096));
  789. OK:=F^.ReadResourceEntryToStream(resCodeTemplates,langDefault,S^);
  790. S^.Seek(0);
  791. if OK then
  792. OK:=LoadCodeTemplates(S^);
  793. Dispose(S, Done);
  794. if OK=false then
  795. ErrorBox(msg_errorloadingcodetemplates,nil);
  796. PopStatus;
  797. ReadCodeTemplates:=OK;
  798. end;
  799. function WriteCodeTemplates(F: PResourceFile): boolean;
  800. var OK: boolean;
  801. S: PMemoryStream;
  802. begin
  803. PushStatus(msg_storingcodetemplates);
  804. New(S, Init(1024,4096));
  805. OK:=StoreCodeTemplates(S^);
  806. if OK then
  807. begin
  808. S^.Seek(0);
  809. F^.CreateResource(resCodeTemplates,rcBinary,0);
  810. OK:=F^.AddResourceEntryFromStream(resCodeTemplates,langDefault,0,S^,S^.GetSize);
  811. end;
  812. Dispose(S, Done);
  813. if OK=false then
  814. ErrorBox(msg_errorstoringcodetemplates,nil);
  815. PopStatus;
  816. WriteCodeTemplates:=OK;
  817. end;
  818. function ReadReturnToLastDir(F: PResourceFile): boolean;
  819. var S: PMemoryStream;
  820. OK: boolean;
  821. Dir:AnsiString;
  822. Size:sw_integer;
  823. begin
  824. PushStatus(msg_readingreturntolastdir);
  825. New(S, Init(1024,4096));
  826. OK:=F^.ReadResourceEntryToStream(ResLastDirectory,langDefault,S^);
  827. S^.Seek(0);
  828. if OK then
  829. begin
  830. S^.Read(Size, sizeof(Size)); { Read directory size }
  831. if Size>0 then
  832. begin
  833. Setlength(Dir,Size);
  834. S^.Read(Dir[1], Size); { Read the directory }
  835. {$i-}ChDir(Dir);{$i+}
  836. IOResult; {eat io result so it does not affect leater operations}
  837. GetDir(0,StartUpDir);
  838. end;
  839. end;
  840. Dispose(S, Done);
  841. if OK=false then
  842. ErrorBox(msg_errorloadingreturntolastdir,nil);
  843. PopStatus;
  844. ReadReturnToLastDir:=OK;
  845. end;
  846. function WriteReturnToLastDir(F: PResourceFile): boolean;
  847. var OK: boolean;
  848. S: PMemoryStream;
  849. Dir:AnsiString;
  850. Size:sw_integer;
  851. begin
  852. PushStatus(msg_storingreturntolastdir);
  853. New(S, Init(1024,4096));
  854. OK:=true;
  855. {$i-}GetDir(0,Dir);{$i+}
  856. if IOResult=0 then
  857. begin
  858. Size:=length(Dir);
  859. S^.Write(Size, sizeof(Size));
  860. if Size>0 then S^.Write(Dir[1],Size);
  861. S^.Seek(0);
  862. F^.CreateResource(ResLastDirectory,rcBinary,0);
  863. OK:=F^.AddResourceEntryFromStream(ResLastDirectory,langDefault,0,S^,S^.GetSize);
  864. end;
  865. Dispose(S, Done);
  866. if OK=false then
  867. ErrorBox(msg_errorstoringreturntolastdir,nil);
  868. PopStatus;
  869. WriteReturnToLastDir:=OK;
  870. end;
  871. function ReadFlags(F: PResourceFile): boolean;
  872. var
  873. OK: boolean;
  874. begin
  875. OK:=F^.ReadResourceEntry(resDesktopFlags,langDefault,DesktopFileFlags,
  876. sizeof(DesktopFileFlags));
  877. if OK=false then
  878. ErrorBox(msg_errorreadingflags,nil);
  879. ReadFlags:=OK;
  880. end;
  881. function WriteVideoMode(F: PResourceFile): boolean;
  882. var
  883. OK: boolean;
  884. begin
  885. F^.CreateResource(resVideo,rcBinary,0);
  886. OK:=F^.AddResourceEntry(resVideo,langDefault,0,ScreenMode,
  887. SizeOf(TVideoMode));
  888. if OK=false then
  889. ErrorBox(msg_errorstoringvideomode,nil);
  890. WriteVideoMode:=OK;
  891. end;
  892. function ReadVideoMode(F: PResourceFile;var NewScreenMode : TVideoMode): boolean;
  893. var
  894. OK,test : boolean;
  895. begin
  896. test:=F^.ReadResourceEntry(resVideo,langDefault,NewScreenMode,
  897. sizeof(NewScreenMode));
  898. if not test then
  899. NewScreenMode:=ScreenMode;
  900. OK:=test;
  901. if OK=false then
  902. ErrorBox(msg_errorreadingvideomode,nil);
  903. ReadVideoMode:=OK;
  904. end;
  905. function ReadSymbols(F: PResourceFile): boolean;
  906. var S: PMemoryStream;
  907. OK: boolean;
  908. R: PResource;
  909. begin
  910. ReadSymbols:=false; { if no symbols stored ... no problems }
  911. R:=F^.FindResource(resSymbols);
  912. if not Assigned(R) then
  913. exit;
  914. PushStatus(msg_readingsymbolinformation);
  915. New(S, Init(32*1024,4096));
  916. OK:=F^.ReadResourceEntryToStream(resSymbols,langDefault,S^);
  917. S^.Seek(0);
  918. if OK then
  919. OK:=LoadBrowserCol(S);
  920. Dispose(S, Done);
  921. if OK=false then
  922. ErrorBox(msg_errorloadingsymbolinformation,nil);
  923. PopStatus;
  924. ReadSymbols:=OK;
  925. end;
  926. function WriteSymbols(F: PResourceFile): boolean;
  927. var S: PMemoryStream;
  928. OK: boolean;
  929. begin
  930. OK:=Assigned(Modules);
  931. if OK then
  932. begin
  933. PushStatus(msg_storingsymbolinformation);
  934. New(S, Init(200*1024,4096));
  935. OK:=Assigned(S);
  936. if OK then
  937. OK:=StoreBrowserCol(S);
  938. if OK then
  939. begin
  940. S^.Seek(0);
  941. F^.CreateResource(resSymbols,rcBinary,0);
  942. OK:=F^.AddResourceEntryFromStream(resSymbols,langDefault,0,S^,S^.GetSize);
  943. end;
  944. Dispose(S, Done);
  945. if OK=false then
  946. ErrorBox(msg_errorstoringsymbolinformation,nil);
  947. PopStatus;
  948. end;
  949. WriteSymbols:=OK;
  950. end;
  951. function LoadDesktop: boolean;
  952. var OK,VOK: boolean;
  953. F: PResourceFile;
  954. VM : TVideoMode;
  955. begin
  956. PushStatus(msg_readingdesktopfile);
  957. New(F, LoadFile(DesktopPath));
  958. OK:=false;
  959. if Assigned(F) then
  960. begin
  961. OK:=ReadFlags(F);
  962. VOK:=ReadVideoMode(F,VM);
  963. if VOK and ((VM.Col<>ScreenMode.Col) or
  964. (VM.Row<>ScreenMode.Row) or (VM.Color<>ScreenMode.Color)) then
  965. begin
  966. if Assigned(Application) then
  967. Application^.SetScreenVideoMode(VM);
  968. end;
  969. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  970. OK:=ReadHistory(F) and OK;
  971. if ((DesktopFileFlags and dfWatches)<>0) then
  972. OK:=ReadWatches(F) and OK;
  973. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  974. OK:=ReadBreakpoints(F) and OK;
  975. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  976. OK:=ReadOpenWindows(F) and OK;
  977. { no errors if no browser info available PM }
  978. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  979. OK:=ReadSymbols(F) and OK;
  980. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  981. OK:=ReadCodeComplete(F) and OK;
  982. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  983. OK:=ReadCodeTemplates(F) and OK;
  984. if not OverrideLastDirOption then
  985. if ((DesktopFileFlags and dfReturnToLastDir)<>0) then
  986. StartupOptions:=StartupOptions or soReturnToLastDir
  987. else
  988. StartupOptions:=StartupOptions and( not soReturnToLastDir);
  989. if ((StartupOptions and soReturnToLastDir)<>0) then
  990. OK:=ReadReturnToLastDir(F) and OK;
  991. {$ifdef Unix}
  992. OK:=ReadKeys(F) and OK;
  993. {$endif Unix}
  994. Dispose(F, Done);
  995. end;
  996. PopStatus;
  997. LoadDesktop:=OK;
  998. end;
  999. function SaveDesktop: boolean;
  1000. var OK: boolean;
  1001. F: PResourceFile;
  1002. TempPath: string;
  1003. begin
  1004. TempPath:=DirOf(DesktopPath)+DesktopTempName;
  1005. PushStatus(msg_writingdesktopfile);
  1006. New(F, CreateFile(TempPath));
  1007. if Assigned(Clipboard) then
  1008. if (DesktopFileFlags and dfClipboardContent)<>0 then
  1009. Clipboard^.SetFlags(Clipboard^.GetFlags or efStoreContent)
  1010. else
  1011. Clipboard^.SetFlags(Clipboard^.GetFlags and not efStoreContent);
  1012. OK:=false;
  1013. if Assigned(F) then
  1014. begin
  1015. OK:=WriteFlags(F);
  1016. OK:=OK and WriteVideoMode(F);
  1017. if ((DesktopFileFlags and dfHistoryLists)<>0) then
  1018. OK:=OK and WriteHistory(F);
  1019. if ((DesktopFileFlags and dfWatches)<>0) then
  1020. OK:=OK and WriteWatches(F);
  1021. if ((DesktopFileFlags and dfBreakpoints)<>0) then
  1022. OK:=OK and WriteBreakpoints(F);
  1023. if ((DesktopFileFlags and dfOpenWindows)<>0) then
  1024. OK:=OK and WriteOpenWindows(F);
  1025. { no errors if no browser info available PM }
  1026. if ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1027. OK:=OK and (WriteSymbols(F) or not Assigned(Modules));
  1028. if ((DesktopFileFlags and dfCodeCompleteWords)<>0) then
  1029. OK:=OK and WriteCodeComplete(F);
  1030. if ((DesktopFileFlags and dfCodeTemplates)<>0) then
  1031. OK:=OK and WriteCodeTemplates(F);
  1032. {if ((DesktopFileFlags and dfReturnToLastDir)<>0) then
  1033. always write last dir }
  1034. OK:=WriteReturnToLastDir(F) and OK;
  1035. {$ifdef Unix}
  1036. OK:=OK and WriteKeys(F);
  1037. {$endif Unix}
  1038. Dispose(F, Done);
  1039. end;
  1040. if OK then
  1041. begin
  1042. if ExistsFile(DesktopPath) then
  1043. OK:=EraseFile(DesktopPath);
  1044. OK:=OK and RenameFile(TempPath,DesktopPath);
  1045. if OK=false then
  1046. ErrorBox(msg_failedtoreplacedesktopfile,nil);
  1047. end;
  1048. PopStatus;
  1049. SaveDesktop:=OK;
  1050. end;
  1051. function WriteSymbolsFile(const filename : string): boolean;
  1052. var OK: boolean;
  1053. F: PResourceFile;
  1054. begin
  1055. WriteSymbolsFile:=false;
  1056. If not assigned(Modules) then
  1057. exit;
  1058. New(F, CreateFile(FileName));
  1059. OK:=Assigned(F);
  1060. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1061. OK:=OK and WriteSymbols(F);
  1062. if assigned(F) then
  1063. Dispose(F,Done);
  1064. WriteSymbolsFile:=OK;
  1065. end;
  1066. function ReadSymbolsFile(const FileName : string): boolean;
  1067. var OK: boolean;
  1068. F: PResourceFile;
  1069. begin
  1070. ReadSymbolsFile:=false;
  1071. { Don't read again !! }
  1072. If assigned(Modules) then
  1073. exit;
  1074. New(F, LoadFile(FileName));
  1075. OK:=Assigned(F);
  1076. if OK and ((DesktopFileFlags and dfSymbolInformation)<>0) then
  1077. OK:=OK and ReadSymbols(F);
  1078. if assigned(F) then
  1079. Dispose(F,Done);
  1080. ReadSymbolsFile:=OK;
  1081. end;
  1082. END.