tabs.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. {
  2. $Id$
  3. Tabbed group for TV/FV dialogs
  4. Copyright 2000-4 by Free Pascal core team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free
  15. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. unit tabs;
  18. interface
  19. uses
  20. objects, drivers, views, fvconsts;
  21. {$I platform.inc} (* Multi-platform support defines *)
  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 (AtTab (I)^.ShortCut <> #0) and
  365. (Upcase(GetAltChar(Event.KeyCode)) = AtTab(I)^.ShortCut)
  366. then begin
  367. Index:=I;
  368. ClearEvent(Event);
  369. Break;
  370. end;
  371. end;
  372. end;
  373. if Index<>-1 then
  374. begin
  375. Select;
  376. SelectTab(Index);
  377. V:=AtTab(ActiveDef)^.DefItem;
  378. if V<>nil then V^.Focus;
  379. end;
  380. end;
  381. CallOrig:=true;
  382. if Event.What=evKeyDown then
  383. begin
  384. if ((Owner<>nil) and (Owner^.Phase=phPostProcess) and (GetAltChar(Event.KeyCode)<>#0)) or GetState(sfFocused)
  385. then
  386. else CallOrig:=false;
  387. end;
  388. if CallOrig then inherited HandleEvent(Event);
  389. end;
  390. function TTab.GetPalette: PPalette;
  391. begin
  392. GetPalette:=nil;
  393. end;
  394. procedure TTab.Draw;
  395. var B : TDrawBuffer;
  396. i : integer;
  397. C1,C2,C3,C : word;
  398. HeaderLen : integer;
  399. X,X2 : integer;
  400. Name : PString;
  401. ActiveKPos : integer;
  402. ActiveVPos : integer;
  403. FC : char;
  404. procedure SWriteBuf(X,Y,W,H: integer; var Buf);
  405. var i: integer;
  406. begin
  407. if Y+H>Size.Y then H:=Size.Y-Y;
  408. if X+W>Size.X then W:=Size.X-X;
  409. if Buffer=nil then WriteBuf(X,Y,W,H,Buf)
  410. else for i:=1 to H do
  411. Move(Buf,Buffer^[X+(Y+i-1)*Size.X],W*2);
  412. end;
  413. procedure ClearBuf;
  414. begin
  415. MoveChar(B,' ',C1,Size.X);
  416. end;
  417. begin
  418. if InDraw then Exit;
  419. InDraw:=true;
  420. { - Start of TGroup.Draw - }
  421. { if Buffer = nil then
  422. begin
  423. GetBuffer;
  424. end; }
  425. { - Start of TGroup.Draw - }
  426. C1:=GetColor(1);
  427. C2:=(GetColor(7) and $f0 or $08)+GetColor(9)*256;
  428. C3:=GetColor(8)+GetColor({9}8)*256;
  429. { Calculate the size of the headers }
  430. HeaderLen:=0;
  431. for i:=0 to DefCount-1 do
  432. HeaderLen:=HeaderLen+CStrLen(AtTab(i)^.Name^)+3;
  433. Dec(HeaderLen);
  434. if HeaderLen>Size.X-2 then HeaderLen:=Size.X-2;
  435. { --- 1. sor --- }
  436. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[HeaderLen+1],'³',C1,1);
  437. X:=1;
  438. for i:=0 to DefCount-1 do
  439. begin
  440. Name:=AtTab(i)^.Name; X2:=CStrLen(Name^);
  441. if i=ActiveDef
  442. then begin
  443. ActiveKPos:=X-1;
  444. ActiveVPos:=X+X2+2;
  445. if GetState(sfFocused) then C:=C3 else C:=C2;
  446. end
  447. else C:=C2;
  448. MoveCStr(B[X],' '+Name^+' ',C); X:=X+X2+3;
  449. MoveChar(B[X-1],'³',C1,1);
  450. end;
  451. SWriteBuf(0,1,Size.X,1,B);
  452. { --- 0. sor --- }
  453. ClearBuf; MoveChar(B[0],'Ú',C1,1);
  454. X:=1;
  455. for i:=0 to DefCount-1 do
  456. begin
  457. if I<ActiveDef then FC:='Ú'
  458. else FC:='¿';
  459. X2:=CStrLen(AtTab(i)^.Name^)+2;
  460. MoveChar(B[X+X2],{'Â'}FC,C1,1);
  461. if i=DefCount-1 then X2:=X2+1;
  462. if X2>0 then
  463. MoveChar(B[X],'Ä',C1,X2);
  464. X:=X+X2+1;
  465. end;
  466. MoveChar(B[HeaderLen+1],'¿',C1,1);
  467. MoveChar(B[ActiveKPos],'Ú',C1,1); MoveChar(B[ActiveVPos],'¿',C1,1);
  468. SWriteBuf(0,0,Size.X,1,B);
  469. { --- 2. sor --- }
  470. MoveChar(B[1],'Ä',C1,Max(HeaderLen,0)); MoveChar(B[HeaderLen+2],'Ä',C1,Max(Size.X-HeaderLen-3,0));
  471. MoveChar(B[Size.X-1],'¿',C1,1);
  472. MoveChar(B[ActiveKPos],'Ù',C1,1);
  473. if ActiveDef=0 then MoveChar(B[0],'³',C1,1)
  474. else MoveChar(B[0],{'Ã'}'Ú',C1,1);
  475. MoveChar(B[HeaderLen+1],'Ä'{'Á'},C1,1); MoveChar(B[ActiveVPos],'À',C1,1);
  476. MoveChar(B[ActiveKPos+1],' ',C1,Max(ActiveVPos-ActiveKPos-1,0));
  477. SWriteBuf(0,2,Size.X,1,B);
  478. { --- marad‚k sor --- }
  479. ClearBuf; MoveChar(B[0],'³',C1,1); MoveChar(B[Size.X-1],'³',C1,1);
  480. {SWriteBuf(0,3,Size.X,Size.Y-4,B);}
  481. for i:=3 to Size.Y-1 do
  482. SWriteBuf(0,i,Size.X,1,B);
  483. { --- Size.X . sor --- }
  484. MoveChar(B[0],'À',C1,1); MoveChar(B[1],'Ä',C1,Max(Size.X-2,0)); MoveChar(B[Size.X-1],'Ù',C1,1);
  485. SWriteBuf(0,Size.Y-1,Size.X,1,B);
  486. { - End of TGroup.Draw - }
  487. if Buffer <> nil then
  488. begin
  489. Lock;
  490. Redraw;
  491. UnLock;
  492. end;
  493. if Buffer <> nil then
  494. WriteBuf(0, 0, Size.X, Size.Y, Buffer^)
  495. else
  496. Redraw;
  497. { - End of TGroup.Draw - }
  498. InDraw:=false;
  499. end;
  500. function TTab.Valid(Command: Word): Boolean;
  501. var PT : PTabDef;
  502. PI : PTabItem;
  503. OK : boolean;
  504. begin
  505. OK:=true;
  506. PT:=TabDefs;
  507. while (PT<>nil) and (OK=true) do
  508. begin
  509. PI:=PT^.Items;
  510. while (PI<>nil) and (OK=true) do
  511. begin
  512. if PI^.View<>nil then OK:=OK and PI^.View^.Valid(Command);
  513. PI:=PI^.Next;
  514. end;
  515. PT:=PT^.Next;
  516. end;
  517. Valid:=OK;
  518. end;
  519. procedure TTab.SetData(var Rec);
  520. type
  521. Bytes = array[0..65534] of Byte;
  522. var
  523. I: Sw_Word;
  524. PT : PTabDef;
  525. PI : PTabItem;
  526. begin
  527. I := 0;
  528. PT:=TabDefs;
  529. while (PT<>nil) do
  530. begin
  531. PI:=PT^.Items;
  532. while (PI<>nil) do
  533. begin
  534. if PI^.View<>nil then
  535. begin
  536. PI^.View^.SetData(Bytes(Rec)[I]);
  537. Inc(I, PI^.View^.DataSize);
  538. end;
  539. PI:=PI^.Next;
  540. end;
  541. PT:=PT^.Next;
  542. end;
  543. end;
  544. function TTab.DataSize: sw_word;
  545. var
  546. I: Sw_Word;
  547. PT : PTabDef;
  548. PI : PTabItem;
  549. begin
  550. I := 0;
  551. PT:=TabDefs;
  552. while (PT<>nil) do
  553. begin
  554. PI:=PT^.Items;
  555. while (PI<>nil) do
  556. begin
  557. if PI^.View<>nil then
  558. begin
  559. Inc(I, PI^.View^.DataSize);
  560. end;
  561. PI:=PI^.Next;
  562. end;
  563. PT:=PT^.Next;
  564. end;
  565. DataSize:=i;
  566. end;
  567. procedure TTab.GetData(var Rec);
  568. type
  569. Bytes = array[0..65534] of Byte;
  570. var
  571. I: Sw_Word;
  572. PT : PTabDef;
  573. PI : PTabItem;
  574. begin
  575. I := 0;
  576. PT:=TabDefs;
  577. while (PT<>nil) do
  578. begin
  579. PI:=PT^.Items;
  580. while (PI<>nil) do
  581. begin
  582. if PI^.View<>nil then
  583. begin
  584. PI^.View^.GetData(Bytes(Rec)[I]);
  585. Inc(I, PI^.View^.DataSize);
  586. end;
  587. PI:=PI^.Next;
  588. end;
  589. PT:=PT^.Next;
  590. end;
  591. end;
  592. procedure TTab.SetState(AState: Word; Enable: Boolean);
  593. var
  594. LastV : PView;
  595. begin
  596. inherited SetState(AState,Enable);
  597. { Select first item }
  598. if (AState and sfSelected)<>0 then
  599. begin
  600. LastV:=LastSelectable;
  601. if LastV<>nil then
  602. LastV^.Select;
  603. end;
  604. end;
  605. destructor TTab.Done;
  606. var P,X: PTabDef;
  607. procedure DeleteViews(P: PView); {$ifndef FPC}far;{$endif}
  608. begin
  609. if P<>nil then Delete(P);
  610. end;
  611. begin
  612. ForEach(@DeleteViews);
  613. inherited Done;
  614. P:=TabDefs;
  615. while P<>nil do
  616. begin
  617. X:=P^.Next;
  618. DisposeTabDef(P);
  619. P:=X;
  620. end;
  621. end;
  622. function NewTabItem(AView: PView; ANext: PTabItem): PTabItem;
  623. var P: PTabItem;
  624. begin
  625. New(P); FillChar(P^,SizeOf(P^),0);
  626. P^.Next:=ANext; P^.View:=AView;
  627. NewTabItem:=P;
  628. end;
  629. procedure DisposeTabItem(P: PTabItem);
  630. begin
  631. if P<>nil then
  632. begin
  633. if P^.View<>nil then Dispose(P^.View, Done);
  634. Dispose(P);
  635. end;
  636. end;
  637. function NewTabDef(AName: string; ADefItem: PView; AItems: PTabItem; ANext: PTabDef): PTabDef;
  638. var P: PTabDef;
  639. x: byte;
  640. begin
  641. New(P);
  642. P^.Next:=ANext; P^.Name:=NewStr(AName); P^.Items:=AItems;
  643. x:=pos('~',AName);
  644. if (x<>0) and (x<length(AName)) then P^.ShortCut:=Upcase(AName[x+1])
  645. else P^.ShortCut:=#0;
  646. P^.DefItem:=ADefItem;
  647. NewTabDef:=P;
  648. end;
  649. procedure DisposeTabDef(P: PTabDef);
  650. var PI,X: PTabItem;
  651. begin
  652. DisposeStr(P^.Name);
  653. PI:=P^.Items;
  654. while PI<>nil do
  655. begin
  656. X:=PI^.Next;
  657. DisposeTabItem(PI);
  658. PI:=X;
  659. end;
  660. Dispose(P);
  661. end;
  662. procedure RegisterTab;
  663. begin
  664. RegisterType (RTab);
  665. end;
  666. begin
  667. RegisterTab;
  668. end.
  669. {
  670. $Log$
  671. Revision 1.7 2005-05-15 15:23:28 hajny
  672. * fix for buggy behaviour with Tabs without shortcuts
  673. Revision 1.6 2005/02/14 17:13:18 peter
  674. * truncate log
  675. }