📄 jvqlookout.pas
字号:
X, Y: Integer);
begin
if Assigned(FEdit) then
begin
if not PtInRect(FEdit.ClientRect, Point(X, Y)) or ((Button = mbRight) and FEdit.Visible) then
begin
if FEdit.Handle = GetCapture then
ReleaseCapture;
Screen.Cursor := crDefault;
FEdit.Hide;
FEdit.Free;
FEdit := nil;
end
else
begin
ReleaseCapture;
Screen.Cursor := crIBeam;
SetCapture(FEdit.Handle);
end;
end;
end;
procedure TJvCustomLookOutButton.Assign(Source: TPersistent);
begin
if Source is TJvCustomLookOutButton then
begin
Offset := TJvCustomLookOutButton(Source).Offset;
Height := TJvCustomLookOutButton(Source).Height;
Width := TJvCustomLookOutButton(Source).Width;
ButtonBorder := TJvCustomLookOutButton(Source).ButtonBorder;
Caption := TJvCustomLookOutButton(Source).Caption;
Centered := TJvCustomLookOutButton(Source).Centered;
Down := TJvCustomLookOutButton(Source).Down;
Font := TJvCustomLookOutButton(Source).Font;
HighlightFont := TJvCustomLookOutButton(Source).HighlightFont;
ParentImageSize := TJvCustomLookOutButton(Source).ParentImageSize;
ImageSize := TJvCustomLookOutButton(Source).ImageSize;
ImageIndex := TJvCustomLookOutButton(Source).ImageIndex;
LargeImages := TJvCustomLookOutButton(Source).LargeImages;
SmallImages := TJvCustomLookOutButton(Source).SmallImages;
Spacing := TJvCustomLookOutButton(Source).Spacing;
end
else
inherited Assign(Source);
end;
function TJvCustomLookOutButton.WantKey(Key: Integer; Shift: TShiftState;
const KeyText: WideString): Boolean;
begin
Result := IsAccel(Key, FCaption) and Enabled and
Visible and ParentVisible and (ssAlt in Shift);
if Result then
Click
else
Result := inherited WantKey(Key, Shift, KeyText);
end;
function TJvCustomLookOutButton.ParentVisible: Boolean;
begin
Result := False;
if Parent = nil then
Exit;
if (Parent is TJvLookOutPage) and (Parent.Parent is TJvLookOut) then
Result := TJvLookOutPage(Parent) = TJvLookOut(Parent.Parent).ActivePage
else
Result := Parent.Visible;
end;
procedure TJvCustomLookOutButton.SetGroupIndex(Value: Integer);
begin
if FGroupIndex <> Value then
begin
FGroupIndex := Value;
UpdateExclusive;
end;
end;
procedure TJvCustomLookOutButton.UpdateExclusive;
var
Msg: TCMButtonPressed;
begin
if (FGroupIndex <> 0) and (Parent <> nil) then
begin
Msg.Msg := CM_BUTTONPRESSED;
Msg.Index := FGroupIndex;
Msg.Control := Self;
Msg.Result := 0;
BroadcastMsg(Parent, Msg);
end;
end;
procedure TJvCustomLookOutButton.SetCentered(Value: Boolean);
begin
if FCentered <> Value then
begin
FCentered := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetDown(Value: Boolean);
begin
if FStayDown <> Value then
begin
FStayDown := Value;
if FStayDown then
begin
MouseOver := True;
FDown := True;
end
else
FDown := False;
if FStayDown then
UpdateExclusive;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetOffset(Value: Integer);
begin
if FOffset <> Value then
FOffset := Value;
end;
procedure TJvCustomLookOutButton.SetCaption(Value: TCaption);
begin
if FCaption <> Value then
begin
FCaption := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetButtonBorder(Value: TJvButtonBorder);
begin
if FButtonBorder <> Value then
begin
FButtonBorder := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetSmallImages(Value: TImageList);
begin
if FSmallImages <> nil then
FSmallImages.UnRegisterChanges(FSmallImageChangeLink);
FSmallImages := Value;
if FSmallImages <> nil then
FSmallImages.RegisterChanges(FSmallImageChangeLink);
Invalidate;
end;
procedure TJvCustomLookOutButton.SetLargeImages(Value: TImageList);
begin
if Assigned(FLargeImages) then
FLargeImages.UnRegisterChanges(FLargeImageChangeLink);
FLargeImages := Value;
if Assigned(FLargeImages) then
FLargeImages.RegisterChanges(FLargeImageChangeLink);
Invalidate;
end;
procedure TJvCustomLookOutButton.SetImageIndex(Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetImageSize(Value: TJvImageSize);
begin
if FImageSize <> Value then
begin
FImageSize := Value;
if csDesigning in ComponentState then
SetParentImageSize(False);
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetFillColor(Value: TColor);
begin
if FFillColor <> Value then
begin
FFillColor := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetHighlightFont(Value: TFont);
begin
FHighlightFont.Assign(Value);
if FHighlightFont <> Font then
Invalidate;
end;
procedure TJvCustomLookOutButton.SetSpacing(Value: Integer);
begin
if FSpacing <> Value then
begin
FSpacing := Value;
Invalidate;
end;
end;
procedure TJvCustomLookOutButton.SetParentImageSize(Value: Boolean);
begin
FParentImageSize := Value;
if FParentImageSize and (Parent is TJvLookOutPage) then
SetImageSize(TJvLookOutPage(Parent).ImageSize);
end;
procedure TJvCustomLookOutButton.Paint;
var
R: TRect;
Flags, H: Integer;
begin
R := GetClientRect;
with Canvas do
begin
if csDesigning in ComponentState then
begin
Brush.Color := clBlack;
FrameRect( Canvas, R);
end;
if (FImageSize = isSmall) and Assigned(FSmallImages) then
begin
FImageRect.Left := FSpacing;
FImageRect.Right := FImageRect.Left + FSmallImages.Width;
FImageRect.Top := (Height - FSmallImages.Height) div 2;
FImageRect.Bottom := FImageRect.Top + FSmallImages.Height;
end
else
if Assigned(FLargeImages) then
begin
FImageRect.Left := (Width - FLargeImages.Width) div 2;
FImageRect.Right := FImageRect.Left + FLargeImages.Width;
FImageRect.Top := FSpacing;
FImageRect.Bottom := FImageRect.Top + FLargeImages.Height;
end;
PaintFrame;
Flags := DT_END_ELLIPSIS ;
if (FImageSize = isSmall) and Assigned(FSmallImages) then
begin
DrawSmallImages;
Flags := Flags or DT_VCENTER or DT_SINGLELINE;
// W := FSmallImages.Width;
end
else
if (FImageSize = isLarge) and Assigned(FLargeImages) then
begin
DrawLargeImages;
// W := FLargeImages.Width;
Flags := Flags or DT_WORDBREAK or DT_CENTER;
end;
end;
{ draw text }
if Length(Caption) > 0 then
begin
if MouseOver then
Canvas.Font := FHighlightFont
else
Canvas.Font := Font;
// W := FSpacing + W;
SetBkMode(Canvas.Handle, QWindows.Transparent);
R := GetClientRect;
if (ImageSize = isLarge) and Assigned(FLargeImages) then
R.Top := R.Top + FLargeImages.Height + (FSpacing * 2)
else
if (ImageSize = isSmall) and Assigned(FSmallImages) then
R.Left := R.Left + FSmallImages.Width + (FSpacing * 3)
else
Flags := DT_END_ELLIPSIS or DT_WORDBREAK or DT_CENTER or DT_VCENTER ;
if FDown then
OffsetRect(R, FOffset, FOffset);
FTextRect := R;
H := DrawText(Canvas, Caption, -1, FTextRect, Flags or DT_CALCRECT);
if ImageSize = isLarge then
begin
FTextRect.Top := R.Top;
FTextRect.Bottom := FTextRect.Top + H;
FTextRect.Right := R.Left + Canvas.TextWidth(Caption);
end
else
begin
FTextRect.Top := (Height - Canvas.TextHeight(Caption)) div 2;
FTextRect.Bottom := FTextRect.Top + Canvas.TextHeight(Caption);
FTextRect.Right := R.Left + Canvas.TextWidth(Caption);
end;
DrawText(Canvas, Caption, -1, R, Flags);
end;
end;
procedure TJvCustomLookOutButton.DrawSmallImages;
begin
if FDown then
OffsetRect(FImageRect, FOffset, FOffset);
FSmallImages.Draw(Canvas, FImageRect.Left, FImageRect.Top, FImageIndex);
end;
procedure TJvCustomLookOutButton.DrawLargeImages;
begin
if FDown then
OffsetRect(FImageRect, FOffset, FOffset);
FLargeImages.Draw(Canvas, FImageRect.Left, FImageRect.Top, FImageIndex);
end;
procedure TJvCustomLookOutButton.PaintFrame;
var
R: TRect;
begin
R := GetClientRect;
if csDesigning in ComponentState then
begin
Canvas.Brush.Color := clBlack;
with Canvas do
FrameRect( Canvas, R);
Canvas.Brush.Color := Color;
end;
if not Enabled then
Exit;
if MouseOver or (csDesigning in ComponentState) then
begin
if (csDesigning in ComponentState) and not Visible then
begin
Canvas.Brush.Style := bsBDiagonal;
QWindows.FillRect(Canvas.Handle, R, Canvas.Brush.Handle);
Canvas.Brush.Style := bsSolid;
end
else
if FFillColor = clNone then
begin
R := FImageRect;
InflateRect(R, Spacing, Spacing);
end
else
begin { fill it up! }
Canvas.Brush.Color := FFillColor;
QWindows.FillRect(Canvas.Handle, R, Canvas.Brush.Handle);
end;
if FDown then
begin
if FButtonBorder = bbDark then
Frame3D(Canvas, R, cl3DDkShadow, clBtnFace, 1)
else
if FButtonBorder = bbLight then
Frame3D(Canvas, R, clBtnShadow, clBtnHighlight, 1)
else
Frame3D(Canvas, R, cl3DDkShadow, clBtnHighlight, 1)
end
else
case FButtonBorder of
bbDark:
Frame3D(Canvas, R, clBtnFace, cl3DDkShadow, 1);
bbLight:
Frame3D(Canvas, R, clBtnHighlight, clBtnShadow, 1);
else
Frame3D(Canvas, R, clBtnHighlight, cl3DDkShadow, 1);
end;
end;
end;
procedure TJvCustomLookOutButton.ImageListChange(Sender: TObject);
begin
Invalidate;
end;
procedure TJvCustomLookOutButton.CMParentImageSizeChanged(var Msg: TMessage);
var
FTmp: Boolean;
begin
if (Msg.LParam <> Longint(Self)) and FParentImageSize then
begin
FTmp := FParentImageSize;
SetImageSize(TJvImageSize(Msg.WParam));
FParentImageSize := FTmp;
end;
end;
procedure TJvCustomLookOutButton.CMButtonPressed(var Msg: TCMButtonPressed);
var
Sender: TJvCustomLookOutButton;
begin
if Msg.Index = FGroupIndex then
begin
Sender := TJvCustomLookOutButton(Msg.Control);
if Sender <> Self then
begin
if Sender.Down and FDown then
begin
FStayDown := False;
FDown := False;
MouseOver := False;
Invalidate;
end;
end;
end;
end;
procedure TJvCustomLookOutButton.MouseEnter(Control: TControl);
begin
if csDesigning in ComponentState then
Exit;
if not MouseOver then
begin
if FFillColor = clNone then
PaintFrame
else
Invalidate;
end;
inherited MouseEnter(Control);
end;
procedure TJvCustomLookOutButton.MouseLeave(Control: TControl);
begin
if MouseOver then
begin
if not FStayDown then
Invalidate;
end;
inherited MouseLeave(Control);
end;
procedure TJvCustomLookOutButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Tmp: TPoint;
begin
if Parent is TJvLookOutPage then
TJvLookOutPage(Parent).ActiveButton := Self;
inherited MouseDown(Button, Shift, X, Y);
if Button = mbRight then
begin
if Assigned(FPopUpMenu) then
begin
{ calc where to put menu }
Tmp := ClientToScreen(Point(X, Y));
FPopUpMenu.PopupComponent := Self;
FPopUpMenu.Popup(Tmp.X, Tmp.Y);
{ wait 'til menu is Done }
// TODO
repeat
Application.ProcessMessages;
until not QWidget_isVisible(FPopUpMenu.Handle);
end;
{ release button }
if not FStayDown then
FDown := False;
end
else
if MouseOver and (Button = mbLeft) then
FDown := True
else
if not FStayDown then
FDown := False;
if FGroupIndex <> 0 then
SetDown(not FStayDown);
if FOffset = 0 then
PaintFrame
else
Invalidate;
// Parent.Update;
end;
procedure TJvCustomLookOutButton.MouseMove(Shift: TShiftState; X, Y: Integer);
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -