⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqscrollmax.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  SetTrackBar;
end;

procedure TJvPanelScrollBar.CreateWnd;
begin
  inherited CreateWnd;
  SetTrackBar;
end;

//=== { TJvBandBtn } =========================================================

type
  TJvBandBtn = class(TJvNoFrameButton)
  private 
  protected
    procedure FontChanged; override;
  end;



procedure TJvBandBtn.FontChanged;
begin
  inherited FontChanged;
  if Parent <> nil then
    with Parent as TJvScrollMaxBand do
    begin
      FParentButtonFont := False;
      Canvas.Font := Self.Font;
      // (rom) please check this change
      //FButton.Height := Canvas.TextHeight('W') + 4;
      FButton.Height := CanvasMaxTextHeight(Canvas) + 4;
      Invalidate;
    end;
end;

//=== { TJvScrollMaxBand } ===================================================

constructor TJvScrollMaxBand.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csSetCaption, csAcceptsControls];
  IncludeThemeStyle(Self, [csParentBackground]);
  Height := 50;
  FExpandedHeight := 50;
  ParentColor := True;
  FParentButtonFont := True;
  FParentButtonVisible := True;
  FParentBeveled := True;
  FButton := TJvBandBtn.Create(Self);
  with FButton as TJvBandBtn do
  begin
    SetDesigning(False);
    Parent := Self;
    Top := 2;
    Left := 4;
    Cursor := crArrow;
    OnClick := ButtonClick;
    Margin := 4;
    Spacing := -1;
    NoBorder := False;
    ParentColor := True; 
  end;
  Expanded := True;
end;

procedure TJvScrollMaxBand.Loaded;
begin
  inherited Loaded;
  Perform(CM_PARENTBEVELEDCHANGED, 0, 0);
  Perform(CM_PARENTBUTTONVISIBLECHANGED, 0, 0);
  Perform(CM_PARENTBUTTONFONTCHANGED, 0, 0);
end;

procedure TJvScrollMaxBand.BoundsChanged;
begin
  if FExpanded then
    ExpandedHeight := Height;
  inherited BoundsChanged;
  if Parent <> nil then
    ScrollMax.CorrectHeight;
end;

procedure TJvScrollMaxBand.TextChanged;
begin
  inherited TextChanged;
  FButton.Caption := Caption;
end;

procedure TJvScrollMaxBand.SetExpanded(const Value: Boolean);
begin
  if FExpanded <> Value then
  begin
    FExpanded := Value;
    if FExpanded then
      FButton.Glyph.LoadFromResourceName(HInstance, 'JvScrollMaxBandBTNMINUS')
    else
      FButton.Glyph.LoadFromResourceName(HInstance, 'JvScrollMaxBandBTNPLUS');
    if FExpanded and Assigned(FOnExpand) then
      FOnExpand(Self);
    if not FExpanded and Assigned(FOnCollapse) then
      FOnCollapse(Self);
    RequestAlign;
    if Parent <> nil then
      ScrollMax.CorrectHeight;
   { if not (csLoading in ComponentState) and (ScrollMax <> nil) then
      DesignerModified(ScrollMax); }
  end;
end;

procedure TJvScrollMaxBand.SetExpandedHeight(const Value: Integer);
begin
  if FExpandedHeight <> Value then
  begin
    FExpandedHeight := Value;
    if FExpanded then
      Height := FExpandedHeight;
     // RequestAlign - called from SetHeight
  end;
end;

function TJvScrollMaxBand.GetOrder: Integer;
var
  I: Integer;
begin
  Result := FOrder;
  if Parent <> nil then
  begin
    for I := 0 to Parent.ControlCount - 1 do
      if Parent.Controls[I] = Self then
      begin
        Result := I;
        Break;
      end;
  end;
end;

procedure TJvScrollMaxBand.SetOrder(const Value: Integer);
begin
  if FOrder <> Value then
  begin
    if Parent <> nil then
      TJvScrollMaxBands(Parent).SetChildOrder(Self, Value);
    FOrder := GetOrder;
    RequestAlign;
  end;
end;

function TJvScrollMaxBand.GetButtonFont: TFont;
begin
  Result := FButton.Font;
end;

procedure TJvScrollMaxBand.SetButtonFont(Value: TFont);
begin
  FButton.Font := Value;
end;

procedure TJvScrollMaxBand.SetParentButtonFont(const Value: Boolean);
begin
  if FParentButtonFont <> Value then
  begin
    FParentButtonFont := Value;
    if Parent <> nil then
      Perform(CM_PARENTBUTTONFONTCHANGED, 0, 0);
  end;
end;

procedure TJvScrollMaxBand.CMParentButtonFontChanged(var Msg: TMessage);
begin
  if FParentButtonFont then
  begin
    if ScrollMax <> nil then
      SetButtonFont(ScrollMax.FButtonFont);
    FParentButtonFont := True;
  end;
end;

function TJvScrollMaxBand.IsButtonFontStored: Boolean;
begin
  Result := not ParentButtonFont;
end;

function TJvScrollMaxBand.GetButtonVisible: Boolean;
begin
  Result := FButton.Visible;
end;

procedure TJvScrollMaxBand.SetButtonVisible(const Value: Boolean);
begin
  if FButton.Visible <> Value then
  begin
    FParentButtonVisible := False;
    FButton.Visible := Value;
    UpdateSize(Top);
    Invalidate;
  end;
end;

function TJvScrollMaxBand.IsButtonVisibleStored: Boolean;
begin
  Result := not ParentButtonVisible;
end;

procedure TJvScrollMaxBand.SetParentButtonVisible(const Value: Boolean);
begin
  if FParentButtonVisible <> Value then
  begin
    FParentButtonVisible := Value;
    if Parent <> nil then
      Perform(CM_PARENTBUTTONVISIBLECHANGED, 0, 0);
  end;
end;

procedure TJvScrollMaxBand.CMParentButtonVisibleChanged(var Msg: TMessage);
begin
  if FParentButtonVisible then
  begin
    if ScrollMax <> nil then
      SetButtonVisible(ScrollMax.FButtonVisible);
    FParentButtonVisible := True;
  end;
end;

procedure TJvScrollMaxBand.SetBeveled(const Value: Boolean);
begin
  if FBeveled <> Value then
  begin
    FParentBeveled := False;
    FBeveled := Value;
    UpdateSize(Top);
    Invalidate;
  end;
end;

function TJvScrollMaxBand.IsBeveledStored: Boolean;
begin
  Result := not ParentBeveled;
end;

procedure TJvScrollMaxBand.SetParentBeveled(const Value: Boolean);
begin
  if FParentBeveled <> Value then
  begin
    FParentBeveled := Value;
    if Parent <> nil then
      Perform(CM_PARENTBEVELEDCHANGED, 0, 0);
  end;
end;

procedure TJvScrollMaxBand.CMParentBeveledChanged(var Msg: TMessage);
begin
  if FParentBeveled then
  begin
    if ScrollMax <> nil then
      SetBeveled(ScrollMax.FBeveled);
    FParentBeveled := True;
  end;
end;

procedure TJvScrollMaxBand.ButtonClick(Sender: TObject);
var
  E: Boolean;
begin
  E := True;
  if FExpanded then
  begin
    if Assigned(FOnCanCollapse) then
      FOnCanCollapse(Self, E);
  end
  else
  if Assigned(FOnCanExpand) then
    FOnCanExpand(Self, E);
  if E then
    Expanded := not FExpanded;
  DesignerModified(Self);
end;

procedure TJvScrollMaxBand.SetParent( const  AParent: TWinControl);
begin
  if not ((AParent is TJvScrollMaxBands) or (AParent = nil)) then
    raise EJvScrollMaxError.CreateRes(@RsETJvScrollMaxBandCanBePutOnlyIntoTJv);
  inherited SetParent(AParent);
  if not (csLoading in ComponentState) then
  begin
    Perform(CM_PARENTBEVELEDCHANGED, 0, 0);
    Perform(CM_PARENTBUTTONVISIBLECHANGED, 0, 0);
    Perform(CM_PARENTBUTTONFONTCHANGED, 0, 0);
  end;
end;

procedure TJvScrollMaxBand.SetZOrder(TopMost: Boolean);
begin
  inherited SetZOrder(TopMost);
  RequestAlign;
end;

procedure TJvScrollMaxBand.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
  ScrollMax.BandMouseDown(Self, Button, Shift, X, Y);
end;

procedure TJvScrollMaxBand.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseMove(Shift, X, Y);
  ScrollMax.BandMouseMove(Self, Shift, X, Y);
end;

procedure TJvScrollMaxBand.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  inherited MouseUp(Button, Shift, X, Y);
  ScrollMax.BandMouseUp(Self, Button, Shift, X, Y);
end;

function TJvScrollMaxBand.ScrollMax: TJvScrollMax;
begin
  if (Parent <> nil) and ((Parent as TJvScrollMaxBands).Parent <> nil) then
    Result := (Parent as TJvScrollMaxBands).Parent as TJvScrollMax
  else
    Result := nil;
end;

function TJvScrollMaxBand.CollapsedHeight: Integer;
begin
  Result := FButton.BoundsRect.Bottom + FButton.Top;
end;

procedure TJvScrollMaxBand.UpdateSize(ATop: Integer);
var
  W, H: Integer;
begin
  if FExpanded then
    H := FExpandedHeight
  else
    H := CollapsedHeight;
  if ScrollMax <> nil then
  begin
    W := Parent.Width;
    if ScrollMax.ScrollBarVisible then
      W := W - 3;
  end
  else
    W := Width;
  SetBounds(0, ATop, W, H);
  if FBeveled then
    FButton.Left := 16
  else
    FButton.Left := 4;
  FButton.Width := Width - FButton.Left * 2;
end;

procedure TJvScrollMaxBand.Paint;
const
  Ex: array [Boolean] of Integer = (BF_TOP, BF_RECT);
var
  R: TRect;
begin
  if Canvas.Handle <> NullHandle then
  begin
    if csDesigning in ComponentState then
      DrawDesignFrame(Canvas, ClientRect);
    if FBeveled then
    begin
      R.Left := 1;
      if ButtonVisible then
        R.Top := FButton.Top + FButton.Height div 2
      else
        R.Top := 1;
      R.Right := Width - R.Left;
      R.Bottom := Height - 1;
      QWindows.DrawEdge(Canvas.Handle, R, EDGE_ETCHED, Ex[FExpanded]);
      if ButtonVisible then
      begin
        Canvas.Brush.Color := Color;
        Canvas.Brush.Style := bsSolid;
        Canvas.FillRect(Bounds(FButton.Left - 2, R.Top, FButton.Width + 4, 2));
      end;
    end;
  end;
end;

procedure TJvScrollMaxBand.AlignControls(AControl: TControl; var Rect: TRect);
var
  BevelSize: Integer;
begin
  BevelSize := FBorderWidth;
  if FBeveled then
    Inc(BevelSize, 3);
  InflateRect(Rect, -BevelSize, -BevelSize);
  if ButtonVisible then
  begin
    Inc(Rect.Top, FButton.Height);
    if FButton.Top > FBorderWidth then
      Inc(Rect.Top, FButton.Top);
  end;
  inherited AlignControls(AControl, Rect);
end;

procedure TJvScrollMaxBand.SetBorderWidth(const Value: Integer);
begin
  if FBorderWidth <> Value then
  begin
    FBorderWidth := Value;
    Realign;
  end;
end;

procedure TJvScrollMaxBand.ChangeScale(M, D , MH, DH : Integer);
begin
  inherited ChangeScale(M, D , MH, DH );
  ExpandedHeight := FExpandedHeight * M div D;
end;

//=== { TJvScrollMaxBands } ==================================================

procedure TJvScrollMaxBands.AlignControls(AControl: TControl; var Rect: TRect);
var
  I: Integer;
  ScrollMax: TJvScrollMax;
  T: Integer;
  SMax, SPage, SPos: Integer;

  procedure AdjustBottom;
  begin
    if (Controls[ControlCount - 1].BoundsRect.Bottom < Height) and
      (Controls[0].Top < 0) then
    begin
      if Height - (Controls[ControlCount - 1].BoundsRect.Bottom - Controls[0].Top) > 0 then
        ScrollControls(-Controls[0].Top)
      else
        ScrollControls(Height - Controls[ControlCount - 1].BoundsRect.Bottom);
    end;
  end;

  procedure AdjustBand;
  var
    Band: TJvScrollMaxBand;
  begin
    Band := AControl as TJvScrollMaxBand;
    if (Band <> nil) and Band.FExpanded and
      (Band.BoundsRect.Bottom > Height) and
      (Band.Top > 0) and
      not (csLoading in Band.ComponentState) then
    begin
      ScrollControls(Height - Band.BoundsRect.Bottom);
    end;
  end;

  procedure SetCursor;
  var
    I: Integer;
    Cursor: TCursor;
  begin
    if (Controls[ControlCount - 1].BoundsRect.Bottom > ClientHeight) or
      (Controls[0].Top < 0) then
      Cursor := crRAHand
    else
      Cursor := crDefault;
    for I := 0 to ControlCount - 1 do
      Controls[I].Cursor := Cursor;
  end;

begin
  if FScrolling then
    Exit;
  if (Parent <> nil) and (csLoading in Parent.ComponentState) then
    Exit;
  ScrollMax := Parent as TJvScrollMax;
  if (AControl <> nil) and
    (AControl as TJvScrollMaxBand).FExpanded and
    ScrollMax.FOneExpanded then
    for I := 0 to ControlCount - 1 do
      if not (Controls[I] is TJvScrollMaxBand) then
        raise EJvScrollMaxError.CreateRes(@RsETJvScrollMaxCanContainOnlyTJvScroll)
      else
      if Controls[I] <> AControl then
        (Controls[I] as TJvScrollMaxBand).Expanded := False;
  SPos := ScrollMax.FScrollPos;
  if ControlCount > 0 then
  begin
    for I := 0 to ControlCount - 1 do
    begin
      if not (Controls[I] is TJvScrollMaxBand) then
        raise EJvScrollMaxError.CreateRes(@RsETJvScrollMaxCanContainOnlyTJvScroll);
      if I > 0 then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -