Einzelnen Beitrag anzeigen

Sidorion

Registriert seit: 23. Jun 2005
403 Beiträge
 
#13

Re: Dynamisches Editfeld als Komponente

  Alt 29. Aug 2007, 09:00
Mit den Jedis kenn ich mich nicht aus, aber es wäre kein Problem einen eigenen Spin von Anfang an nachzubauen, da Du die Quellen ja hast. Dann kannste nebenbei auch das völlig falsche Zeichenverhalten bei aktivierten Themes korrigieren. Du musst alle drei Klassen nachbauen: den Timerbutton, den UpDown Button und den SpinEdit. Hier mal die Header zu meinen Nachbauten:
Delphi-Quellcode:
  TSpinBtn=Class(TCustomControl)
   Private
    bMouseDown: Boolean;
    bMouseOver: Boolean;
    bMouseOverUp: Boolean;
    oDownGlyph: TBitMap;
    oFocusControl: TWinControl;
    oOnDownClick: TNotifyEvent;
    oOnUpClick: TNotifyEvent;
    oRepeatTimer: TTimer;
    oUpGlyph: TBitMap;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
   Protected
    procedure Click; Override;
    procedure DoRepeatTimer(Sender: TObject);
    function GetDownGlyph: TBitmap;
    function GetUpGlyph: TBitmap;
    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 Notification(AComponent: TComponent;
      Operation: TOperation); override;
    procedure Paint; Override;
    procedure SetDownGlyph(Value: TBitmap);
    procedure SetEnabled(Value: Boolean); Override;
    procedure SetUpGlyph(Value: TBitmap);
    property DownGlyph: TBitmap read GetDownGlyph write SetDownGlyph;
    property UpGlyph: TBitmap read GetUpGlyph write SetUpGlyph;
   Public
    Constructor Create(Owner: TComponent); Override;
    Destructor Destroy; Override;
  published
    property Align;
    property Anchors;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property FocusControl: TWinControl read oFocusControl write oFocusControl;
    property ParentCtl3D;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnDownClick: TNotifyEvent read oOnDownClick write oOnDownClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnStartDock;
    property OnStartDrag;
    property OnUpClick: TNotifyEvent read oOnUpClick write oOnUpClick;
  End;

  TSpinEdt = class(TCustomEdit)
  private
    FMinValue: Single;
    FMaxValue: Single;
    FIncrement: Single;
    FButton: TSpinBtn;
    FEditorEnabled: Boolean;
    function GetMinHeight: Integer;
    function GetIntValue: LongInt;
    function GetValue: Single;
    function CheckIntValue (NewValue: LongInt): LongInt;
    function CheckValue (NewValue: Single): Single;
    procedure SetIntValue (NewValue: LongInt);
    procedure SetValue (NewValue: Single);
    procedure SetEditRect;
    procedure WMSize(var Message: TWMSize); message WM_SIZE;
    procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;
    procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
    procedure WMCut(var Message: TWMCut); message WM_CUT;
  protected
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
    function IsValidChar(Key: Char): Boolean; virtual;
    procedure UpClick (Sender: TObject); virtual;
    procedure DownClick (Sender: TObject); virtual;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    procedure KeyPress(var Key: Char); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure CreateWnd; override;
    procedure SetEnabled(Value: Boolean); Override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Button: TSpinBtn read FButton;
  published
    property Anchors;
    property AutoSelect;
    property AutoSize;
    property Color;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
    property Enabled;
    property Font;
    property Increment: Single read FIncrement write fIncrement;
    property MaxLength;
    property MaxValue: Single read FMaxValue write fMaxValue;
    property MinValue: Single read FMinValue write fMinValue;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ReadOnly;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property IntValue: LongInt read GetIntValue write SetIntValue;
    property Value: Single read GetValue write SetValue;
    property Visible;
    property OnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;
  end;
Hab das auf zwei Klassen Reduziert, weil der TSpinBtn beide Knöpfe zeichnet und bedient. Mehr Code rück ich aber nicht raus, weil ich hab noch keine Lizenz gefunden, die mir passt.
Manchmal sehen Dinge, die wie Dinge aussehen wollen mehr wie Dinge aus, als Dinge
<Esmerelda Wetterwachs>
  Mit Zitat antworten Zitat