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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
{%MainUnit ../stdctrls.pp}
{******************************************************************************
TCustomStaticText
******************************************************************************
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{------------------------------------------------------------------------------
Method: TCustomStaticText.Create
Params: AOwner: the owner of the class
Returns: Nothing
Constructor for the class.
------------------------------------------------------------------------------}
constructor TCustomStaticText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCompStyle := csStaticText;
fAlignment := taLeftJustify;
FShowAccelChar:= true;
FStaticBorderStyle:=sbsNone;
ControlStyle := ControlStyle + [csReplicatable];
Transparent := True;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.GetLabelText
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
function TCustomStaticText.GetLabelText: String;
begin
Result := Caption;
end;
procedure TCustomStaticText.RealSetText(const AValue: TCaption);
begin
if Text=AValue then exit;
inherited RealSetText(AValue);
InvalidatePreferredSize;
AdjustSize;
end;
{------------------------------------------------------------------------------
procedure TCustomStaticText.Notification(AComponent: TComponent;
Operation: TOperation);
------------------------------------------------------------------------------}
procedure TCustomStaticText.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = FFocusControl) and (Operation = opRemove) then
FFocusControl:= nil;
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.SetAlignment
Params: Value - new proterty value
Returns: Nothing
------------------------------------------------------------------------------}
procedure TCustomStaticText.SetAlignment(Value: TAlignment);
begin
if fAlignment <> value then begin
fAlignment:= value;
if HandleAllocated then
TWSCustomStaticTextClass(WidgetSetClass).SetAlignment(Self, Value);
end;
end;
function TCustomStaticText.GetTransparent: Boolean;
begin
Result := not (csOpaque in ControlStyle);
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.SetFocusControl
Params: Val - new property value
Returns: Nothing
------------------------------------------------------------------------------}
procedure TCustomStaticText.SetFocusControl(Val: TWinControl);
begin
if Val <> FFocusControl then
begin
if FFocusControl <> nil then
FFocusControl.RemoveFreeNotification(Self);
FFocusControl := Val;
if Val <> nil then
Val.FreeNotification(Self);
end;
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.SetShowAccelChar
Params: Val - new property value
Returns: Nothing
------------------------------------------------------------------------------}
procedure TCustomStaticText.SetShowAccelChar(Val: boolean);
begin
if Val <> FShowAccelChar then begin
FShowAccelChar:= Val;
if HandleAllocated then begin
TWSWinControlClass(WidgetSetClass).SetText(Self,Caption);
InvalidatePreferredSize;
end;
end;
end;
function TCustomStaticText.DialogChar(var Message: TLMKey): boolean;
begin
if IsAccel(Message.CharCode, Caption)
and (FFocusControl <> nil) and (FFocusControl.CanFocus) then
begin
FFocusControl.SetFocus;
Result := true;
end else
Result := inherited;
end;
class function TCustomStaticText.GetControlClassDefaultSize: TSize;
begin
Result.CX := 65;
Result.CY := 17;
end;
procedure TCustomStaticText.SetStaticBorderStyle(Value : TStaticBorderStyle);
begin
if FStaticBorderStyle <> Value then
begin
FStaticBorderStyle := Value;
if HandleAllocated then
begin
TWSCustomStaticTextClass(WidgetsetClass).SetStaticBorderStyle(Self, Value);
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
end;
end;
end;
procedure TCustomStaticText.SetTransparent(const AValue: Boolean);
begin
if Transparent = AValue then
Exit;
if AValue then
ControlStyle := ControlStyle - [csOpaque]
else
ControlStyle := ControlStyle + [csOpaque];
Invalidate;
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.WMActivate
Params: Message: Activation message
Returns: Nothing
Received when the label has a registered activation shortcut for focuscontrol.
------------------------------------------------------------------------------}
procedure TCustomStaticText.WMActivate(var Message: TLMActivate);
begin
if (FFocusControl <> nil) and (FFocusControl.CanFocus) then
FFocusControl.SetFocus;
end;
class procedure TCustomStaticText.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterCustomStaticText;
end;
// included by stdctrls.pp
|