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

📄 sxskinspinedit.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      SkinStyle:='_SpinEditRV' else
     if not Horizontal and (SkinStyle='_SpinEditLH') then
      SkinStyle:='_SpinEditLV';
    end;
  end;
end;

function TSXSkinCustomSpinEdit.CheckValueRanges(Value:Integer):Integer;
begin
 Result:=Value;
 if FMaxValue>=FMinValue then
  begin
   if Result>FMaxValue then
    Result:=FMaxValue else
   if Result<FMinValue then
    Result:=FMinValue;
  end;
end;

procedure TSXSkinCustomSpinEdit.CheckCurrentValue;
var V1,V2:Integer;
begin
 V1:=Value;
 V2:=CheckValueRanges(V1);
 if (V1<>V2) or ((V1=0) and (Text<>'0')) then
  Text:=inttostr(V2);
end;

procedure TSXSkinCustomSpinEdit.AdjustToEditBounds;
begin
 if not EqualRect(FSkinEdit.BoundsRect,FEditRect) and (FSkinEdit.Height>0) and
        (FEditRect.Bottom-FEditRect.Top>0) then
  begin
   Height:=Height+FSkinEdit.Height-FEditRect.Bottom+FEditRect.Top;
  end;
end;

procedure TSXSkinCustomSpinEdit.ResetChildrenStyles;
var  A:Integer;
 Style:TSXSkinSpinEditStyle;
begin
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinSpinEditStyle) then
    begin
     Style:=TSXSkinSpinEditStyle(SkinLibrary.Styles[A]);
     FSkinEdit.SkinStyle:=Style.Edit;
     FSkinEdit.SkinLibrary:=SkinLibrary;
     FSkinUpDown.SkinStyle:=Style.UpDown;
     FSkinUpDown.SkinLibrary:=SkinLibrary;
    end;
  end;
end;

procedure TSXSkinCustomSpinEdit.ResetChildrenPosition;
var  A:Integer;
 Style:TSXSkinSpinEditStyle;
begin
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinSpinEditStyle) then
    begin
     Style:=TSXSkinSpinEditStyle(SkinLibrary.Styles[A]);
     GetRectFromString(Style.EditRect,FEditRect,OnGetVariable);
     GetRectFromString(Style.UpDownRect,FUpDownRect,OnGetVariable);
     FSkinUpDown.BoundsRect:=FUpDownRect;
     FSkinEdit.BoundsRect:=FEditRect;
    end;
  end;
end;

function TSXSkinCustomSpinEdit.OnGetVariable(const VarName:String;var Error:Boolean):Single;
begin
 Result:=0;
 if VarName='W' then
  begin
   Result:=Width; exit;
  end;
 if VarName='H' then
  begin
   Result:=Height; exit;
  end;
 Error:=True;
end;

procedure TSXSkinCustomSpinEdit.SkinChanged;
begin
 if not (csLoading in ComponentState) then
  begin
   ResetChildrenPosition;
   ResetChildrenStyles;
   FSkinEdit.SkinChanged;
   FSkinUpDown.SkinChanged;
  end;
 inherited;
end;

procedure TSXSkinCustomSpinEdit.Loaded;
begin
 inherited;
 ResetChildrenPosition;
 ResetChildrenStyles;
 FSkinEdit.SetLoaded;
 FSkinUpDown.SetLoaded; 
end;

procedure TSXSkinCustomSpinEdit.SetBounds(ALeft,ATop,AWidth,AHeight:Integer);
var OldWidth,OldHeight:Integer;
begin
 OldWidth:=Width;
 OldHeight:=Height;
 inherited;
 if not (csLoading in ComponentState) and ((Width<>OldWidth) or (Height<>OldHeight)) then
  begin
   ResetChildrenPosition;
   AdjustToEditBounds; 
  end;
end;

procedure TSXSkinCustomSpinEdit.SkinEditResize(Sender:TObject);
begin
 AdjustToEditBounds;
end;

procedure TSXSkinCustomSpinEdit.EditKeyDown(Sender:TObject;var Key:Word;Shift:TShiftState);
begin
 if Key=VK_UP then UpDownClick(Self,True) else
  if Key=VK_DOWN then UpDownClick(Self,False);
end;

procedure TSXSkinCustomSpinEdit.EditKeyPress(Sender:TObject;var Key:Char);
begin
 if not IsValidChar(Key) then
  begin
   Key:=#0;
   MessageBeep(0)
  end;
end;

procedure TSXSkinCustomSpinEdit.EditUsedModified(Sender:TObject);
begin
 CheckCurrentValue;
 if Assigned(OnChange) and (FLastChangeValue<>Text) then
  begin
   FLastChangeValue:=Text;
   OnChange(Self);
  end;
 if Assigned(OnUserModified) then
  OnUserModified(Self);
end;

procedure TSXSkinCustomSpinEdit.UpDownClick(Sender:TObject;UpButton:Boolean);
var LCV:String;
begin
 LCV:=Text;
 if ReadOnly then MessageBeep(0) else
 if UpButton then
  Value:=Value+FIncrement else
   Value:=Value-FIncrement;
 if Text<>LCV then
  begin
   if Assigned(OnUserModified) then
    OnUserModified(Self);
  end;
end;

procedure TSXSkinCustomSpinEdit.EditClick(Sender:TObject);
begin
 if Assigned(OnClick) then
  OnClick(Self);
end;

procedure TSXSkinCustomSpinEdit.EditContextPopup(Sender:TObject;MousePos:TPoint;var Handled:Boolean);
begin
 if Assigned(OnContextPopup) then
  OnContextPopup(Self,MousePos,Handled);
end;

procedure TSXSkinCustomSpinEdit.EditDblClick(Sender:TObject);
begin
 if Assigned(OnDblClick) then
  OnDblClick(Self);
end;

procedure TSXSkinCustomSpinEdit.EditDragDrop(Sender,Source:TObject;X,Y:Integer);
begin
 if Assigned(OnDragDrop) then
  OnDragDrop(Self,Source,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditDragOver(Sender,Source:TObject;X,Y:Integer;
           State:TDragState;var Accept:Boolean);
begin
 if Assigned(OnDragOver) then
  OnDragOver(Self,Source,X,Y,State,Accept);
end;

procedure TSXSkinCustomSpinEdit.EditEndDock(Sender,Target:TObject;X,Y:Integer);
begin
 if Assigned(OnEndDock) then
  OnEndDock(Self,Target,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditEndDrag(Sender,Target:TObject;X,Y:Integer);
begin
 if Assigned(OnEndDrag) then
  OnEndDrag(Self,Target,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditMouseDown(Sender:TObject;Button:TMouseButton;
           Shift:TShiftState;X,Y:Integer);
begin
 if Assigned(OnMouseDown) then
  OnMouseDown(Self,Button,Shift,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditMouseEnter(Sender:TObject);
begin
 if Assigned(OnMouseEnter) then
  OnMouseEnter(Self);
end;

procedure TSXSkinCustomSpinEdit.EditMouseLeave(Sender:TObject);
begin
 if Assigned(OnMouseLeave) then
  OnMouseLeave(Self);
end;

procedure TSXSkinCustomSpinEdit.EditMouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);
begin
 if Assigned(OnMouseMove) then
  OnMouseMove(Self,Shift,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditMouseUp(Sender:TObject;Button:TMouseButton;
           Shift:TShiftState;X,Y:Integer);
begin
 if Assigned(OnMouseUp) then
  OnMouseUp(Self,Button,Shift,X,Y);
end;

procedure TSXSkinCustomSpinEdit.EditMouseWheel(Sender:TObject;Shift:TShiftState;
           WheelDelta:Integer;MousePos:TPoint;var Handled:Boolean);
begin
 if Assigned(OnMouseWheel) then
  OnMouseWheel(Self,Shift,WheelDelta,MousePos,Handled);
end;

procedure TSXSkinCustomSpinEdit.EditMouseWheelDown(Sender:TObject;Shift:TShiftState;
           MousePos:TPoint;var Handled:Boolean);
begin
 if Assigned(OnMouseWheelDown) then
  OnMouseWheelDown(Self,Shift,MousePos,Handled);
end;

procedure TSXSkinCustomSpinEdit.EditMouseWheelUp(Sender:TObject;Shift:TShiftState;
           MousePos:TPoint;var Handled:Boolean);
begin
 if Assigned(OnMouseWheelUp) then
  OnMouseWheelUp(Self,Shift,MousePos,Handled);
end;

procedure TSXSkinCustomSpinEdit.EditStartDock(Sender:TObject;var DragObject:TDragDockObject);
begin
 if Assigned(OnStartDock) then
  OnStartDock(Self,DragObject);
end;

procedure TSXSkinCustomSpinEdit.EditStartDrag(Sender:TObject;var DragObject:TDragObject);
begin
 if Assigned(OnStartDrag) then
  OnStartDrag(Self,DragObject);
end;

procedure TSXSkinCustomSpinEdit.SetEnabled(Value:Boolean);
begin
 if Enabled<>Value then
  begin
   inherited;
   FSkinEdit.Enabled:=Value;
   FSkinUpDown.Enabled:=Value;
  end;
end;

constructor TSXSkinCustomSpinEdit.Create(AOwner:TComponent);
begin
 inherited Create(AOwner);
 FSkinEdit:=TSXSkinCustomEdit.Create(Self);
 FSkinEdit.Parent:=Self;
 FSkinEdit.OnResize:=SkinEditResize;
 FSkinEdit.OnKeyDown:=EditKeyDown;
 FSkinEdit.OnKeyPress:=EditKeyPress;
 FSkinEdit.OnUserModified:=EditUsedModified;
 FSkinEdit.OnClick:=EditClick;
 FSkinEdit.OnContextPopup:=EditContextPopup;
 FSkinEdit.OnDblClick:=EditDblClick;
 FSkinEdit.OnDragDrop:=EditDragDrop;
 FSkinEdit.OnDragOver:=EditDragOver;
 FSkinEdit.OnEndDock:=EditEndDock;
 FSkinEdit.OnEndDrag:=EditEndDrag;
 FSkinEdit.OnMouseDown:=EditMouseDown;
 FSkinEdit.OnMouseEnter:=EditMouseEnter;
 FSkinEdit.OnMouseLeave:=EditMouseLeave;
 FSkinEdit.OnMouseMove:=EditMouseMove;
 FSkinEdit.OnMouseUp:=EditMouseUp;
 FSkinEdit.OnMouseWheel:=EditMouseWheel;
 FSkinEdit.OnMouseWheelDown:=EditMouseWheelDown;
 FSkinEdit.OnMouseWheelUp:=EditMouseWheelUp;
 FSkinEdit.OnStartDock:=EditStartDock;
 FSkinEdit.OnStartDrag:=EditStartDrag;
 FSkinEdit.Text:='0';
 //
 FSkinUpDown:=TSXSkinCustomUpDown.Create(Self);
 FSkinUpDown.Parent:=Self;
 FSkinUpDown.OnClick:=UpDownClick;
 FSkinUpDown.OnContextPopup:=EditContextPopup;
 FSkinUpDown.OnDragDrop:=EditDragDrop;
 FSkinUpDown.OnDragOver:=EditDragOver;
 FSkinUpDown.OnEndDock:=EditEndDock;
 FSkinUpDown.OnEndDrag:=EditEndDrag;
 FSkinUpDown.OnMouseDown:=EditMouseDown;
 FSkinUpDown.OnMouseEnter:=EditMouseEnter;
 FSkinUpDown.OnMouseLeave:=EditMouseLeave;
 FSkinUpDown.OnMouseMove:=EditMouseMove;
 FSkinUpDown.OnMouseUp:=EditMouseUp;
 FSkinUpDown.OnMouseWheel:=EditMouseWheel;
 FSkinUpDown.OnMouseWheelDown:=EditMouseWheelDown;
 FSkinUpDown.OnMouseWheelUp:=EditMouseWheelUp;
 FSkinUpDown.OnStartDock:=EditStartDock;
 FSkinUpDown.OnStartDrag:=EditStartDrag;
 //
 FButtonsPosition:=bpRight;
 FEditorEnabled:=True;
 FIncrement:=1;
 FMaxValue:=-1;
 FMinValue:=0;
 SkinStyle:='_SpinEditRV';
end;

end.

⌨️ 快捷键说明

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