📄 wwradiobutton.pas
字号:
else AnyClickToggles:= False;
TabStop:= False;
if (not IsInGrid(self.parent)) or (AnyClickToggles) then inherited
else begin
ComputeImageRect(r);
InflateRect(r, 3, 3);
if PtInRect(r, Point(Message.xpos,Message.ypos)) then
inherited
else
if CanFocus then SetFocus;
end
end;
procedure TwwCustomRadioButton.WMLButtonUp(var Message: TWMLButtonUp);
//var r: TRect;
begin
inherited;
// Problem of background
// not getting cleared when click on radiobutton
// if IsTransparentEffective then Parent.invalidate;
{ if not IsInGrid(self.parent) then SetChecked(not Checked)
else begin
ComputeGlyphRect(r);
InflateRect(r, 3, 3);
if PtInRect(r, Point(Message.xpos,Message.ypos)) then
SetChecked(not Checked);
end}
end;
procedure TwwCustomRadioButton.BMSetCheck(var Message: TMessage);
var origstyle: longint;
r: Trect;
begin
inherited;
if IsTransparentEffective then
begin
OrigStyle:= Windows.GetWindowLong(Parent.handle, GWL_EXSTYLE);
if (OrigStyle and WS_EX_TRANSPARENT)<>0 then
begin
if Focused and ShowFocusRect then
TransparentInvalidate([wwtrText, wwtrIcon])
else
TransparentInvalidate([wwtrIcon]);
end
else begin
r:= BoundsRect;
InvalidateRect(Parent.handle, @r, True);
end;
end;
invalidate;
end;
procedure TwwCustomRadioButton.PaintBorder;
begin
if HandleAllocated then
begin
if not Frame.Enabled then exit;
Frame.Ncpaint(Focused, AlwaysTransparent);
end;
end;
procedure TwwCustomRadioButton.WMKillFocus(var Message: TWMKillFocus);
var r: TRect;
OrigStyle: longint;
Regions: TwwTransparentRegions;
begin
inherited;
if IsTransparentEffective then
begin
OrigStyle:= Windows.GetWindowLong(Parent.handle, GWL_EXSTYLE);
if (OrigStyle and WS_EX_TRANSPARENT)<>0 then
begin
Regions:= [wwtrIcon];
if ShowFocusRect then Regions:= Regions + [wwtrText];
if Frame.IsFrameEffective then Regions:= Regions + [wwtrBorder];
TransparentInvalidate(Regions);
end
else begin
r:= BoundsRect;
InvalidateRect(Parent.handle, @r, True);
end;
end;
invalidate;
end;
procedure TwwCustomRadioButton.WMSetFocus(var Message: TWMSetFocus);
var r: TRect;
begin
inherited;
SpaceKeyPressed:=False;
if IsTransparentEffective and AlwaysTransparent then
begin
r:= BoundsRect;
InvalidateRect(Parent.handle, @r, False);
end;
invalidate;
end;
constructor TwwCustomRadioButton.Create(AOwner: TComponent);
begin
inherited;
FFrame:= TwwEditFrame.create(self);
// FIndentX:=0;
// FIndentY:=0;
FIndents:= TwwWinButtonIndents.create(self);
FValueChecked:= 'True';
FValueUnchecked:= 'False';
FShowFocusRect:= True;
TabStop:= False;
end;
function TwwCustomRadioButton.isTransparentEffective: boolean;
begin
result:= Frame.Transparent and Frame.IsFrameEffective
end;
{procedure TwwCustomRadioButton.SetIndentX(Value: integer);
begin
FIndentX:= Value;
invalidate;
end;
procedure TwwCustomRadioButton.SetIndentY(Value: integer);
begin
FIndentY:= Value;
invalidate;
end;
}
Function TwwCustomRadioButton.IsMouseInControl: boolean;
var p: TPoint;
AHandle: HWND;
begin
GetCursorPos(p);
p:= ScreenToClient(p);
p.x:= p.x + Left;
p.y:= p.y + Top;
AHandle := ChildWindowFromPoint(Parent.Handle, p);
result:= FindControl(AHandle) = self;
end;
procedure TwwCustomRadioButton.WMMouseMove(var Message: TWMMouseMove);
begin
inherited;
end;
procedure TwwCustomRadioButton.CMTextChanged(var Message: TMessage);
begin
if IsTransparentEffective and
((not Focused) or AlwaysTransparent) then
Frame.RefreshTransparentText(False, False);
inherited;
end;
procedure TwwCustomRadioButton.KeyUp(var Key: Word; Shift: TShiftState);
begin
inherited;
if key=vk_space then SpaceKeyPressed:=False;
end;
procedure TwwCustomRadioButton.CNKeyDown(var Message: TWMKeyDown);
begin
if not (csDesigning in ComponentState) then
begin
with Message do
if (charcode = VK_SPACE) then SpaceKeyPressed:=True;
end;
inherited;
end;
procedure TwwCustomRadioButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = Images then Images := nil;
end;
end;
procedure TwwCustomRadioButton.CNCommand(var Message: TWMCommand);
begin
inherited;
// Handle toggling ourselves instead of control
// as when control is in inspector it does not work otherwise
// Therefore we do not call inherited CNCommand
end;
Function TwwCustomRadioButton.GetCanvas: TCanvas;
begin
{ if Focused and (FPaintBitmap<>nil) then
result:= FPaintCanvas
else}
result:= FCanvas;
end;
procedure TwwCustomRadioButton.DoMouseEnter;
begin
try
If Assigned( FOnMouseEnter ) Then FOnMouseEnter( self );
except
exit;
end;
if wwUseThemes(self.parent) then
begin
Invalidate;
end;
if Frame.IsFrameEffective and (not Focused) and
Frame.MouseEnterSameAsFocus then
wwDrawEdge(self, Frame, Canvas, True);
end;
procedure TwwCustomRadioButton.DoMouseLeave;
var
// r: TRect;
// OrigStyle: longint;
Regions: TwwTransparentRegions;
begin
try
If Assigned( FOnMouseLeave ) Then FOnMouseLeave( self );
except
exit;
end;
if wwUseThemes(self.parent) then
begin
Invalidate;
end;
if Frame.IsFrameEffective and Frame.MouseEnterSameAsFocus then
begin
if Focused then exit; //5/24/2001 - PYW - Don't invalidate if focused.
Frame.RefreshTransparentText(False, False);
Invalidate;
if Frame.Transparent then begin
Regions:= [wwtrBorder, wwtrIcon];
TransparentInvalidate(Regions);
end
end;
end;
procedure TwwCustomRadioButton.CMMouseEnter(var Message: TMessage);
begin
inherited;
DoMouseEnter;
end;
procedure TwwCustomRadioButton.CMMouseLeave(var Message: TMessage);
var r:TRect;
pt:TPoint;
begin
GetCursorPos(pt);
pt := ScreenToClient(pt);
r := ClientRect;
if (PtInRect(r,pt)) then exit;
inherited;
DoMouseLeave;
end;
{procedure TwwCustomRadioButton.SetIndentTextX(Value: integer);
begin
FIndentTextX:= Value;
invalidate;
end;
procedure TwwCustomRadioButton.SetIndentTextY(Value: integer);
begin
FIndentTextY:= Value;
invalidate;
end;
}
procedure TwwWinButtonIndents.SetIndentBX(Value: integer);
begin
FIndentBX:= Value;
if FWinControl<>nil then Repaint(FWinControl);
end;
procedure TwwWinButtonIndents.SetIndentBY(Value: integer);
begin
FIndentBY:= Value;
if FWinControl<>nil then Repaint(FWinControl);
end;
procedure TwwWinButtonIndents.SetIndentTX(Value: integer);
begin
FIndentTX:= Value;
if FWinControl<>nil then Repaint(FWinControl);
end;
procedure TwwWinButtonIndents.SetIndentTY(Value: integer);
begin
FIndentTY:= Value;
if FWinControl<>nil then Repaint(FWinControl);
end;
procedure TwwWinButtonIndents.Repaint(FWinControl: TWinControl);
begin
if FWinControl<>nil then FWinControl.Invalidate;
end;
constructor TwwWinButtonIndents.Create(AOwner: TComponent);
begin
if AOwner is TWinControl then
FWinControl:= TWinControl(AOwner)
end;
procedure TwwWinButtonIndents.Assign(Source: TPersistent);
begin
if Source is TwwWinButtonIndents then with TwwWinButtonIndents(Source) do
begin
self.ButtonX:= ButtonX;
self.ButtonY:= ButtonY;
self.TextX:= TextX;
self.TextY:= TextY;
end
else inherited Assign(Source);
end;
function TwwCustomRadioButton.GetButtonIndex: integer;
begin
result:=0;
end;
function TwwCustomRadioButton.GetLastBrushColor: TColor;
begin
result:= clNone;
end;
function TwwCustomRadioButton.GetPaintCopyTextColor: TColor;
begin
result:= clNone;
end;
procedure TwwCustomRadioButton.TransparentInvalidate(Regions: TwwTransparentRegions);
var r,r2: TRect;
begin
if not HandleAllocated then exit;
if (wwtrText in Regions) then begin
ComputeTextRect(r);
MapWindowPoints(Handle, GetParent(Parent.Handle), r, 2);
InflateRect(r,2,2);
InvalidateRect(GetParent(Parent.handle), @r, False);
end;
if (wwtrIcon in Regions) and (Images<>nil) then begin
ComputeImageRect(r);
MapWindowPoints(Handle, GetParent(Parent.Handle), r, 2);
InvalidateRect(GetParent(Parent.handle), @r, False);
end;
if (wwtrBorder in Regions) then
begin
r:= BoundsRect;
r.Top:= r.Top + Parent.Top;
r.Left:= r.Left + Parent.Left;
r.Bottom:= r.Bottom + Parent.Top;
r.Right:= r.Right + Parent.Left;
r2:= Rect(r.left+2,r.top+2,r.right-2,r.bottom-2);
ValidateRect(GetParent(Parent.handle),@r2);
InvalidateRect(GetParent(Parent.handle), @r, False);
end;
{ r:= BoundsRect;
r.Top:= r.Top + Parent.Top;
r.Left:= r.Left + Parent.Left;
r.Bottom:= r.Bottom + Parent.Top;
r.Right:= r.Right + Parent.Left;
InvalidateRect(GetParent(Parent.handle), @r, False);
}
end;
function TwwCustomRadioButton.GetShowText: boolean;
begin
result:= True;
end;
procedure TwwCustomRadioButton.SetChecked(Value: Boolean);
begin
inherited;
// inherited makes radiobutton a tabstop.
// We do not wish to do this, as it causes problems when
// tabbing away from radiogroup
if (parent is TwwCustomRadioGroup) then TabStop:= False;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -