summaryrefslogtreecommitdiff
path: root/gui/bin.inc
blob: d30e20e75318cfa3ae4237010c53d09229c7d934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
    fpGUI  -  Free Pascal GUI Library
    
    Bin widget declarations
    
    Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this
    distribution, for details of the copyright.

    See the file COPYING.modifiedLGPL, included in this distribution,
    for details about redistributing fpGUI.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}

{%mainunit fpgui.pas}

{$IFDEF read_interface}

  { Bin widget declarations }
  TBinWidget = class(TContainerWidget)
  protected
    FChild: TWidget;
    procedure   SetChild(AChild: TWidget);
    function    GetChildCount: Integer; override;
    function    GetChild(Index: Integer): TWidget; override;
    procedure   CalcSizes; override;
  public // !!!: temporarily
    property    Child: TWidget read FChild write SetChild;
    // really public :)
    function    ContainsChild(AChild: TWidget): Boolean; override;
    procedure   InsertChild(AChild: TWidget); override;
    procedure   RemoveChild(AChild: TWidget); override;
  end;

{$ENDIF read_interface}



{$IFDEF read_implementation}



// ===================================================================
//   TBinWidget
// ===================================================================

function TBinWidget.ContainsChild(AChild: TWidget): Boolean;
begin
  Result := Assigned(AChild) and (FChild = AChild);
end;


procedure TBinWidget.InsertChild(AChild: TWidget);
begin
  if FChild <> AChild then
  begin
    if Assigned(FChild) then
      FChild.Parent := nil;
    FChild := AChild;
    FChild.Parent := Self;
  end;
end;


procedure TBinWidget.RemoveChild(AChild: TWidget);
begin
  if FChild = AChild then
  begin
    FChild := nil;
    AChild.Parent := nil;
  end;
end;


function TBinWidget.GetChildCount: Integer;
begin
  Result := Ord(Assigned(Child));
end;


function TBinWidget.GetChild(Index: Integer): TWidget;
begin
  if (Index = 0) and Assigned(Child) then
    Result := Child
  else
    TList.Error(SListIndexError, Index);
end;


procedure TBinWidget.CalcSizes;
begin
  LAYOUTTRACE('TBinWidget.CalcSizes for %s:%s', [Name, ClassName]);
  if Assigned(Child) then
  begin
    FMinSize := Child.MinSize;
    FMaxSize := Child.MaxSize;
    FDefSize := Child.DefSize;
  end;
end;


procedure TBinWidget.SetChild(AChild: TWidget);
begin
  InsertChild(AChild);
end;


{$ENDIF read_implementation}