tabs.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. {
  2. Tabbed group for TV/FV dialogs
  3. Copyright 2000-4 by Free Pascal core team
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library 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. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this library; if not, write to the Free
  14. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. unit tabs;
  17. {$I platform.inc} (* Multi-platform support defines *)
  18. {$CODEPAGE cp437}
  19. interface
  20. uses
  21. objects, drivers, views, fvconsts;
  22. type
  23. PTabItem = ^TTabItem;
  24. TTabItem = record
  25. Next : PTabItem;
  26. View : PView;
  27. Dis : boolean;
  28. end;
  29. PTabDef = ^TTabDef;
  30. TTabDef = record
  31. Next : PTabDef;
  32. Name : PString;
  33. Items : PTabItem;
  34. DefItem : PView;
  35. ShortCut : char;
  36. end;
  37. PTab = ^TTab;
  38. TTab = object(TGroup)
  39. TabDefs : PTabDef;
  40. ActiveDef : integer;
  41. DefCount : word;
  42. constructor Init(var Bounds: TRect; ATabDef: PTabDef);
  43. constructor Load (var S: TStream);
  44. function AtTab(Index: integer): PTabDef; virtual;
  45. procedure SelectTab(Index: integer); virtual;
  46. procedure Store (var S: TStream);
  47. function TabCount: integer;
  48. function Valid(Command: Word): Boolean; virtual;
  49. procedure ChangeBounds(var Bounds: TRect); virtual;
  50. procedure HandleEvent(var Event: TEvent); virtual;
  51. function GetPalette: PPalette; virtual;
  52. procedure Draw; virtual;
  53. function DataSize: sw_word;virtual;
  54. procedure SetData(var Rec);virtual;
  55. procedure GetData(var Rec);virtual;
  56. procedure SetState(AState: Word; Enable: Boolean); virtual;
  57. destructor Done; virtual;
  58. private
  59. InDraw: boolean;
  60. function FirstSelectable: PView;
  61. function LastSelectable: PView;
  62. end;
  63. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  64. procedure DisposeTabItem(P: PTabItem);
  65. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  66. procedure DisposeTabDef(P: PTabDef);
  67. procedure RegisterTab;
  68. const
  69. RTab: TStreamRec = (
  70. ObjType: idTab;
  71. {$IFDEF BP_VMTLink} { BP style VMT link }
  72. VmtLink: Ofs (TypeOf (TTab)^);
  73. {$ELSE BP_VMTLink} { Alt style VMT link }
  74. VmtLink: TypeOf (TTab);
  75. {$ENDIF BP_VMTLink}
  76. Load: @TTab.Load;
  77. Store: @TTab.Store
  78. );
  79. implementation
  80. uses
  81. FvCommon,dialogs;
  82. constructor TTab.Init(var Bounds: TRect; ATabDef: PTabDef);
  83. begin
  84. inherited Init(Bounds);
  85. Options:=Options or ofSelectable or ofFirstClick or ofPreProcess or ofPostProcess;
  86. GrowMode:=gfGrowHiX+gfGrowHiY+gfGrowRel;
  87. TabDefs:=ATabDef;
  88. ActiveDef:=-1;
  89. SelectTab(0);
  90. ReDraw;
  91. end;
  92. constructor TTab.Load (var S: TStream);
  93. function DoLoadTabItems (var XDefItem: PView; ActItem: longint): PTabItem;
  94. var
  95. Count: longint;
  96. Cur, First: PTabItem;
  97. Last: ^PTabItem;
  98. begin
  99. Cur := nil; { Preset nil }
  100. Last := @First; { Start on first item }
  101. S.Read (Count, SizeOf(Count)); { Read item count }
  102. while (Count > 0) do
  103. begin
  104. New (Cur); { New status item }
  105. Last^ := Cur; { First chain part }
  106. if (Cur <> nil) then { Check pointer valid }
  107. begin
  108. Last := @Cur^.Next; { Chain complete }
  109. S.Read (Cur^.Dis, SizeOf (Cur^.Dis));
  110. Cur^.View := PView (S.Get);
  111. if ActItem = 0 then
  112. XDefItem := Cur^.View; { Find default view }
  113. end;
  114. Dec (Count); { One item loaded }
  115. Dec (ActItem);
  116. end;
  117. Last^ := nil; { Now chain end }
  118. DoLoadTabItems := First; { Return the list }
  119. end;
  120. function DoLoadTabDefs: PTabDef;
  121. var
  122. Count: longint;
  123. Cur, First: PTabDef;
  124. Last: ^PTabDef;
  125. ActItem: longint;
  126. begin
  127. Last := @First; { Start on first }
  128. Count := DefCount;
  129. while (Count > 0) do
  130. begin
  131. New (Cur); { New status def }
  132. Last^ := Cur; { First part of chain }
  133. if (Cur <> nil) then { Check pointer valid }
  134. begin
  135. Last := @Cur^.Next; { Chain complete }
  136. Cur^.Name := S.ReadStr; { Read name }
  137. S.Read (Cur^.ShortCut, SizeOf (Cur^.ShortCut));
  138. S.Read (ActItem, SizeOf (ActItem));
  139. Cur^.Items := DoLoadTabItems (Cur^.DefItem, ActItem); { Set pointer }
  140. end;
  141. Dec (Count); { One item loaded }
  142. end;
  143. Last^ := nil; { Now chain ends }
  144. DoLoadTabDefs := First; { Return item list }
  145. end;
  146. begin
  147. inherited Load (S);
  148. S.Read (DefCount, SizeOf (DefCount));
  149. S.Read (ActiveDef, SizeOf (ActiveDef));
  150. TabDefs := DoLoadTabDefs;
  151. end;
  152. procedure TTab.Store (var S: TStream);
  153. procedure DoStoreTabItems (Cur: PTabItem; XDefItem: PView);
  154. var
  155. Count: longint;
  156. T: PTabItem;
  157. ActItem: longint;
  158. begin
  159. Count := 0; { Clear count }
  160. T := Cur; { Start on current }
  161. while (T <> nil) do
  162. begin
  163. if T^.View = XDefItem then { Current = active? }
  164. ActItem := Count; { => set order }
  165. Inc (Count); { Count items }
  166. T := T^.Next; { Next item }
  167. end;
  168. S.Write (ActItem, SizeOf (ActItem));
  169. S.Write (Count, SizeOf (Count)); { Write item count }
  170. while (Cur <> nil) do
  171. begin
  172. S.Write (Cur^.Dis, SizeOf (Cur^.Dis));
  173. S.Put (Cur^.View);
  174. end;
  175. end;
  176. procedure DoStoreTabDefs (Cur: PTabDef);
  177. begin
  178. while (Cur <> nil) do
  179. begin
  180. with Cur^ do
  181. begin
  182. S.WriteStr (Cur^.Name); { Write name }
  183. S.Write (Cur^.ShortCut, SizeOf (Cur^.ShortCut));
  184. DoStoreTabItems (Items, DefItem); { Store the items }
  185. end;
  186. Cur := Cur^.Next; { Next status item }
  187. end;
  188. end;
  189. begin
  190. inherited Store (S);
  191. S.Write (DefCount, SizeOf (DefCount));
  192. S.Write (ActiveDef, SizeOf (ActiveDef));
  193. DoStoreTabDefs (TabDefs);
  194. end;
  195. function TTab.TabCount: integer;
  196. var i: integer;
  197. P: PTabDef;
  198. begin
  199. I:=0; P:=TabDefs;
  200. while (P<>nil) do
  201. begin
  202. Inc(I);
  203. P:=P^.Next;
  204. end;
  205. TabCount:=I;
  206. end;
  207. function TTab.AtTab(Index: integer): PTabDef;
  208. var i: integer;
  209. P: PTabDef;
  210. begin
  211. i:=0; P:=TabDefs;
  212. while (I<Index) do
  213. begin
  214. if P=nil then RunError($AA);
  215. P:=P^.Next;
  216. Inc(i);
  217. end;
  218. AtTab:=P;
  219. end;
  220. procedure TTab.SelectTab(Index: integer);
  221. var P: PTabItem;
  222. V: PView;
  223. begin
  224. if ActiveDef<>Index then
  225. begin
  226. if Owner<>nil then Owner^.Lock;
  227. Lock;
  228. { --- Update --- }
  229. if TabDefs<>nil then
  230. begin
  231. DefCount:=1;
  232. while AtTab(DefCount-1)^.Next<>nil do Inc(DefCount);
  233. end
  234. else DefCount:=0;
  235. if ActiveDef<>-1 then
  236. begin
  237. P:=AtTab(ActiveDef)^.Items;
  238. while P<>nil do
  239. begin
  240. if P^.View<>nil then Delete(P^.View);
  241. P:=P^.Next;
  242. end;
  243. end;
  244. ActiveDef:=Index;
  245. P:=AtTab(ActiveDef)^.Items;
  246. while P<>nil do
  247. begin
  248. if P^.View<>nil then Insert(P^.View);
  249. P:=P^.Next;
  250. end;
  251. V:=AtTab(ActiveDef)^.DefItem;
  252. if V<>nil then V^.Select;
  253. ReDraw;
  254. { --- Update --- }
  255. UnLock;
  256. if Owner<>nil then Owner^.UnLock;
  257. DrawView;
  258. end;
  259. end;
  260. procedure TTab.ChangeBounds(var Bounds: TRect);
  261. var D: TPoint;
  262. procedure DoCalcChange(P: PView); {$ifndef FPC}far;{$endif}
  263. var
  264. R: TRect;
  265. begin
  266. if P^.Owner=nil then Exit; { it think this is a bug in TV }
  267. P^.CalcBounds(R, D);
  268. P^.ChangeBounds(R);
  269. end;
  270. var
  271. P: PTabItem;
  272. I: integer;
  273. begin
  274. D.X := Bounds.B.X - Bounds.A.X - Size.X;
  275. D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  276. inherited ChangeBounds(Bounds);
  277. for I:=0 to TabCount-1 do
  278. if I<>ActiveDef then
  279. begin
  280. P:=AtTab(I)^.Items;
  281. while P<>nil do
  282. begin
  283. if P^.View<>nil then DoCalcChange(P^.View);
  284. P:=P^.Next;
  285. end;
  286. end;
  287. end;
  288. function TTab.FirstSelectable: PView;
  289. var
  290. FV : PView;
  291. begin
  292. FV := First;
  293. while (FV<>nil) and ((FV^.Options and ofSelectable)=0) and (FV<>Last) do
  294. FV:=FV^.Next;
  295. if FV<>nil then
  296. if (FV^.Options and ofSelectable)=0 then FV:=nil;
  297. FirstSelectable:=FV;
  298. end;
  299. function TTab.LastSelectable: PView;
  300. var
  301. LV : PView;
  302. begin
  303. LV := Last;
  304. while (LV<>nil) and ((LV^.Options and ofSelectable)=0) and (LV<>First) do
  305. LV:=LV^.Prev;
  306. if LV<>nil then
  307. if (LV^.Options and ofSelectable)=0 then LV:=nil;
  308. LastSelectable:=LV;
  309. end;
  310. procedure TTab.HandleEvent(var Event: TEvent);
  311. var Index : integer;
  312. I : integer;
  313. X : integer;
  314. Len : byte;
  315. P : TPoint;
  316. V : PView;
  317. CallOrig: boolean;
  318. LastV : PView;
  319. FirstV: PView;
  320. begin
  321. if (Event.What and evMouseDown)<>0 then
  322. begin
  323. MakeLocal(Event.Where,P);
  324. if P.Y<3 then
  325. begin
  326. Index:=-1; X:=1;
  327. for i:=0 to DefCount-1 do
  328. begin
  329. Len:=CStrLen(AtTab(i)^.Name^);
  330. if (P.X>=X) and (P.X<=X+Len+1) then Index:=i;
  331. X:=X+Len+3;
  332. end;
  333. if Index<>-1 then
  334. SelectTab(Index);
  335. end;
  336. end;
  337. if Event.What=evKeyDown then
  338. begin
  339. Index:=-1;
  340. case Event.KeyCode of
  341. kbTab,kbShiftTab :
  342. if GetState(sfSelected) then
  343. begin
  344. if Current<>nil then
  345. begin
  346. LastV:=LastSelectable; FirstV:=FirstSelectable;
  347. if ((Current=LastV) or (Current=PLabel(LastV)^.Link)) and (Event.KeyCode=kbShiftTab) then
  348. begin
  349. if Owner<>nil then Owner^.SelectNext(true);
  350. end else
  351. if ((Current=FirstV) or (Current=PLabel(FirstV)^.Link)) and (Event.KeyCode=kbTab) then
  352. begin
  353. Lock;
  354. if Owner<>nil then Owner^.SelectNext(false);
  355. UnLock;
  356. end else
  357. SelectNext(Event.KeyCode=kbShiftTab);
  358. ClearEvent(Event);
  359. end;
  360. end;
  361. else
  362. for I:=0 to DefCount-1 do
  363. begin
  364. if Upcase(GetAltChar(Event.KeyCode))=AtTab(I)^.ShortCut
  365. then begin
  366. Index:=I;
  367. ClearEvent(Event);
  368. Break;
  369. end;
  370. end;
  371. end;
  372. if Index<>-1 then
  373. begin
  374. Select;
  375. SelectTab(Index);
  376. V:=AtTab(ActiveDef)^.DefItem;
  377. if V<>nil then V^.Focus;
  378. end;
  379. end;
  380. CallOrig:=true;
  381. if Event.What=evKeyDown then
  382. begin
  383. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  384. then
  385. else CallOrig:=false;
  386. end;
  387. if CallOrig then inherited HandleEvent(Event);
  388. end;
  389. function TTab.GetPalette: PPalette;
  390. begin
  391. GetPalette:=nil;
  392. end;
  393. procedure TTab.Draw;
  394. var B : TDrawBuffer;
  395. i : integer;
  396. C1,C2,C3,C : word;
  397. HeaderLen : integer;
  398. X,X2 : integer;
  399. Name : PString;
  400. ActiveKPos : integer;
  401. ActiveVPos : integer;
  402. FC : char;
  403. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  404. var i: integer;
  405. begin
  406. if Y+H>Size.Y then H:=Size.Y-Y;
  407. if X+W>Size.X then W:=Size.X-X;
  408. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  409. else for i:=1 to H do
  410. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  411. end;
  412. procedure ClearBuf;
  413. begin
  414. MoveChar(B,' ',C1,Size.X);
  415. end;
  416. begin
  417. if InDraw then Exit;
  418. InDraw:=true;
  419. { - Start of TGroup.Draw - }
  420. { if Buffer = nil then
  421. begin
  422. GetBuffer;
  423. end; }
  424. { - Start of TGroup.Draw - }
  425. C1:=GetColor(1);
  426. C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256;
  427. C3:=GetColor(8)+GetColor({9}8)*256;
  428. { Calculate the size of the headers }
  429. HeaderLen:=0;
  430. for i:=0 to DefCount-1 do
  431. HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3;
  432. Dec(HeaderLen);
  433. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  434. { --- 1. sor --- }
  435. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[HeaderLen+1],'³',C1,1);
  436. X:=1;
  437. for i:=0 to DefCount-1 do
  438. begin
  439. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  440. if i=ActiveDef
  441. then begin
  442. ActiveKPos:=X-1;
  443. ActiveVPos:=X+X2+2;
  444. if GetState(sfFocused) then C:=C3 else C:=C2;
  445. end
  446. else C:=C2;
  447. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  448. MoveChar(B[X-1],'³',C1,1);
  449. end;
  450. SWriteBuf(0,1,Size.X,1,B);
  451. { --- 0. sor --- }
  452. ClearBuf; MoveChar(B[0],'Ú',C1,1);
  453. X:=1;
  454. for i:=0 to DefCount-1 do
  455. begin
  456. if I<ActiveDef then FC:='Ú'
  457. else FC:='¿';
  458. X2:=CStrLen(AtTab(i)^.Name^)+2;
  459. MoveChar(B[X+X2],{'Â'}FC,C1,1);
  460. if i=DefCount-1 then X2:=X2+1;
  461. if X2>0 then
  462. MoveChar(B[X],'Ä',C1,X2);
  463. X:=X+X2+1;
  464. end;
  465. MoveChar(B[HeaderLen+1],'¿',C1,1);
  466. MoveChar(B[ActiveKPos],'Ú',C1,1); MoveChar(B[ActiveVPos],'¿',C1,1);
  467. SWriteBuf(0,0,Size.X,1,B);
  468. { --- 2. sor --- }
  469. MoveChar(B[1],'Ä',C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],'Ä',C1,Max(Size.X-HeaderLen-3,0));
  470. MoveChar(B[Size.X-1],'¿',C1,1);
  471. MoveChar(B[ActiveKPos],'Ù',C1,1);
  472. if ActiveDef=0 then MoveChar(B[0],'³',C1,1)
  473. else MoveChar(B[0],{'Ã'}'Ú',C1,1);
  474. MoveChar(B[HeaderLen+1],'Ä'{'Á'},C1,1); MoveChar(B[ActiveVPos],'À',C1,1);
  475. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  476. SWriteBuf(0,2,Size.X,1,B);
  477. { --- marad‚k sor --- }
  478. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[Size.X-1],'³',C1,1);
  479. {SWriteBuf(0,3,Size.X,Size.Y-4,B);}
  480. for i:=3 to Size.Y-1 do
  481. SWriteBuf(0,i,Size.X,1,B);
  482. { --- Size.X . sor --- }
  483. MoveChar(B[0],'À',C1,1); MoveChar(B[1],'Ä',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],'Ù',C1,1);
  484. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  485. { - End of TGroup.Draw - }
  486. if Buffer <> nil then
  487. begin
  488. Lock;
  489. Redraw;
  490. UnLock;
  491. end;
  492. if Buffer <> nil then
  493. WriteBuf(0, 0, Size.X, Size.Y, Buffer^)
  494. else
  495. Redraw;
  496. { - End of TGroup.Draw - }
  497. InDraw:=false;
  498. end;
  499. function TTab.Valid(Command: Word): Boolean;
  500. var PT : PTabDef;
  501. PI : PTabItem;
  502. OK : boolean;
  503. begin
  504. OK:=true;
  505. PT:=TabDefs;
  506. while (PT<>nil) and (OK=true) do
  507. begin
  508. PI:=PT^.Items;
  509. while (PI<>nil) and (OK=true) do
  510. begin
  511. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  512. PI:=PI^.Next;
  513. end;
  514. PT:=PT^.Next;
  515. end;
  516. Valid:=OK;
  517. end;
  518. procedure TTab.SetData(var Rec);
  519. type
  520. Bytes = array[0..65534] of Byte;
  521. var
  522. I: Sw_Word;
  523. PT : PTabDef;
  524. PI : PTabItem;
  525. begin
  526. I := 0;
  527. PT:=TabDefs;
  528. while (PT<>nil) do
  529. begin
  530. PI:=PT^.Items;
  531. while (PI<>nil) do
  532. begin
  533. if PI^.View<>nil then
  534. begin
  535. PI^.View^.SetData(Bytes(Rec)[I]);
  536. Inc(I, PI^.View^.DataSize);
  537. end;
  538. PI:=PI^.Next;
  539. end;
  540. PT:=PT^.Next;
  541. end;
  542. end;
  543. function TTab.DataSize: sw_word;
  544. var
  545. I: Sw_Word;
  546. PT : PTabDef;
  547. PI : PTabItem;
  548. begin
  549. I := 0;
  550. PT:=TabDefs;
  551. while (PT<>nil) do
  552. begin
  553. PI:=PT^.Items;
  554. while (PI<>nil) do
  555. begin
  556. if PI^.View<>nil then
  557. begin
  558. Inc(I, PI^.View^.DataSize);
  559. end;
  560. PI:=PI^.Next;
  561. end;
  562. PT:=PT^.Next;
  563. end;
  564. DataSize:=i;
  565. end;
  566. procedure TTab.GetData(var Rec);
  567. type
  568. Bytes = array[0..65534] of Byte;
  569. var
  570. I: Sw_Word;
  571. PT : PTabDef;
  572. PI : PTabItem;
  573. begin
  574. I := 0;
  575. PT:=TabDefs;
  576. while (PT<>nil) do
  577. begin
  578. PI:=PT^.Items;
  579. while (PI<>nil) do
  580. begin
  581. if PI^.View<>nil then
  582. begin
  583. PI^.View^.GetData(Bytes(Rec)[I]);
  584. Inc(I, PI^.View^.DataSize);
  585. end;
  586. PI:=PI^.Next;
  587. end;
  588. PT:=PT^.Next;
  589. end;
  590. end;
  591. procedure TTab.SetState(AState: Word; Enable: Boolean);
  592. var
  593. LastV : PView;
  594. begin
  595. inherited SetState(AState,Enable);
  596. { Select first item }
  597. if (AState and sfSelected)<>0 then
  598. begin
  599. LastV:=LastSelectable;
  600. if LastV<>nil then
  601. LastV^.Select;
  602. end;
  603. end;
  604. destructor TTab.Done;
  605. var P,X: PTabDef;
  606. procedure DeleteViews(P: PView); {$ifndef FPC}far;{$endif}
  607. begin
  608. if P<>nil then Delete(P);
  609. end;
  610. begin
  611. ForEach(@DeleteViews);
  612. inherited Done;
  613. P:=TabDefs;
  614. while P<>nil do
  615. begin
  616. X:=P^.Next;
  617. DisposeTabDef(P);
  618. P:=X;
  619. end;
  620. end;
  621. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  622. var P: PTabItem;
  623. begin
  624. New(P); FillChar(P^,SizeOf(P^),0);
  625. P^.Next:=ANext; P^.View:=AView;
  626. NewTabItem:=P;
  627. end;
  628. procedure DisposeTabItem(P: PTabItem);
  629. begin
  630. if P<>nil then
  631. begin
  632. if P^.View<>nil then Dispose(P^.View, Done);
  633. Dispose(P);
  634. end;
  635. end;
  636. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  637. var P: PTabDef;
  638. x: byte;
  639. begin
  640. New(P);
  641. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  642. x:=pos('~',AName);
  643. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  644. else P^.ShortCut:=#0;
  645. P^.DefItem:=ADefItem;
  646. NewTabDef:=P;
  647. end;
  648. procedure DisposeTabDef(P: PTabDef);
  649. var PI,X: PTabItem;
  650. begin
  651. DisposeStr(P^.Name);
  652. PI:=P^.Items;
  653. while PI<>nil do
  654. begin
  655. X:=PI^.Next;
  656. DisposeTabItem(PI);
  657. PI:=X;
  658. end;
  659. Dispose(P);
  660. end;
  661. procedure RegisterTab;
  662. begin
  663. RegisterType (RTab);
  664. end;
  665. begin
  666. RegisterTab;
  667. end.