📄 jvcomctrls.pas
字号:
WM_CREATE:
if (FEditControlCount <= Length(FEditControls)) and
(FEditControls[FEditControlCount] <> nil) then
begin
FEditControls[FEditControlCount].Handle := ChildWnd;
EnableWindow(ChildWnd, Enabled and not (csDesigning in ComponentState));
Inc(FEditControlCount);
end;
WM_DESTROY:
ClearEditControls;
// (p3) this code prevents the user from dblclicking on any edit field
// to select it (the first edit is always selected). I don't know if removing
// it has any side-effects but I haven't noticed anything
// WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN:
// Perform(Event, Value, Integer(SmallPoint(XPos, YPos)));
end;
inherited;
end;
procedure TJvIPAddress.WMSetFont(var Msg: TWMSetFont);
var
LF: TLogFont;
begin
FillChar(LF, SizeOf(TLogFont), #0);
try
OSCheck(GetObject(Font.Handle, SizeOf(LF), @LF) > 0);
DestroyLocalFont;
FLocalFont := CreateFontIndirect(LF);
Msg.Font := FLocalFont;
inherited;
except
Application.HandleException(Self);
end;
end;
{$ENDIF VCL}
//=== { TJvTabControlPainter } ===============================================
destructor TJvTabControlPainter.Destroy;
begin
if FClients <> nil then
while FClients.Count > 0 do
UnRegisterChange(TCustomTabControl(FClients.Last));
FreeAndNil(FClients);
inherited Destroy;
end;
procedure TJvTabControlPainter.Change;
var
I: Integer;
begin
if FClients <> nil then
for I := 0 to FClients.Count - 1 do
TCustomTabControl(FClients[I]).Invalidate;
end;
procedure TJvTabControlPainter.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent is TCustomTabControl) and (FClients <> nil) then
FClients.Remove(AComponent);
end;
procedure TJvTabControlPainter.RegisterChange(AControl: TCustomTabControl);
begin
if FClients = nil then
FClients := TList.Create;
if AControl <> nil then
begin
FClients.Add(AControl);
AControl.FreeNotification(Self);
AControl.Invalidate;
end;
end;
procedure TJvTabControlPainter.UnRegisterChange(AControl: TCustomTabControl);
begin
if FClients <> nil then
begin
FClients.Remove(AControl);
if (AControl <> nil) and not (csDestroying in AControl.ComponentState) then
AControl.Invalidate;
end;
end;
//=== { TJvTabDefaultPainter } ===============================================
constructor TJvTabDefaultPainter.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActiveFont := TFont.Create;
if Owner is TForm then
FActiveFont.Assign(TForm(Owner).Font)
else
{$IFDEF VCL}
FActiveFont.Assign(Screen.IconFont);
{$ENDIF VCL}
{$IFDEF VisualCLX}
FActiveFont.Assign(Screen.HintFont);
{$ENDIF VisualCLX}
FActiveFont.Color := clHighlight;
FActiveFont.OnChange := DoFontChange;
FActiveColorFrom := clWhite;
FActiveColorTo := clBtnFace;
FActiveGradientDirection := fdTopToBottom;
FDisabledFont := TFont.Create;
if Owner is TForm then
FDisabledFont.Assign(TForm(Owner).Font)
else
{$IFDEF VCL}
FDisabledFont.Assign(Screen.IconFont);
{$ENDIF VCL}
{$IFDEF VisualCLX}
FDisabledFont.Assign(Screen.HintFont);
{$ENDIF VisualCLX}
FDisabledFont.Color := clGrayText;
FDisabledFont.OnChange := DoFontChange;
FDisabledColorFrom := clBtnFace;
FDisabledColorTo := clBtnFace;
FDisabledGradientDirection := fdTopToBottom;
FInactiveFont := TFont.Create;
if Owner is TForm then
FInactiveFont.Assign(TForm(Owner).Font)
else
{$IFDEF VCL}
FInactiveFont.Assign(Screen.IconFont);
{$ENDIF VCL}
{$IFDEF VisualCLX}
FInactiveFont.Assign(Screen.HintFont);
{$ENDIF VisualCLX}
FInactiveFont.OnChange := DoFontChange;
FInactiveColorFrom := JvDefaultInactiveColorFrom;
FInactiveColorTo := JvDefaultInactiveColorTo;
FInactiveGradientDirection := fdTopToBottom;
FGlyphLayout := blGlyphLeft;
end;
destructor TJvTabDefaultPainter.Destroy;
begin
FActiveFont.Free;
FDisabledFont.Free;
FInactiveFont.Free;
inherited Destroy;
end;
procedure TJvTabDefaultPainter.DoFontChange(Sender: TObject);
begin
Change;
end;
procedure TJvTabDefaultPainter.DrawTab(AControl: TCustomTabControl;
Canvas: TCanvas; Images: TCustomImageList; ImageIndex: Integer;
const Caption: string; const Rect: TRect; Active, Enabled: Boolean);
var
TextRect, ImageRect: TRect;
SaveState: Integer;
procedure DrawDivider(X, Y, X1, Y1: Integer);
begin
Canvas.Pen.Color := clBtnShadow;
Canvas.MoveTo(X, Y);
Canvas.LineTo(X1, Y1);
Canvas.Pen.Color := clHighlightText;
Canvas.MoveTo(X + 1, Y + 1);
Canvas.LineTo(X1 + 1, Y1 + 1);
end;
begin
TextRect := Rect;
ImageRect := Rect;
if not Enabled then
begin
GradientFillRect(Canvas, TextRect, DisabledColorFrom, DisabledColorTo, DisabledGradientDirection, 255);
Canvas.Font := DisabledFont;
end
else
if Active then
begin
GradientFillRect(Canvas, TextRect, ActiveColorFrom, ActiveColorTo, ActiveGradientDirection, 255);
Canvas.Font := ActiveFont;
end
else
begin
GradientFillRect(Canvas, TextRect, InactiveColorFrom, InactiveColorTo, InactiveGradientDirection, 255);
Canvas.Font := InactiveFont;
end;
if Assigned(Images) and (ImageIndex >= 0) and (ImageIndex < Images.Count) then
begin // GlyphLayout is only used if we have images
case GlyphLayout of
blGlyphLeft:
begin
Inc(ImageRect.Left, 4);
ImageRect.Right := ImageRect.Left + Images.Width + 4;
TextRect.Left := ImageRect.Right;
end;
blGlyphRight:
begin
Dec(ImageRect.Right, 4);
ImageRect.Left := ImageRect.Right - Images.Width - 4;
TextRect.Right := ImageRect.Left;
end;
blGlyphTop:
begin
Dec(ImageRect.Bottom, RectHeight(Rect) div 2);
TextRect.Top := ImageRect.Bottom;
if Divider and (Caption <> '') then
DrawDivider(Rect.Left + 4 + Ord(Active), Rect.Top + RectHeight(Rect) div 2, Rect.Right - 4 - Ord(Active), Rect.Top + RectHeight(Rect) div 2);
end;
blGlyphBottom:
begin
Inc(ImageRect.Top, RectHeight(Rect) div 2);
TextRect.Bottom := ImageRect.Top;
if Divider and (Caption <> '') then
DrawDivider(Rect.Left + 4 + Ord(Active), Rect.Top + RectHeight(Rect) div 2, Rect.Right - 4 - Ord(Active), Rect.Top + RectHeight(Rect) div 2);
end;
end;
InflateRect(ImageRect, -(RectWidth(ImageRect) - Images.Width) div 2, -(RectHeight(ImageRect) - Images.Height) div 2);
SaveState := SaveDC(Canvas.Handle);
try
Images.Draw(Canvas, ImageRect.Left, ImageRect.Top, ImageIndex,
{$IFDEF VisualCLX}
itImage,
{$ENDIF VisualCLX}
Enabled);
finally
RestoreDC(Canvas.Handle, SaveState);
end;
end;
if Caption <> '' then
begin
// InflateRect(TextRect, -2, -2);
SetBkMode(Canvas.Handle, TRANSPARENT);
DrawText(Canvas, Caption, Length(Caption), TextRect, DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end;
if Active and ShowFocus then
begin
TextRect := Rect;
InflateRect(TextRect, -3, -3);
Canvas.DrawFocusRect(TextRect);
end;
end;
procedure TJvTabDefaultPainter.SetActiveColorFrom(const Value: TColor);
begin
if FActiveColorFrom <> Value then
begin
FActiveColorFrom := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetActiveFont(const Value: TFont);
begin
FActiveFont.Assign(Value);
end;
procedure TJvTabDefaultPainter.SetActiveColorTo(const Value: TColor);
begin
if FActiveColorTo <> Value then
begin
FActiveColorTo := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetActiveGradientDirection(
const Value: TFillDirection);
begin
if FActiveGradientDirection <> Value then
begin
FActiveGradientDirection := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetDisabledColorFrom(const Value: TColor);
begin
if FDisabledColorFrom <> Value then
begin
FDisabledColorFrom := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetDisabledColorTo(const Value: TColor);
begin
if FDisabledColorTo <> Value then
begin
FDisabledColorTo := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetDisabledFont(const Value: TFont);
begin
FDisabledFont.Assign(Value);
end;
procedure TJvTabDefaultPainter.SetDisabledGradientDirection(
const Value: TFillDirection);
begin
if FDisabledGradientDirection <> Value then
begin
FDisabledGradientDirection := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetInactiveColorFrom(const Value: TColor);
begin
if FInactiveColorFrom <> Value then
begin
FInactiveColorFrom := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetInactiveColorTo(const Value: TColor);
begin
if FInactiveColorTo <> Value then
begin
FInactiveColorTo := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetInactiveFont(const Value: TFont);
begin
FInactiveFont.Assign(Value);
end;
procedure TJvTabDefaultPainter.SetInactiveGradientDirection(const Value: TFillDirection);
begin
if FInactiveGradientDirection <> Value then
begin
FInactiveGradientDirection := Value;
Change;
end;
end;
function TJvTabDefaultPainter.IsActiveFontStored: Boolean;
begin
Result := True;
end;
function TJvTabDefaultPainter.IsDisabledFontStored: Boolean;
begin
Result := True;
end;
function TJvTabDefaultPainter.IsInactiveFontStored: Boolean;
begin
Result := True;
end;
procedure TJvTabDefaultPainter.SetGlyphLayout(const Value: TButtonLayout);
begin
if FGlyphLayout <> Value then
begin
FGlyphLayout := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetDivider(const Value: Boolean);
begin
if FDivider <> Value then
begin
FDivider := Value;
Change;
end;
end;
procedure TJvTabDefaultPainter.SetShowFocus(const Value: Boolean);
begin
if FShowFocus <> Value then
begin
FShowFocus := Value;
Change;
end;
end;
//=== { TJvTabControl } ======================================================
constructor TJvTabControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF VisualCLX}
InputKeys := [ikTabs];
{$ENDIF VisualCLX}
end;
{$IFDEF VCL}
procedure TJvTabControl.CMDialogKey(var Msg: TWMKey);
begin
if (Msg.CharCode = VK_TAB) and (GetKeyState(VK_CONTROL) < 0) and
IsChild(Handle, Windows.GetFocus) then
begin
if GetKeyState(VK_SHIFT) < 0 then
begin
if TabIndex = 0 then
TabIndex := Tabs.Count - 1
else
TabIndex := TabIndex - 1;
end
else
TabIndex := (TabIndex + 1) mod Tabs.Count;
Msg.Result := 1;
end
else
inherited;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -