📄 dxstatusbar.pas
字号:
inherited SetItem(Index, Value);
end;
{ TdxStatusBarStateIndicatorPanelStyle }
constructor TdxStatusBarStateIndicatorPanelStyle.Create(AOwner: TdxStatusBarPanel);
begin
inherited Create(AOwner);
FSpacing := 4;
FIndicators := TdxStatusBarStateIndicators.Create;
FIndicators.OnChange := IndicatorChangeHandler;
end;
destructor TdxStatusBarStateIndicatorPanelStyle.Destroy;
begin
FreeAndNil(FIndicators);
inherited;
end;
procedure TdxStatusBarStateIndicatorPanelStyle.RestoreDefaults;
begin
FSpacing := 4;
inherited RestoreDefaults;
end;
function TdxStatusBarStateIndicatorPanelStyle.CanSizing: Boolean;
begin
Result := False;
end;
procedure TdxStatusBarStateIndicatorPanelStyle.DoAssign(ASource: TPersistent);
var
AStyle: TdxStatusBarStateIndicatorPanelStyle;
begin
inherited;
if ASource is TdxStatusBarStateIndicatorPanelStyle then
begin
AStyle := TdxStatusBarStateIndicatorPanelStyle(ASource);
Spacing := AStyle.Spacing;
Indicators := AStyle.Indicators;
end;
end;
procedure TdxStatusBarStateIndicatorPanelStyle.DrawContent(ACanvas: TcxCanvas;
R: TRect; APainter: TdxStatusBarPainterClass);
var
I, ALeft, ATop: Integer;
ABitmap: TBitmap;
begin
inherited;
ALeft := R.Left + Spacing;
for I := 0 to Indicators.Count - 1 do
begin
ABitmap := Indicators[I].FIndicatorBitmap;
if Indicators[I].Visible and (ABitmap <> nil) and not ABitmap.Empty then
begin
ATop := ((R.Top + R.Bottom) div 2) - (ABitmap.Height div 2);
ACanvas.Draw(ALeft, ATop, ABitmap);
Inc(ALeft, ABitmap.Width + Spacing);
end;
end;
end;
function TdxStatusBarStateIndicatorPanelStyle.GetMinWidth: Integer;
var
I: Integer;
ABitmap: TBitmap;
begin
// WARNING: sync with DrawContent
if Indicators.Count > 0 then
begin
Result := Spacing;
for I := 0 to Indicators.Count - 1 do
begin
ABitmap := Indicators[I].FIndicatorBitmap;
if Indicators[I].Visible and (ABitmap <> nil) and not ABitmap.Empty then
Inc(Result, ABitmap.Width + Spacing);
end;
end
else
Result := 20;
end;
function TdxStatusBarStateIndicatorPanelStyle.GetIndicators: TdxStatusBarStateIndicators;
begin
Result := FIndicators;
end;
procedure TdxStatusBarStateIndicatorPanelStyle.IndicatorChangeHandler(Sender: TObject);
begin
Owner.Changed(False);
end;
procedure TdxStatusBarStateIndicatorPanelStyle.SetIndicators(Value: TdxStatusBarStateIndicators);
begin
FIndicators.Assign(Value);
end;
procedure TdxStatusBarStateIndicatorPanelStyle.SetSpacing(Value: Integer);
begin
if FSpacing <> Value then
begin
FSpacing := Value;
Owner.Changed(False);
end;
end;
{ TdxStatusBarKeyboardStateWatchedKey }
constructor TdxStatusBarKeyboardStateWatchedKey.Create(AKeyCode: Integer);
begin
FKeyCode := AKeyCode;
FKeyState := Lo(GetKeyState(AKeyCode));
end;
function TdxStatusBarKeyboardStateWatchedKey.GetCurrentState: Integer;
begin
Result := Lo(GetKeyState(FKeyCode));
end;
procedure TdxStatusBarKeyboardStateWatchedKey.SetKeyState(Value: Integer);
begin
FKeyState := Value;
end;
{ TdxStatusBarKeyboardStateNotifier }
constructor TdxStatusBarKeyboardStateNotifier.Create(AStatusBar: TdxCustomStatusBar);
begin
inherited Create;
FStatusBar := AStatusBar;
FTimer := TTimer.Create(nil);
FTimer.Interval := 100;
FTimer.OnTimer := Execute;
end;
destructor TdxStatusBarKeyboardStateNotifier.Destroy;
begin
FTimer.Free;
inherited Destroy;
end;
procedure TdxStatusBarKeyboardStateNotifier.SubScribeKey(AKeyCode: Integer);
begin
UnSubscribeKey(AKeyCode);
SetLength(FKeys, Length(FKeys) + 1);
FKeys[High(FKeys)] := TdxStatusBarKeyboardStateWatchedKey.Create(AKeyCode);
end;
procedure TdxStatusBarKeyboardStateNotifier.UnSubScribeKey(AKeyCode: Integer);
var
I: Integer;
begin
for I := 0 to High(FKeys) do
if FKeys[I].KeyCode = AKeyCode then
begin
FreeAndNil(FKeys[I]);
SetLength(FKeys, Length(FKeys) - 1);
Break;
end;
end;
procedure TdxStatusBarKeyboardStateNotifier.Execute(Sender: TObject);
var
I, ACurState: Integer;
AChanged: Boolean;
begin
AChanged := False;
for I := Low(FKeys) to High(FKeys) do
begin
ACurState := Lo(GetKeyState(FKeys[I].KeyCode));
if ACurState <> FKeys[I].KeyState then
begin
FKeys[I].KeyState := ACurState;
AChanged := True;
end;
end;
if AChanged then
FStatusBar.UpdatePanels;
end;
{ TdxStatusBarKeyStateAppearance }
constructor TdxStatusBarKeyStateAppearance.Create(AId: TdxStatusBarKeyboardState;
ACode: Integer; const AActiveCaption: string; AActiveFontColor: TColor;
const AInactiveCaption: string; AInactiveFontColor: TColor; AChangeHandler: TNotifyEvent);
begin
inherited Create;
FId := AId;
FCode := ACode;
FOnChange := AChangeHandler;
FActiveFontColor := AActiveFontColor;
FInactiveFontColor := AInactiveFontColor;
FActiveCaption := AActiveCaption;
FInactiveCaption := AInactiveCaption;
end;
procedure TdxStatusBarKeyStateAppearance.Assign(Source: TPersistent);
begin
if Source is TdxStatusBarKeyStateAppearance then
begin
ActiveFontColor := TdxStatusBarKeyStateAppearance(Source).ActiveFontColor;
InactiveFontColor := TdxStatusBarKeyStateAppearance(Source).InactiveFontColor;
ActiveCaption := TdxStatusBarKeyStateAppearance(Source).ActiveCaption;
InactiveCaption := TdxStatusBarKeyStateAppearance(Source).InactiveCaption;
end
else
inherited Assign(Source);
end;
function TdxStatusBarKeyStateAppearance.GetRectWidth(ACanvas: TcxCanvas): Integer;
var
AW, IW: Integer;
begin
AW := ACanvas.TextWidth(FActiveCaption);
IW := ACanvas.TextWidth(FInactiveCaption);
if AW > IW then
Result := AW
else
Result := IW;
Inc(Result, 4);
end;
procedure TdxStatusBarKeyStateAppearance.Changed;
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TdxStatusBarKeyStateAppearance.SetActiveFontColor(Value: TColor);
begin
FActiveFontColor := Value;
Changed;
end;
procedure TdxStatusBarKeyStateAppearance.SetInactiveFontColor(Value: TColor);
begin
FInactiveFontColor := Value;
Changed;
end;
procedure TdxStatusBarKeyStateAppearance.SetActiveCaption(const Value: string);
begin
FActiveCaption := Value;
Changed;
end;
procedure TdxStatusBarKeyStateAppearance.SetInactiveCaption(const Value: string);
begin
FInactiveCaption := Value;
Changed;
end;
{ TdxStatusBarKeyboardStatePanelStyle }
constructor TdxStatusBarKeyboardStatePanelStyle.Create(AOwner: TdxStatusBarPanel);
var
I: Integer;
begin
inherited Create(AOwner);
FKeyInfos[0] := TdxStatusBarKeyStateAppearance.Create(dxksCapsLock, VK_CAPITAL, 'CAPS',
FFont.Color, 'CAPS', clBtnShadow, NamesChangeHandler);
FKeyInfos[1] := TdxStatusBarKeyStateAppearance.Create(dxksNumLock, VK_NUMLOCK, 'NUM',
FFont.Color, 'NUM', clBtnShadow, NamesChangeHandler);
FKeyInfos[2] := TdxStatusBarKeyStateAppearance.Create(dxksScrollLock, VK_SCROLL, 'SCRL',
FFont.Color, 'SCRL', clBtnShadow, NamesChangeHandler);
FKeyInfos[3] := TdxStatusBarKeyStateAppearance.Create(dxksInsert, VK_INSERT, 'OVR',
FFont.Color, 'INS', clBtnShadow, NamesChangeHandler);
FKeyboardStates := [FKeyInfos[0].Id, FKeyInfos[1].Id, FKeyInfos[2].Id, FKeyInfos[3].Id];
FNotifier := TdxStatusBarKeyboardStateNotifier.Create(StatusBarControl);
for I := 0 to High(FKeyInfos) do
FNotifier.SubscribeKey(FKeyInfos[I].Code);
end;
destructor TdxStatusBarKeyboardStatePanelStyle.Destroy;
var
I: Integer;
begin
for I := High(FKeyInfos) downto 0 do
if Assigned(FKeyInfos[I]) then
FNotifier.UnSubscribeKey(FKeyInfos[I].Code);
FNotifier.Free;
for I := High(FKeyInfos) downto 0 do
FreeAndNil(FKeyInfos[I]);
inherited;
end;
procedure TdxStatusBarKeyboardStatePanelStyle.RestoreDefaults;
begin
FKeyboardStates := [FKeyInfos[0].Id, FKeyInfos[1].Id, FKeyInfos[2].Id, FKeyInfos[3].Id];
inherited RestoreDefaults;
end;
function TdxStatusBarKeyboardStatePanelStyle.CanSizing: Boolean;
begin
Result := False;
end;
procedure TdxStatusBarKeyboardStatePanelStyle.DoAssign(ASource: TPersistent);
var
AStyle: TdxStatusBarKeyboardStatePanelStyle;
begin
inherited;
if ASource is TdxStatusBarKeyboardStatePanelStyle then
begin
AStyle := TdxStatusBarKeyboardStatePanelStyle(ASource);
KeyboardStates := AStyle.KeyboardStates;
FullRect := AStyle.FullRect;
CapsLockKeyAppearance := AStyle.CapsLockKeyAppearance;
NumLockKeyAppearance := AStyle.NumLockKeyAppearance;
ScrollLockKeyAppearance := AStyle.ScrollLockKeyAppearance;
InsertKeyAppearance := AStyle.InsertKeyAppearance;
end;
end;
procedure TdxStatusBarKeyboardStatePanelStyle.DrawContent(ACanvas: TcxCanvas;
R: TRect; APainter: TdxStatusBarPainterClass);
var
I: Integer;
S: string;
Active: Boolean;
ARect: TRect;
ALastKeyIndex: Integer;
ATextColor: TColor;
begin
inherited;
ACanvas.Font.Assign(FFont);
ALastKeyIndex := -1;
for I := Low(FKeyInfos) to High(FKeyInfos) do
if FKeyInfos[I].Id in FKeyboardStates then
ALastKeyIndex := I;
for I := Low(FKeyInfos) to High(FKeyInfos) do
begin
if FKeyInfos[I].Id in FKeyboardStates then
begin
Active := not (csDesigning in StatusBarControl.ComponentState) and
(Lo(GetKeyState(FKeyInfos[I].Code)) = 1);
if Active then
begin
S := FKeyInfos[I].ActiveCaption;
ATextColor := FKeyInfos[I].FActiveFontColor;
end
else
begin
S := FKeyInfos[I].InactiveCaption;
ATextColor := FKeyInfos[I].FInactiveFontColor;
end;
APainter.AdjustTextColor(Owner.GetStatusBarControl, ATextColor, Active);
AdjustTextColor(ATextColor, Active);
ACanvas.Font.Color := ATextColor;
// key cell
R.Right := R.Left + FKeyInfos[I].GetRectWidth(ACanvas);
if not FullRect then
Inc(R.Right, 2);
ARect := R;
if not FullRect then
APainter.DrawPanelBorder(StatusBarControl, Owner.Bevel, ACanvas, ARect);
ACanvas.Brush.Style := bsClear;
ACanvas.DrawTexT(S, ARect, cxSingleLine or cxAlignVCenter or cxAlignHCenter,
StatusBarControl.Enabled);
ACanvas.Brush.Style := bsSolid;
// key separator
if I <> ALastKeyIndex then
R.Left := R.Right + APainter.SeparatorSize;
end;
end;
end;
function TdxStatusBarKeyboardStatePanelStyle.GetMinWidth: Integer;
var
I: Integer;
ALastKeyIndex: Integer;
begin
// WARNING: sync with DrawContent
if FKeyboardStates <> [] then
begin
StatusBarControl.Canvas.Font.Assign(FFont);
Result := 0;
ALastKeyIndex := -1;
for I := Low(FKeyInfos) to High(FKeyInfos) do
if FKeyInfos[I].Id in FKeyboardStates then
ALastKeyIndex := I;
for I := Low(FKeyInfos) to High(FKeyInfos) do
begin
if FKeyInfos[I].Id in FKeyboardStates then
begin
Inc(Result, FKeyInfos[I].GetRectWidth(StatusBarControl.Canvas));
if not FullRect then Inc(Result, 2); // bevel
// key separator
if I <> ALastKeyIndex then
Inc(Result, StatusBarControl.Painter.SeparatorSize);
end;
end;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -