📄 jvqtooledit.pas
字号:
end;
procedure TJvCustomComboEdit.Loaded;
begin
inherited Loaded;
if FStreamedButtonWidth >= 0 then
begin
SetButtonWidth(FStreamedButtonWidth);
if FStreamedFixedWidth then
with FButton do
ControlStyle := ControlStyle + [csFixedWidth];
end;
UpdateControls;
UpdateMargins;
end;
procedure TJvCustomComboEdit.LocalKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
UpdateGroup;
if Assigned(FOnKeyDown) then
FOnKeyDown(Sender, Key, Shift);
end;
procedure TJvCustomComboEdit.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if (FPopup <> nil) and (Button = mbLeft) then
begin
if CanFocus then
SetFocus;
if not FFocused then
Exit;
if FPopupVisible then
PopupCloseUp(FPopup, False);
{else
if (not ReadOnly or AlwaysEnable) and (not DirectInput) then
PopupDropDown(True);}
end;
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TJvCustomComboEdit.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FImages) then
Images := nil;
end;
procedure TJvCustomComboEdit.Paint;
begin
if Enabled then
inherited Paint
else
begin
if not PaintEdit(Self, Text, Alignment, PopupVisible,
DisabledTextColor, Focused and not PopupVisible, {Flat:}False, Canvas) then
inherited Paint;
end;
end;
procedure TJvCustomComboEdit.PopupChange;
begin
end;
procedure TJvCustomComboEdit.PopupCloseUp(Sender: TObject; Accept: Boolean);
var
AValue: Variant;
begin
if (FPopup <> nil) and FPopupVisible then
begin
if Mouse.Capture <> nil then
Mouse.Capture := nil;
AValue := GetPopupValue;
HidePopup;
try
try
if CanFocus and ParentFormVisible(Self) then
begin
SetFocus;
if GetFocus = Handle then
// SetShowCaret;
end;
except
{ ignore exceptions }
end;
SetDirectInput(DirectInput);
Invalidate;
if Accept and AcceptPopup(AValue) and EditCanModify then
begin
AcceptValue(AValue);
if FFocused then
inherited SelectAll;
end;
finally
FPopupVisible := False;
end;
end;
end;
procedure TJvCustomComboEdit.PopupDropDown(DisableEdit: Boolean);
var
P: TPoint;
Y: Integer;
SR: TJvSizeRect;
begin
if not ((ReadOnly and not FAlwaysShowPopup) or FPopupVisible) then
begin
CreatePopup;
if FPopup = nil then
Exit;
P := Parent.ClientToScreen(Point(Left, Top));
SR.Top := 0; //Screen.Top;
SR.Left := 0; //Screen.Left;
SR.Width := Screen.Width;
SR.Height := Screen.Height;
Y := P.Y + Height;
if Y + FPopup.Height > SR.Top + SR.Height then
Y := P.Y - FPopup.Height;
case FPopupAlign of
epaRight:
begin
Dec(P.X, FPopup.Width - Width);
if P.X < SR.Left then
Inc(P.X, FPopup.Width - Width);
end;
epaLeft:
if P.X + FPopup.Width > SR.Left + SR.Width then
Dec(P.X, FPopup.Width - Width);
end;
if P.X < SR.Left then
P.X := SR.Left
else
if P.X + FPopup.Width > SR.Left + SR.Width then
P.X := SR.Left + SR.Width - FPopup.Width;
if Text <> '' then
SetPopupValue(Text)
else
SetPopupValue(Null);
if CanFocus then
SetFocus;
ShowPopup(Point(P.X, Y));
FPopupVisible := True;
if DisableEdit then
begin
inherited ReadOnly := True;
// HideCaret(Handle);
end;
end;
end;
procedure TJvCustomComboEdit.ReadGlyphKind(Reader: TReader);
const
sEnumValues: array [TGlyphKind] of PChar =
('gkCustom', 'gkDefault', 'gkDropDown', 'gkEllipsis');
var
S: string;
GlyphKind: TGlyphKind;
begin
{ No need to drag in TypInfo.pas }
S := Reader.ReadIdent;
for GlyphKind := Low(TGlyphKind) to High(TGlyphKind) do
if SameText(S, sEnumValues[GlyphKind]) then
begin
ImageKind := TJvImageKind(GlyphKind);
Break;
end;
end;
procedure TJvCustomComboEdit.RecreateGlyph;
var
NewGlyph: TBitmap;
function CreateEllipsisGlyph: TBitmap;
var
W, g, I: Integer;
begin
Result := TBitmap.Create;
with Result do
try
Width := Max(1, FButton.Width - 6);
Height := 4;
W := 2;
g := (Result.Width - 3 * W) div 2;
if g <= 0 then
g := 1;
if g > 3 then
g := 3;
I := (Width - 3 * W - 2 * g) div 2;
Canvas.Start;
PatBlt(Canvas.Handle, I, 1, W, W, BLACKNESS);
PatBlt(Canvas.Handle, I + g + W, 1, W, W, BLACKNESS);
PatBlt(Canvas.Handle, I + 2 * g + 2 * W, 1, W, W, BLACKNESS);
Canvas.Stop;
except
Free;
raise;
end;
end;
begin
{ Delay until button is shown }
if not ShowButton then
Exit;
if FImageKind in [ikDropDown, ikEllipsis] then
begin
FButton.ImageIndex := -1;
FButton.NumGlyphs := 1;
end;
case FImageKind of
ikDropDown:
begin
begin
LoadDefaultBitmap(TJvxButtonGlyph(FButton.ButtonGlyph).Glyph, OBM_COMBO);
FButton.Invalidate;
end;
end;
ikEllipsis:
begin
NewGlyph := CreateEllipsisGlyph;
try
TJvxButtonGlyph(FButton.ButtonGlyph).Glyph := NewGlyph;
FButton.Invalidate;
finally
NewGlyph.Destroy;
end;
end;
else
// TJvxButtonGlyph(FButton.ButtonGlyph).Glyph := nil;
FButton.Invalidate;
end;
end;
procedure TJvCustomComboEdit.SelectAll;
begin
if DirectInput then
inherited SelectAll;
end;
procedure TJvCustomComboEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
UpdateControls;
UpdateMargins;
end;
procedure TJvCustomComboEdit.SetButtonFlat(const Value: Boolean);
begin
FButton.Flat := Value;
end;
procedure TJvCustomComboEdit.SetButtonHint(const Value: string);
begin
FButton.Hint := Value;
end;
procedure TJvCustomComboEdit.SetButtonWidth(Value: Integer);
begin
if csLoading in ComponentState then
begin
FStreamedButtonWidth := Value;
FStreamedFixedWidth := False;
end
else
if not ShowButton then
FSavedButtonWidth := Value
else
if (ButtonWidth <> Value) {or ((Value > 0) <> ShowButton)} then
begin
if Value > 1 then
FBtnControl.Visible := True
else
begin
FSavedButtonWidth := ButtonWidth;
FBtnControl.Visible := False;
end;
if csCreating in ControlState then
begin
FBtnControl.Width := Value;
FButton.Width := Value;
with FButton do
ControlStyle := ControlStyle - [csFixedWidth];
{ Some glyphs are size dependant (ellipses), thus recreate on size changes }
RecreateGlyph;
end
//else
//if (Value <> ButtonWidth) and (Value < ClientWidth) then begin
//Polaris
else
if (Value <> ButtonWidth) and
((Assigned(Parent) and (Value < ClientWidth)) or
(not Assigned(Parent) and (Value < Width))) then
begin
FBtnControl.SetBounds(FBtnControl.Left + FBtnControl.Width - Value,
FBtnControl.Top, Value, FBtnControl.Height);
FButton.Width := Value;
with FButton do
ControlStyle := ControlStyle - [csFixedWidth];
if HandleAllocated then
Invalidate;
{ Some glyphs are size dependant (ellipses), thus recreate on size changes }
RecreateGlyph;
end;
end;
end;
procedure TJvCustomComboEdit.SetDirectInput(Value: Boolean);
begin
inherited ReadOnly := not Value or FReadOnly;
FDirectInput := Value;
end;
procedure TJvCustomComboEdit.SetDisabledColor(const Value: TColor);
begin
if FDisabledColor <> Value then
begin
FDisabledColor := Value;
if not Enabled then
Invalidate;
end;
end;
procedure TJvCustomComboEdit.SetDisabledTextColor(const Value: TColor);
begin
if FDisabledTextColor <> Value then
begin
FDisabledTextColor := Value;
if not Enabled then
Invalidate;
end;
end;
procedure TJvCustomComboEdit.SetGlyph(Value: TBitmap);
begin
ImageKind := ikCustom;
FButton.Glyph := Value;
FNumGlyphs := FButton.NumGlyphs;
end;
procedure TJvCustomComboEdit.SetGlyphKind(Value: TGlyphKind);
begin
ImageKind := TJvImageKind(Value);
end;
procedure TJvCustomComboEdit.SetGroupIndex(const Value: Integer);
begin
FGroupIndex := Value;
UpdateGroup;
end;
procedure TJvCustomComboEdit.SetImageIndex(const Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
if FImageKind = ikCustom then
FButton.ImageIndex := FImageIndex;
end;
end;
procedure TJvCustomComboEdit.SetImageKind(const Value: TJvImageKind);
begin
if FImageKind <> Value then
begin
FImageKind := Value;
RecreateGlyph;
case FImageKind of
ikCustom:
begin
FButton.Images := FImages;
FButton.ImageIndex := FImageIndex;
FButton.NumGlyphs := FNumGlyphs;
end;
ikDefault:
begin
FButton.Images := DefaultImages;
FButton.ImageIndex := DefaultImageIndex;
{ Default glyphs have a default width }
if Assigned(FButton.Images) and (FButton.ImageIndex >= 0) then
ButtonWidth := Max(FButton.Images.Width + 6, FButton.Width)
end;
ikDropDown:
if csLoading in ComponentState then
begin
if (FStreamedButtonWidth < 0) or FStreamedFixedWidth then
begin
ButtonWidth := GetSystemMetrics(SM_CXVSCROLL);
{ Setting ButtonWidth will set FStreamedFixedWidth to False, thus
reapply it. }
FStreamedFixedWidth := True;
end;
end
else
begin
ButtonWidth := GetSystemMetrics(SM_CXVSCROLL);
{ Setting ButtonWidth will remove the csFixedWidth flag, thus
reapply it. }
with FButton do
ControlStyle := ControlStyle + [csFixedWidth];
end;
ikEllipsis: ;
end;
end;
end;
procedure TJvCustomComboEdit.SetImages(const Value: TCustomImageList);
begin
FImages := Value;
if FImages <> nil then
FImages.FreeNotification(Self)
else
SetImageIndex(-1);
if ImageKind = ikCustom then
begin
FButton.Images := FImages;
FButton.ImageIndex := FImageIndex;
end;
end;
procedure TJvCustomComboEdit.SetNumGlyphs(const Value: TNumGlyphs);
begin
//if FGlyphKind in [gkDropDown, gkEll
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -