📄 jvqspeedbar.pas
字号:
procedure BoundsChanged; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AssignSpeedItem(Item: TJvSpeedItem);
procedure Activate(Rect: TRect);
procedure ReleaseHandle;
property Alignment: TAlignment read GetAlignment write SetAlignment;
property Caption: TCaption read GetCaption write SetCaption;
property Glyph: TBitmap read GetGlyph write SetGlyph;
property NumGlyphs: TJvNumGlyphs read GetNumGlyphs write SetNumGlyphs;
property Spacing: Integer read FSpacing write FSpacing;
property ImageIndex: Integer read FImageIndex write FImageIndex;
property Images: TImageList read FImages write FImages;
property Margin: Integer read FMargin write FMargin;
property Layout: TButtonLayout read FLayout write FLayout;
property WordWrap: Boolean read GetWordWrap write SetWordWrap;
property Font;
end;
{ Utility routines for SpeedBar Editors }
function FindSpeedBar(const Pos: TPoint): TJvSpeedBar;
procedure DrawCellButton(Grid: TDrawGrid; R: TRect; Item: TJvSpeedItem;
Image: TJvButtonImage; ARightToLeft: Boolean = False);
function NewSpeedSection(ASpeedBar: TJvSpeedBar; const ACaption: string): Integer;
function NewSpeedItem(AOwner: TComponent; ASpeedBar: TJvSpeedBar; Section: Integer;
const AName: string): TJvSpeedItem;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Math, QConsts,
JvQJVCLUtils, JvQJCLUtils, JvQSpeedbarSetupForm, JvQResources;
const
DefaultButtonSize: TPoint = (X: DefButtonWidth; Y: DefButtonHeight);
DragFrameWidth = 3;
StartDragOffset = 4;
// (rom) changed to var
var
Registered: Boolean = False;
const
Alignments: array [TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
// (rom) moved here to make JvMaxMin obsolete
procedure SwapInt(var Int1, Int2: Integer);
var
I: Integer;
begin
I := Int1;
Int1 := Int2;
Int2 := I;
end;
//=== { TJvSpeedBarSection } =================================================
constructor TJvSpeedBarSection.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FList := TList.Create;
FTitle := '';
end;
destructor TJvSpeedBarSection.Destroy;
begin
Clear;
if FParent <> nil then
FParent.DeleteSection(Index);
FList.Free;
inherited Destroy;
end;
procedure TJvSpeedBarSection.Clear;
begin
while FList.Count > 0 do
begin
TJvSpeedItem(FList[0]).Free;
FList.Delete(0);
end;
end;
function TJvSpeedBarSection.Get(Index: Integer): TJvSpeedItem;
begin
Result := TJvSpeedItem(FList[Index]);
end;
procedure TJvSpeedBarSection.Put(Index: Integer; Item: TJvSpeedItem);
begin
FList[Index] := Item;
end;
function TJvSpeedBarSection.GetCount: Integer;
begin
Result := FList.Count;
end;
function TJvSpeedBarSection.GetIndex: Integer;
begin
if FParent <> nil then
Result := FParent.FSections.IndexOf(Self)
else
Result := -1;
end;
procedure TJvSpeedBarSection.SetIndex(Value: Integer);
var
CurIndex, Count: Integer;
begin
CurIndex := GetIndex;
if CurIndex >= 0 then
begin
Count := FParent.FSections.Count;
if Value < 0 then
Value := 0;
if Value >= Count then
Value := Count - 1;
if Value <> CurIndex then
begin
FParent.FSections.Delete(CurIndex);
FParent.FSections.Insert(Value, Self);
end;
end;
end;
function TJvSpeedBarSection.HasParent: Boolean;
begin
Result := True;
end;
procedure TJvSpeedBarSection.SetSpeedBar(Value: TJvSpeedBar);
var
CurIndex: Integer;
begin
CurIndex := GetIndex;
if FParent <> nil then
FParent.DeleteSection(Index);
if Value <> nil then
Value.AppendSection(Self);
if CurIndex >= 0 then
Index := CurIndex;
end;
function TJvSpeedBarSection.GetParentComponent: TComponent;
begin
Result := FParent;
end;
procedure TJvSpeedBarSection.SetParentComponent(Value: TComponent);
begin
SpeedBar := Value as TJvSpeedBar;
end;
procedure TJvSpeedBarSection.RemoveItem(Item: TJvSpeedItem);
var
I: Integer;
begin
I := FList.IndexOf(Item);
if I >= 0 then
begin
Item.FButton.Parent := nil;
Item.FParent := nil;
Item.FSection := -1;
FList.Delete(I);
end;
end;
procedure TJvSpeedBarSection.ValidateCaption(const NewCaption: string);
var
I: Integer;
begin
if FParent <> nil then
begin
I := FParent.SearchSection(NewCaption);
if (I <> Index) and (I >= 0) then
raise EJvSpeedbarError.CreateRes(@SDuplicateString);
end;
end;
procedure TJvSpeedBarSection.SetTitle(const Value: string);
begin
if not (csLoading in ComponentState) then
ValidateCaption(Value);
FTitle := Value;
end;
function TJvSpeedBarSection.GetTitle: string;
begin
Result := FTitle;
end;
//=== { TJvSpeedBarButton } ==================================================
type
TJvSpeedBarButton = class(TJvSpeedButton)
private
FItem: TJvSpeedItem;
FBtn: TJvBtnControl;
procedure InvalidateGlyph;
protected
procedure VisibleChanged; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure PaintImage(Canvas: TCanvas; ARect: TRect; const Offset: TPoint;
AState: TJvButtonState; DrawMark: Boolean); override;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
end;
constructor TJvSpeedBarButton.Create(AOwner: TComponent);
begin
FItem := TJvSpeedItem(AOwner);
{ Ensure FItem is assigned before inherited Create }
inherited Create(AOwner);
Visible := False;
Style := bsNew;
ParentShowHint := True;
ParentFont := True;
end;
destructor TJvSpeedBarButton.Destroy;
begin
FBtn.Free;
inherited Destroy;
end;
procedure TJvSpeedBarButton.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
if FItem.SpeedBar <> nil then
begin
case FItem.SpeedBar.Orientation of
boHorizontal:
ATop := Max(FItem.SpeedBar.FOffset.Y, ATop);
boVertical:
ALeft := Max(FItem.SpeedBar.FOffset.X, ALeft);
end;
end;
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
end;
procedure TJvSpeedBarButton.VisibleChanged;
begin
if Visible then
begin
ControlStyle := ControlStyle - [csNoDesignVisible];
Invalidate;
end
else
ControlStyle := ControlStyle + [csNoDesignVisible];
inherited;
end;
procedure TJvSpeedBarButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
P: TPoint;
begin
if FItem.FEditing and Visible and (Button = mbLeft) and
(FItem.SpeedBar <> nil) then
begin
P := ClientToScreen(Point(FItem.SpeedBar.BtnWidth {div 2},
FItem.SpeedBar.BtnHeight {div 2}));
if FBtn = nil then
begin
Mouse.CursorPos := P;
FBtn := TJvBtnControl.Create(Self);
FBtn.AssignSpeedItem(FItem);
end;
BringToFront;
end
else
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TJvSpeedBarButton.MouseMove(Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
R: TRect;
begin
if FItem.FEditing and (FBtn <> nil) then
begin
P := ClientToScreen(Point(X - (FBtn.Width {div 2}),
Y - (FBtn.Height {div 2})));
X := P.X;
Y := P.Y;
if FItem.SpeedBar <> nil then
begin
Visible := False;
if csDesigning in ComponentState then
begin
R := BoundsRect;
InvalidateRect(FItem.SpeedBar.Handle, @R, True);
end;
P := FItem.SpeedBar.ScreenToClient(P);
if PtInRect(FItem.SpeedBar.ClientRect, P) then
begin
FBtn.Activate(Bounds(X, Y, FBtn.Width, FBtn.Height));
end
else
FBtn.ReleaseHandle;
end;
end
else
inherited MouseMove(Shift, X, Y);
end;
procedure TJvSpeedBarButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
P: TPoint;
begin
if FItem.FEditing and (FBtn <> nil) then
begin
X := X - (FBtn.Width {div 2});
Y := Y - (FBtn.Height {div 2});
FBtn.Free;
FBtn := nil;
P := ClientToScreen(Point(X, Y));
if FItem.SpeedBar <> nil then
begin
P := FItem.SpeedBar.ScreenToClient(P);
if PtInRect(FItem.SpeedBar.ClientRect, P) then
begin
if not FItem.SpeedBar.AcceptDropItem(FItem, P.X, P.Y) then
begin
SendMessage(FItem.SpeedBar.FEditWin, CM_SPEEDBARCHANGED, SBR_CHANGED,
Longint(FItem.SpeedBar));
end
else
begin
SendMessage(FItem.SpeedBar.FEditWin, CM_SPEEDBARCHANGED, SBR_BTNSELECT,
Longint(FItem));
Invalidate;
end;
end
else
begin
SendToBack;
FItem.Visible := False;
SendMessage(FItem.SpeedBar.FEditWin, CM_SPEEDBARCHANGED, SBR_CHANGED,
Longint(FItem.SpeedBar));
end;
end;
end
else
inherited MouseUp(Button, Shift, X, Y);
end;
procedure TJvSpeedBarButton.InvalidateGlyph;
begin
TJvxButtonGlyph(ButtonGlyph).Invalidate;
end;
procedure TJvSpeedBarButton.PaintImage(Canvas: TCanvas; ARect: TRect; const Offset: TPoint;
AState: TJvButtonState; DrawMark: Boolean);
begin
if FItem.SpeedBar <> nil then
begin
TJvxButtonGlyph(ButtonGlyph).DrawEx(Canvas, ARect, Offset, Caption, Layout,
Margin, Spacing, DrawMark, FItem.SpeedBar.Images, FItem.FImageIndex,
AState,
Alignments[Alignment]
);
end
else
inherited PaintImage(Canvas, ARect, Offset, AState, DrawMark);
end;
procedure TJvSpeedBarButton.Paint;
begin
if Visible then
inherited Paint;
end;
//=== { TJvSpeedItem } =======================================================
constructor TJvSpeedItem.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FButton := TJvSpeedBarButton.Create(Self);
FButton.Visible := False;
FButton.SetBounds(0, 0, DefaultButtonSize.X, DefaultButtonSize.Y);
FCaption := '';
ShowHint := True;
ParentShowHint := True;
FVisible := False;
FStored := True;
FEnabled := True;
FEditing := False;
FParent := nil;
FImageIndex := -1;
end;
destructor TJvSpeedItem.Destroy;
begin
FVisible := False;
if FParent <> nil then
FParent.RemoveItem(Self);
FButton.Free;
inherited Destroy;
end;
function TJvSpeedItem.GetCaption: TCaption;
begin
Result := TCaption(FCaption);
end;
procedure TJvSpeedItem.SetCaption(const Value: TCaption);
var
ChangeHint: Boolean;
begin
ChangeHint := (Owner = nil) or not (Owner is TControl) or
not (csLoading in TControl(Owner).ComponentState) and
(Caption = GetShortHint(Hint));
FCaption := Value;
if ChangeHint then
begin
if Pos('|', Value) = 0 then
begin
if Pos('|', Hint) = 0 then
Hint := Value + '|'
else
Hint := Value + '|' + GetLongHint(Hint);
end
else
begin
if GetLongHint(Value) = '' then
Hint := GetShortHint(Value) + '|' + GetLongHint(Hint)
else
Hint := Value;
end;
end;
end;
procedure TJvSpeedItem.SetName(const Value: TComponentName);
var
ChangeText: Boolean;
begin
ChangeText := (Name = Caption) and
((Owner = nil) or not (Owner is TControl) or
not (csLoading in TControl(Owner).ComponentState));
inherited SetName(Value);
if ChangeText then
Caption := Value;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -