summaryrefslogtreecommitdiff
path: root/gui/container.inc
blob: fe129f1c38a978c82e232a9054d1a92dee84a2f0 (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
{
    fpGUI  -  Free Pascal Graphical User Interface
    Copyright (C) 2000 - 2001 by
      Areca Systems GmbH / Sebastian Guenther
    Copyright (C) 2006 by Graeme Geldenhuys 
      member of the fpGUI development team.

    Container class declarations

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

    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.pp}

{$IFDEF read_interface}

  { Container widget declarations }

  TContainerWidget = class(TWidget)
  protected
    function    DistributeEvent(Event: TEventObj): Boolean; override;
    function    GetChildCount: Integer; virtual; abstract;
    function    GetChild(Index: Integer): TWidget; virtual; abstract;
    property    ChildCount: Integer read GetChildCount;
    property    Children[Index: Integer]: TWidget read GetChild;
    // Move to public in decendant classes, if you want them visible
    procedure   InsertChild(AChild: TWidget); dynamic; virtual;
    procedure   RemoveChild(AChild: TWidget); dynamic; virtual;
  public
    function    GetChildAt(APoint: TPoint): TWidget;
    function    ContainsChild(AChild: TWidget): Boolean; dynamic; abstract;
  end;
  
{$ENDIF read_interface}



{$IFDEF read_implementation}

// ===================================================================
//   TContainerWidget
// ===================================================================

function TContainerWidget.GetChildAt(APoint: TPoint): TWidget;
var
  i: Integer;
begin
  for i := 0 to ChildCount - 1 do
  begin
    Result := Children[i];
    if PtInRect(Result.BoundsRect, APoint) then
      exit;
  end;
  Result := nil;
end;

function TContainerWidget.DistributeEvent(Event: TEventObj): Boolean;
var
  i: Integer;
begin
  // Propagate the event to all children
  for i := 0 to ChildCount - 1 do
    if Event.SendToChild(Children[i]) then
    begin
      Result := True;
      exit;
    end;
  // The event hasn't been processed by any child:
  Result := inherited DistributeEvent(Event);
end;

procedure TContainerWidget.InsertChild(AChild: TWidget);
begin
  // do nothing
end;

procedure TContainerWidget.RemoveChild(AChild: TWidget);
begin
  // do nothing
end;


{$ENDIF read_implementation}