tabs.pas 19 KB

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