MMLEDS.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:65k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/index.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 22.10.98 - 17:51:31 $ =}
- {========================================================================}
- Unit MMLEDS;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- SysUtils,
- Messages,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- ExtCtrls,
- Buttons,
- MMObj,
- MMUtils,
- MMString,
- MMSpin;
- type
- TMMLEDType =(ltDigit, ltPeriod, ltColon, ltMinus);
- TMMLEDSize =(ls06x07,ls07x11,ls08x13,ls11x19,ls13x20,ls13x21,ls15x24,
- ls15x25,ls17x29,ls18x25,ls19x33,ls21x37,ls23x41);
- TMMPaintEvent = procedure(Sender: TObject; Canvas: TCanvas; R: TRect) of object;
-
- {-- TMMLED -----------------------------------------------------------}
- TMMLED = class(TMMGraphicControl)
- private
- FEnabled : Boolean; { Enable or disable LED }
- FLEDColor : TColor; { foreground color }
- FBeveledRect: TRect; { the real LED area }
- FOnPaint : TMMPaintEvent;
- procedure SetEnabled(aValue: Boolean);
- procedure SetLEDColor(aValue: TColor);
- procedure DrawLED;
- procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
- protected
- procedure Paint; override;
- procedure Changed; override;
- procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
- public
- constructor Create(AOwner: TComponent); override;
- published
- { Events }
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- property OnStartDrag;
- property OnPaint: TMMPaintEvent read FOnPaint write FOnPaint;
- property Bevel;
- property Color default clGreen;
- property ParentShowHint;
- property ShowHint;
- property Visible;
- property Font;
- property Caption;
- property DragCursor;
- property Enabled: Boolean read FEnabled write SetEnabled default True;
- property Height default 8;
- property Width default 16;
- property LEDColor: TColor read FLEDColor write setLEDColor default clLime;
- end;
- {-- TMMLEDMode -------------------------------------------------------}
- TMMLEDMode = class(TMMGraphicControl)
- private
- FMode : TMMMode;
- FEnabled : Boolean;
- FLEDColor : TColor;
- FInactiveColor : TColor;
- FDrawInactive : Boolean;
- FBitmap : TBitmap;
- procedure LoadNewResource;
- procedure SetMode(aValue: TMMMode);
- procedure SetLEDColor(aColor: TColor);
- procedure SetInactiveColor(aColor: TColor);
- procedure SetDrawInactive(aValue: Boolean);
- procedure SetEnabled(aValue: Boolean);
- function GetEnabled: Boolean;
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- protected
- procedure Paint; override;
- public
- constructor Create (AOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Events }
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnDragDrop;
- property OnDragOver;
- property OnEndDrag;
- property OnStartDrag;
- property ParentShowHint;
- property ParentColor;
- property ShowHint;
- property Visible;
- property Color;
- property DragCursor;
- property Width default 27;
- property Height default 11;
- property DrawInactive: Boolean read FDrawInactive write SetDrawInactive default True;
- property Enabled: Boolean read GetEnabled write SetEnabled default True;
- property Mode: TMMMode read FMode write SetMode default mMono;
- property LEDColor: TColor read FLEDColor write SetLEDColor default clLime;
- property InactiveColor: TColor read FInactiveColor write SetInactiveColor default clGreen;
- end;
- {-- TMMCustomLEDDigit ------------------------------------------------}
- TMMCustomLEDDigit = class(TMMGraphicControl);
- {-- TMMLEDDigit ------------------------------------------------------}
- TMMLEDDigit = class(TMMCustomLEDDigit)
- private
- FMinValue : integer;
- FMaxValue : integer;
- FValue : Longint;
- FDrawInactive : Boolean;
- FZeroBlank : Boolean;
- FInactiveColor : TColor;
- FLEDColor : TColor;
- FEnabled : Boolean;
- FSize : TMMLEDSize;
- FType : TMMLEDType;
- FCascade : Boolean;
- FConnect : TMMCustomLEDDigit;
- FBitmap : TBitmap;
- FOnRollForward : TNotifyEvent;
- FOnRollBackward: TNotifyEvent;
- procedure LoadNewResource;
- procedure SetEnabled(aValue: Boolean);
- function GetEnabled: Boolean;
- procedure SetMinValue(aValue: integer);
- procedure SetMaxValue(aValue: integer);
- procedure SetValue(aValue: Longint);
- procedure SetDrawInactive(aValue: Boolean);
- procedure SetZeroBlank(aValue: Boolean);
- procedure SetType(aType: TMMLEDType);
- procedure SetSize(aValue: TMMLEDSize);
- procedure SetLEDColor(aColor: TColor);
- procedure SetInactiveColor(aColor: TColor);
- procedure SetCascade(aValue: Boolean);
- procedure SetConnect(aControl: TMMCustomLEDDigit);
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- {$IFDEF BUILD_ACTIVEX}
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- {$ENDIF}
- protected
- procedure Loaded; override;
- procedure Paint; override;
- procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure RollForward; dynamic;
- procedure RollBackward; dynamic;
- public
- constructor Create (AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Increase;
- procedure Decrease;
- published
- { Events }
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnRollForward: TNotifyEvent read FOnRollForward write FOnRollForward;
- property OnRollBackward: TNotifyEvent read FOnRollBackward write FOnRollBackward;
- property ParentShowHint;
- property ParentColor;
- property ShowHint;
- property Visible;
- property Color;
- property Width default 11;
- property Height default 21;
- property Enabled: Boolean read GetEnabled write SetEnabled default True;
- property MinValue: integer read FMinValue write SetMinValue default 0;
- property MaxValue: integer read FMaxValue write SetMaxValue default 9;
- property Value: Longint read FValue write SetValue default 0;
- property DrawInactive: Boolean read FDrawInactive write SetDrawInactive default True;
- property ZeroBlank: Boolean read FZeroBlank write SetZeroBlank default False;
- property InactiveColor: TColor read FInactiveColor write SetInactiveColor default clGreen;
- property LEDColor: TColor read FLEDColor write SetLEDColor default clLime;
- property DigitSize: TMMLEDSize read FSize write SetSize default ls13X21;
- property DisplayType: TMMLEDType read FType write SetType default ltDigit;
- property CascadeValues: Boolean read FCascade write SetCascade default False;
- property Connect: TMMCustomLEDDigit read FConnect write SetConnect;
- end;
- {-- TMMLEDPanel ------------------------------------------------------}
- TMMLEDPanel = class(TMMCustomPanel)
- private
- FMinValue : LongInt;
- FMaxValue : LongInt;
- FValue : Longint;
- FSize : TMMLEDSize;
- FLEDSpace : integer;
- FLEDColor : TColor;
- FInactiveColor: TColor;
- FDrawInactive : Boolean;
- FZeroBlank : Boolean;
- FNumDigits : integer;
- FDigits : array[0..8] of TMMLedDigit;
- FOnChange : TNotifyEvent;
- function CreateDigit: TMMLedDigit;
- procedure CreateAllDigits;
- procedure AdjustSize (var W, H: integer);
- procedure AdjustBounds;
- procedure DestroyAllDigits;
- procedure SetMaxValue(aValue: Longint);
- procedure SetMinValue(aValue: Longint);
- procedure SetNumDigits(aValue: integer);
- procedure SetLEDSpace(aValue: integer);
- procedure SetLEDColor(aValue: TColor);
- procedure SetInactiveColor(aValue: TColor);
- procedure SetDrawInactive(aValue: Boolean);
- procedure SetEnabled(aValue: Boolean);
- function GetEnabled: Boolean;
- procedure SetSize(aValue: TMMLEDSize);
- procedure SetZeroBlank(aValue: Boolean);
- procedure SetValue(aValue: Longint);
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- procedure BtnClick(Sender: TObject);
- procedure BtnDblClick(Sender: TObject);
- procedure MsDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure MsUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure MsMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- protected
- procedure Loaded; override;
- procedure Change; dynamic;
- procedure Changed; override;
- procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
- {$IFDEF WIN32}
- {$IFDEF DELPHI3}
- procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
- {$ELSE}
- procedure GetChildren(Proc: TGetChildProc); override;
- {$ENDIF}
- {$ENDIF}
- public
- constructor Create (aOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Events }
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnResize;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property Bevel;
- property ParentShowHint;
- property ParentColor;
- property ShowHint;
- property Visible;
- property Color default clBlack;
- property DrawInactive: Boolean read FDrawInactive write SetDrawInactive default True;
- property Enabled: Boolean read GetEnabled write SetEnabled default True;
- property LEDColor: TColor read FLEDColor write SetLEDColor default clLime;
- property InactiveColor: TColor read FInactiveColor write SetInactiveColor default clGreen;
- property NumDigits: integer read FNumDigits write SetNumDigits default 2;
- property DigitSize: TMMLEDSize read FSize write SetSize default ls13X21;
- property LEDSpace: integer read FLEDSpace write SetLEDSpace default 1;
- property MaxValue: LongInt read FMaxValue write SetMaxValue default 0;
- property MinValue: LongInt read FMinValue write SetMinValue default 100;
- property TabOrder;
- property TabStop;
- property ZeroBlank: Boolean read FZeroBlank write SetZeroBlank default False;
- property Value: Longint read FValue write SetValue default 0;
- end;
- {-- TMMLEDSpin -------------------------------------------------------}
- TMMLEDSpin = class(TMMWinControl)
- private
- FLEDPanel : TMMLEDPanel;
- FButton : TMMSpinButton;
- FSpace : integer;
- FOnChange : TNotifyEvent;
- FOnUpClick : TNotifyEvent;
- FOnDownClick: TNotifyEvent;
- procedure SetIncrement(aValue: Longint);
- function GetIncrement: Longint;
- procedure SetSpace(aValue: integer);
- procedure SetNumDigits(aValue: integer);
- function GetNumDigits: integer;
- procedure SetLEDSpace(aValue: integer);
- function GetLEDSpace: integer;
- procedure SetColor(aValue: TColor);
- function GetColor: TColor;
- procedure SetLEDColor(aValue: TColor);
- function GetLedColor: TColor;
- procedure SetInactiveColor(aValue: TColor);
- function GetInactiveColor: TColor;
- procedure SetDrawInactive(aValue: Boolean);
- function GetDrawInactive: Boolean;
- procedure SetEnabled(aValue: Boolean);
- function GetEnabled: Boolean;
- procedure SetSize(aValue: TMMLEDSize);
- function GetSize: TMMLEDSize;
- procedure SetZeroBlank(aValue: Boolean);
- function GetZeroBlank: Boolean;
- procedure SetValue(aValue: Longint);
- function GetValue: Longint;
- procedure SetMinValue(aValue: Longint);
- function GetMinValue: Longint;
- procedure SetMaxValue(aValue: Longint);
- function GetMaxValue: Longint;
- procedure SetLEDBevel(aBevel: TMMBevel);
- function GetLEDBevel: TMMBevel;
- procedure SetTabStop(aValue: Boolean);
- function GetTabStop: Boolean;
- function GetUpGlyph: TBitmap;
- function GetDownGlyph: TBitmap;
- procedure SetUpGlyph(Value: TBitmap);
- procedure SetUpNumGlyphs(Value: TNumGlyphs);
- function GetUpNumGlyphs: TNumGlyphs;
- procedure SetDownGlyph(Value: TBitmap);
- procedure SetDownNumGlyphs(Value: TNumGlyphs);
- function GetDownNumGlyphs: TNumGlyphs;
- procedure SetButtonFace(Value: Boolean);
- function GetButtonFace: Boolean;
- procedure SetMiddleButton(Value: Boolean);
- function GetMiddleButton: Boolean;
- procedure SetSpinBevel(aValue: TMMBevel);
- function GetSpinBevel: TMMBevel;
- procedure AdjustSize (var W, H: integer);
- procedure AdjustBounds;
- procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- procedure BtnClick(Sender: TObject);
- procedure BtnDblClick(Sender: TObject);
- procedure MsDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure MsUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure MsMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- protected
- procedure UpClick(Sender: TObject); virtual;
- procedure DownClick(Sender: TObject); virtual;
- procedure ChildChange(Sender: TObject); virtual;
- procedure Change; virtual;
- procedure GetChanged(Sender: TObject); virtual;
- {$IFDEF WIN32}
- {$IFDEF DELPHI3}
- procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
- {$ELSE}
- procedure GetChildren(Proc: TGetChildProc); override;
- {$ENDIF}
- {$ENDIF}
- procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
- procedure Click; override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- property Button: TMMSpinButton read FButton write FButton;
- published
- { Events }
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property OnDownClick: TNotifyEvent read FOnDownClick write FOnDownClick;
- property OnUpClick: TNotifyEvent read FOnUpClick write FOnUpClick;
- property Bevel: TMMBevel read GetLEDBevel write SetLEDBevel;
- property ParentShowHint;
- property ShowHint;
- property Visible;
- property Color: TColor read GetColor write SetColor default clBlack;
- property DrawInactive: Boolean read GetDrawInactive write SetDrawInactive default True;
- property Enabled: Boolean read GetEnabled write SetEnabled;
- property LEDColor: TColor read GetLEDColor write SetLEDColor;
- property InactiveColor: TColor read GetInactiveColor write SetInactiveColor;
- property NumDigits: integer read GetNumDigits write SetNumDigits;
- property DigitSize: TMMLEDSize read GetSize write SetSize;
- property LEDSpace: integer read GetLEDSpace write SetLEDSpace;
- property Space: integer read FSpace write SetSpace default 2;
- property TabStop: Boolean read GetTabStop write setTabStop default True;
- property TabOrder;
- property Increment: Longint read GetIncrement write SetIncrement;
- property ZeroBlank: Boolean read GetZeroBlank write SetZeroBlank;
- property MaxValue: LongInt read GetMaxValue write SetMaxValue;
- property MinValue: LongInt read GetMinValue write SetMinValue;
- property Value: Longint read GetValue write SetValue;
- property DownGlyph: TBitmap read GetDownGlyph write SetDownGlyph;
- property DownNumGlyphs: TNumGlyphs read GetDownNumGlyphs write SetDownNumGlyphs;
- property UpGlyph: TBitmap read GetUpGlyph write SetUpGlyph;
- property UpNumGlyphs: TNumGlyphs read GetUpNumGlyphs write SetUpNumGlyphs;
- property ButtonFace: Boolean read GetButtonFace write SetButtonFace;
- property MiddleButton: Boolean read GetMiddleButton write SetMiddleButton;
- property SpinBevel: TMMBevel read GetSpinBevel write SetSpinBevel;
- end;
- implementation
- const
- RC_NumDigits = 11; { number of digits in the resource file }
- RC_NumSeparators= 4; { number of separators in resource file }
- {$IFDEF WIN32}
- {$R MMLEDS.D32}
- {$ELSE}
- {$R MMLEDS.D16}
- {$ENDIF}
- { these mode resource are available: }
- { 'LCD_MODE' }
- { these digit resources are available: }
- { 'LCD_06X07' }
- { 'LCD_07X11' }
- { 'LCD_08X13' }
- { 'LCD_11X19' }
- { 'LCD_13X20' }
- { 'LCD_13X21' }
- { 'LCD_15X24' }
- { 'LCD_15X25' }
- { 'LCD_18X25' }
- { 'LCD_21X37' }
- { 'LCD_23X41' }
- { these separator resources are available: }
- { 'LCDS_06X07' }
- { 'LCDS_07X11' }
- { 'LCDS_08X13' }
- { 'LCDS_11X19' }
- { 'LCDS_13X20' }
- { 'LCDS_13X21' }
- { 'LCDS_15X24' }
- { 'LCDS_15X25' }
- { 'LCDS_18X25' }
- { 'LCDS_21X37' }
- { 'LCDS_23X41' }
- {-- TMMLED ---------------------------------------------------------------}
- constructor TMMLED.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle - [csSetCaption];
- FBeveledRect := BeveledRect;
- Height := 8;
- Width := 16;
- FEnabled := True;
- Color := clGreen;
- FLEDColor := clLime;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMLED ---------------------------------------------------------------}
- Procedure TMMLED.SetLEDColor(aValue: TColor);
- begin
- if (aValue <> FLEDColor) then
- begin
- FLEDColor := aValue;
- Invalidate;
- end;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- procedure TMMLED.SetEnabled(aValue: Boolean);
- begin
- if (aValue <> FEnabled) then
- begin
- FEnabled := aValue;
- if (Caption = '') then
- DrawLED
- else
- Repaint;
- end;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- procedure TMMLED.SetBounds(aLeft, aTop, aWidth, aHeight: integer);
- begin
- inherited SetBounds(aLeft, aTop, aWidth, aHeight);
- FBeveledRect := BeveledRect;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- Procedure TMMLED.Changed;
- begin
- FBeveledRect := BeveledRect;
- inherited Changed;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- procedure TMMLED.CMTextChanged(var Message: TMessage);
- begin
- Refresh;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- Procedure TMMLED.DrawLED;
- var
- aRect: TRect;
- FontHeight: Integer;
- Text: PChar;
- begin
- {$IFNDEF BUILD_ACTIVEX}
- if (Parent <> nil) and Parent.HandleAllocated then
- {$ENDIF}
- with Canvas do
- begin
- if assigned(FOnPaint) then
- FOnPaint(Self,Canvas,ClientRect)
- else
- begin
- if FEnabled then
- Brush.Color := FLEDColor
- else
- Brush.Color := Color;
- FillRect(FBeveledRect);
- if (Caption <> '') then
- begin
- Text := StrAlloc(Length(Caption)+1);
- try
- StrPCopy(Text, Caption);
- Brush.Style := bsClear;
- Font := Self.Font;
- FontHeight := TextHeight('W');
- with aRect do
- begin
- Top := ((Bottom + Top) - FontHeight) shr 1;
- Bottom := Top + FontHeight;
- end;
- DrawText(Handle, Text, StrLen(Text), aRect, (DT_EXPANDTABS or
- DT_VCENTER) or DT_CENTER);
- finally
- StrDispose(Text);
- end;
- end;
- end;
- end;
- end;
- {-- TMMLED ---------------------------------------------------------------}
- Procedure TMMLED.Paint;
- begin
- inherited Paint; { draw the bevel }
- DrawLED;
- end;
- {== TMMLEDMode ===========================================================}
- constructor TMMLedMode.Create (AOwner: TComponent);
- begin
- FBitmap := TBitmap.Create;
- inherited Create (AOwner);
- Width := 27;
- Height := 11;
- FEnabled := True; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- FMode := mMono;
- FDrawInactive := True;
- FInactiveColor := clGreen;
- LEDColor := clLime;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- destructor TMMLedMode.Destroy;
- begin
- FBitmap.Free;
- inherited Destroy;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLEDMode.LoadNewResource;
- begin { load the resource }
- FBitmap.Handle := LoadBitmap(HInstance, 'LCD_MODE');
- { Change the black/white resource to a colored bitmap }
- ChangeColors(FBitmap,FDrawInactive,FLEDColor,FInactiveColor,Color);
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLedMode.SetMode(aValue: TMMMode);
- begin
- if (aValue <> FMode) then
- begin
- FMode := aValue;
- Invalidate;
- end;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLEDMode.CMColorChanged(var Message: TMessage);
- begin
- LoadNewResource;
- Invalidate;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLEDMode.SetEnabled(aValue: Boolean);
- begin
- {inherited Enabled := aValue;}
- FEnabled := aValue; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- Invalidate;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- function TMMLEDMode.GetEnabled: Boolean;
- begin
- {Result := inherited Enabled;}
- Result := FEnabled; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLedMode.SetLEDColor(aColor: TColor);
- begin
- if (aColor <> FLEDColor) then
- begin
- FLEDColor := aColor;
- LoadNewResource;
- Invalidate;
- end;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLedMode.SetInactiveColor(aColor: TColor);
- begin
- if (aColor <> FInactiveColor) then
- begin
- FInactiveColor := aColor;
- LoadNewResource;
- Invalidate;
- end;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLedMode.SetDrawInactive(aValue: Boolean);
- begin
- if (FDrawInactive <> aValue) then
- begin
- FDrawInactive := aValue;
- LoadNewResource;
- Invalidate;
- end;
- end;
- {-- TMMLEDMode -----------------------------------------------------------}
- procedure TMMLedMode.Paint;
- Var
- MemDC: HDC;
- oldBitmap: HBitmap;
- BitmapOfs: integer;
- begin
- MemDC := CreateCompatibleDC(0);
- oldBitmap := SelectObject(MemDC, FBitmap.Handle);
- BitmapOfs := (FBitmap.Width div 4) * (Ord(FMode)+1) * Ord(Enabled);
- StretchBlt(Canvas.Handle,
- 0, 0, Width, Height,
- MemDC,
- BitmapOfs, 0,
- FBitmap.Width div 4, FBitmap.Height,
- SRCCOPY);
- SelectObject(MemDC, oldBitmap);
- DeleteDC(MemDC);
- end;
- {=========================================================================}
- type
- PDigitBitmap = ^TDigitBitmap;
- TDigitBitmap = record
- FBitmap : TBitmap;
- FType : TMMLEDType;
- FSize : TMMLEDSize;
- FInactive : Boolean;
- FColor : TColor;
- FLEDColor : TColor;
- FInactColor: TColor;
- FCount : integer;
- end;
- TDigitCache = class
- public
- BitmapList: TList;
- constructor Create;
- destructor Destroy; override;
- function Empty: Boolean;
- function LoadBitmap(Typ: TMMLEDType; Size: TMMLEDSize; Inactive: Boolean;
- LEDColor, InactColor,Color: TColor): TBitmap;
- procedure RemoveBitmap(var Bitmap: TBitmap);
- end;
- const
- DigitCache : TDigitCache = nil;
- {== TDigitCache ==========================================================}
- constructor TDigitCache.Create;
- begin
- inherited Create;
- BitmapList := TList.Create;
- end;
- {-- TDigitCache ----------------------------------------------------------}
- destructor TDigitCache.Destroy;
- begin
- BitmapList.Free;
- inherited Destroy;
- end;
- {-- TDigitCache ----------------------------------------------------------}
- function TDigitCache.Empty: Boolean;
- begin
- Result := BitmapList.Count = 0;
- end;
- {-- TDigitCache ----------------------------------------------------------}
- function TDigitCache.LoadBitmap(Typ: TMMLEDType; Size: TMMLEDSize; Inactive: Boolean;
- LEDColor,InactColor,Color: TColor): TBitmap;
- Var
- DigitBitmap: PDigitBitmap;
- Str1: array[0..80] of Char;
- i: integer;
- begin
- if (BitmapList.Count > 0) then
- begin
- { look if we have such a bitmap always in the cache }
- for i := 0 to BitmapList.Count-1 do
- with PDigitBitmap(BitmapList.Items[i])^ do
- begin
- if (Typ = FType) and (Size = FSize) and (Inactive = FInactive) and
- (Color = FColor) and (LEDColor = FLEDColor) and (InactColor = FInactColor) then
- begin
- inc(FCount);
- Result := FBitmap;
- exit;
- end;
- end;
- end;
- { load and prepare a new bitmap resource }
- if (Typ = ltDigit) then
- case Size of
- ls06x07: StrCopy(str1, 'LCD_06X07');
- ls07x11: StrCopy(str1, 'LCD_07X11');
- ls08x13: StrCopy(str1, 'LCD_08X13');
- ls11x19: StrCopy(str1, 'LCD_11X19');
- ls13x20: StrCopy(str1, 'LCD_13X20');
- ls13x21: StrCopy(str1, 'LCD_13X21');
- ls15x24: StrCopy(str1, 'LCD_15X24');
- ls15x25: StrCopy(str1, 'LCD_15X25');
- ls17x29: StrCopy(str1, 'LCD_17X29');
- ls18x25: StrCopy(str1, 'LCD_18X25');
- ls19x33: StrCopy(str1, 'LCD_19X33');
- ls21x37: StrCopy(str1, 'LCD_21X37');
- ls23x41: StrCopy(str1, 'LCD_23X41');
- end
- else
- case Size of
- ls06x07: StrCopy(str1, 'LCDS_06X07');
- ls07x11: StrCopy(str1, 'LCDS_07X11');
- ls08x13: StrCopy(str1, 'LCDS_08X13');
- ls11x19: StrCopy(str1, 'LCDS_11X19');
- ls13x20: StrCopy(str1, 'LCDS_13X20');
- ls13x21: StrCopy(str1, 'LCDS_13X21');
- ls15x24: StrCopy(str1, 'LCDS_15X24');
- ls15x25: StrCopy(str1, 'LCDS_15X25');
- ls17x29: StrCopy(str1, 'LCDS_17X29');
- ls18x25: StrCopy(str1, 'LCDS_18X25');
- ls19x33: StrCopy(str1, 'LCDS_19X33');
- ls21x37: StrCopy(str1, 'LCDS_21X37');
- ls23x41: StrCopy(str1, 'LCDS_23X41');
- end;
- New(DigitBitmap);
- with DigitBitmap^ do
- begin
- FBitmap := TBitmap.Create;
- {$IFDEF WIN32}
- FBitmap.Handle := Windows.LoadBitmap(HInstance, Str1);{ load the resource }
- {$ELSE}
- FBitmap.Handle := WinProcs.LoadBitmap(HInstance, Str1);{ load the resource }
- {$ENDIF}
- { Change the black/white resource to a colored bitmap }
- ChangeColors(FBitmap,Inactive,LEDColor,InactColor,Color);
- FType := Typ;
- FSize := Size;
- FInactive := Inactive;
- FColor := Color;
- FLEDColor := LEDColor;
- FInactColor:= InactColor;
- FCount := 1;
- BitmapList.Add(DigitBitmap);
- Result := FBitmap;
- end;
- end;
- {-- TDigitCache ----------------------------------------------------------}
- procedure TDigitCache.RemoveBitmap(var Bitmap: TBitmap);
- var
- i: integer;
- begin
- if (Bitmap <> nil) and (BitmapList.Count > 0) then
- begin
- for i := 0 to BitmapList.Count-1 do
- with PDigitBitmap(BitmapList.Items[i])^ do
- begin
- if (FBitmap = Bitmap) then
- begin
- dec(FCount);
- if (FCount = 0) then
- begin
- FBitmap.Free;
- Dispose(BitmapList.Items[i]);
- BitmapList.Delete(i);
- Bitmap := nil;
- end;
- break;
- end;
- end;
- end;
- end;
- {== TMMLEDDigit ==========================================================}
- constructor TMMLedDigit.Create (AOwner: TComponent);
- begin
- ControlState := ControlState + [csCreating];
- inherited Create (AOwner);
- ControlStyle := ControlStyle - [csSetCaption];
- FBitmap := nil;
- Width := 11;
- Height := 21;
- FCascade := False;
- FConnect := Nil;
- FEnabled := True; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- FMinValue := 0;
- FMaxValue := 9;
- FDrawInactive := True;
- FZeroBlank := False;
- FType := ltDigit;
- FInactiveColor := clGreen;
- FLEDColor := clLime;
- FSize := ls13x21;
- if (DigitCache = nil) then DigitCache := TDigitCache.Create;
- ControlState := ControlState - [csCreating];
- LoadNewResource;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- destructor TMMLedDigit.Destroy;
- begin
- if (DigitCache <> nil) then
- begin
- DigitCache.RemoveBitmap(FBitmap);
- if DigitCache.Empty then
- begin
- DigitCache.Free;
- DigitCache := nil;
- end;
- end;
- inherited Destroy;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (AComponent = FConnect) then
- FConnect := Nil;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.RollForward;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if assigned(FOnRollForward) then FOnRollForward(self);
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.RollBackward;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if assigned(FOnRollBackward) then FOnRollBackward(self);
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.SetBounds(aLeft, aTop, aWidth, aHeight: integer);
- Var
- DigitWidth: integer;
- begin
- if (FBitmap <> nil) then
- begin
- if (FType = ltDigit) then
- DigitWidth := FBitmap.Width div RC_NumDigits
- else
- DigitWidth := FBitmap.Width div RC_NumSeparators;
- inherited SetBounds(aLeft, aTop, DigitWidth, FBitmap.Height);
- end
- else inherited SetBounds(aLeft, aTop, aWidth, aHeight);
- end;
- {$IFDEF BUILD_ACTIVEX}
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.WMSize(var Message: TWMSize);
- begin
- inherited;
- SetBounds(Left,Top,Width,Height);
- end;
- {$ENDIF}
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.LoadNewResource;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) or
- (csCreating in ControlState) or
- (DigitCache = nil) then exit;
- DigitCache.RemoveBitmap(FBitmap);
- FBitmap := DigitCache.LoadBitmap(FType, FSize, FDrawInactive,
- FLEDColor, FInactiveColor, Color);
- { only a dummy call to change to the new Digit size }
- if (FBitmap <> nil) then
- SetBounds(Left, Top, FBitmap.Width, FBitmap.Height);
- Invalidate;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.SetSize(aValue: TMMLEDSize);
- begin
- if (FSize <> aValue) then
- begin
- FSize := aValue;
- LoadNewResource;
- end;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK1}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetType(aType: TMMLEDType);
- begin
- if (aType <> FType) then
- begin
- FType := aType;
- LoadNewResource;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetDrawInactive(aValue: Boolean);
- begin
- if (FDrawInactive <> aValue) then
- begin
- FDrawInactive := aValue;
- LoadNewResource;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.SetZeroBlank(aValue: Boolean);
- begin
- if (FZeroBlank <> aValue) then
- begin
- FZeroBlank := aValue;
- Invalidate;
- end;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK2}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.CMColorChanged(var Message: TMessage);
- begin
- LoadNewResource;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetLEDColor(aColor: TColor);
- begin
- if (aColor <> FLEDColor) then
- begin
- FLEDColor := aColor;
- LoadNewResource;
- end;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK3}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetInactiveColor(aColor: TColor);
- begin
- if (aColor <> FInactiveColor) then
- begin
- FInactiveColor := aColor;
- LoadNewResource;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetCascade(aValue: Boolean);
- begin
- if (aValue <> FCascade) then FCascade := aValue;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetMinValue(aValue: integer);
- begin
- if (aValue <> FMinValue) AND (aValue >= 0) AND (aValue < 10) then
- begin
- FMinValue := aValue;
- if (FValue < FMinValue) then FValue := FMinValue;
- Invalidate;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetMaxValue(aValue: integer);
- begin
- if (aValue <> FMaxValue) AND (aValue >= 0) AND (aValue < 10) then
- begin
- FMaxValue := aValue;
- if (FValue > FMaxValue) then FValue := FMaxValue;
- Invalidate;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.SetValue(aValue: Longint);
- begin
- if FCascade AND assigned(FConnect) then
- TMMLEDDigit(FConnect).Value := aValue div 10;
- aValue := aValue mod 10;
- if (aValue <> FValue) AND (aValue >= FMinValue) AND (aValue <= FMaxValue) then
- begin
- FValue := aValue;
- Refresh;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.Increase;
- begin
- if (FValue = FMaxValue) then
- begin
- FValue := FMinValue;
- if assigned(FConnect) then TMMLEDDigit(FConnect).Increase;
- RollForward;
- end
- else inc(FValue);
- Invalidate;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.Decrease;
- begin
- if (FValue = FMinValue) then
- begin
- FValue := FMaxValue;
- if assigned(FConnect) then TMMLEDDigit(FConnect).Decrease;
- RollBackward;
- end
- else dec(FValue);
- Invalidate;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.SetEnabled(aValue: Boolean);
- begin
- {inherited Enabled := aValue;}
- if (aValue <> FEnabled) then
- begin
- FEnabled := aValue; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- Invalidate;
- end;
- end;
- {-0- TMMLEDDigit ----------------------------------------------------------}
- function TMMLEDDigit.GetEnabled: Boolean;
- begin
- {Result := inherited Enabled;}
- Result := FEnabled; { !!!!!!!! ev. wieder zu inherited 鋘dern }
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLEDDigit.SetConnect(aControl: TMMCustomLEDDigit);
- begin
- if (aControl <> Self) and (FConnect <> aControl) then
- begin
- FConnect := aControl;
- end;
- end;
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.Loaded;
- begin
- inherited Loaded;
- LoadNewResource;
- end;
-
- {-- TMMLEDDigit ----------------------------------------------------------}
- procedure TMMLedDigit.Paint;
- Var
- MemDC: HDC;
- oldBitmap: HBitmap;
- BitmapOfs: integer;
- Blank: Boolean;
- begin
- if (FBitmap = nil) then exit;
- if FZeroBlank AND (FValue = 0) then Blank := True
- else Blank := False;
- if (FType = ltDigit) then
- BitmapOfs := Width * ((Ord(FValue)+1) * Ord(Enabled)) * Ord(NOT Blank)
- else
- BitmapOfs := Width * (Ord(FType) * Ord(Enabled));
- MemDC := CreateCompatibleDC(0);
- oldBitmap := SelectObject(MemDC, FBitmap.Handle);
- BitBlt(Canvas.Handle,
- 0, 0, Width, Height,
- MemDC,
- BitmapOfs, 0,
- SRCCOPY);
- SelectObject(MemDC, oldBitmap);
- DeleteDC(MemDC);
- end;
- {== TMMLEDPanel ==========================================================}
- constructor TMMLedPanel.Create (aOwner: TComponent);
- begin
- inherited Create (aOwner);
- ControlStyle := ControlStyle - [csAcceptsControls,csSetCaption];
- Color := clBlack;
- FValue := 0;
- FMinValue := 0;
- FMaxValue := 100;
- FInactiveColor := clGreen;
- FLEDColor := clLime;
- FDrawInactive := True;
- FZeroBlank := False;
- FSize := ls13x21;
- FLEDSpace := 1;
- NumDigits := 2;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- destructor TMMLedPanel.Destroy;
- begin
- DestroyAllDigits;
- inherited Destroy;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- {$IFDEF WIN32}
- {$IFDEF DELPHI3}
- procedure TMMLedPanel.GetChildren(Proc: TGetChildProc; Root: TComponent);
- {$ELSE}
- procedure TMMLedPanel.GetChildren(Proc: TGetChildProc);
- {$ENDIF}
- begin
- end;
- {$ENDIF}
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLEDPanel.CMColorChanged(var Message: TMessage);
- {$IFDEF BUILD_ACTIVEX}
- var
- i: integer;
- {$ENDIF}
- begin
- inherited;
- {$IFDEF BUILD_ACTIVEX}
- for i := 0 to FNumDigits-1 do FDigits[i].Color := Color;
- {$ENDIF}
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.Change;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if assigned(FOnChange) then FOnChange(Self);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- function TMMLedPanel.CreateDigit: TMMLedDigit;
- begin
- Result := TMMLedDigit.Create(Self);
- Result.Parent := Self;
- Result.CascadeValues := True;
- Result.Enabled := Enabled;
- Result.DigitSize := FSize;
- {$IFDEF BUILD_ACTIVEX}
- Result.Color := Color;
- {$ENDIF}
- Result.InactiveColor := FInactiveColor;
- Result.LEDColor := FLEDColor;
- Result.DrawInactive := FDrawInactive;
- Result.ParentShowHint := False;
- Result.OnClick := BtnClick;
- Result.OnDblClick := BtnDblClick;
- Result.OnMouseDown := MsDown;
- Result.OnMouseMove := MsMove;
- Result.OnMouseUp := MsUp;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.CreateAllDigits;
- Var
- i: integer;
- begin
- for i := 0 to FNumDigits-1 do
- begin
- FDigits[i] := CreateDigit;
- if i > 0 then FDigits[i-1].Connect := FDigits[i];
- end;
- FDigits[0].ZeroBlank := False;
- FDigits[0].Value := FValue;
- SetZeroBlank(FZeroBlank);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.DestroyAllDigits;
- Var
- i: integer;
- begin
- for i := 0 to FNumDigits-1 do
- begin
- FDigits[i].Free;
- FDigits[i] := Nil;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.BtnClick(Sender: TObject);
- begin
- Click;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.BtnDblClick(Sender: TObject);
- begin
- DblClick;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.MsDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- MouseDown(Button, Shift, X, Y);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.MsUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- MouseUp(Button, Shift, X, Y);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.MsMove(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- MouseMove(Shift, X, Y);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetBounds(aLeft, aTop, aWidth, aHeight: Integer);
- var
- W, H: Integer;
- begin
- W := aWidth;
- H := aHeight;
- AdjustSize (W, H);
- inherited SetBounds (aLeft, aTop, W, H);
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.AdjustSize (Var W, H: Integer);
- Var
- i: integer;
- aLeft: integer;
- begin
- if (FDigits[0] = Nil) or (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- W := (((FDigits[0].Width + FLEDSpace) * FNumDigits) + 2 * BevelExtend) - FLEDSpace;
- H := FDigits[0].Height + 2 * BevelExtend;
- aLeft := BevelExtend;
- for i := FNumDigits-1 downTo 0 do
- begin
- FDigits[i].SetBounds (aLeft,BevelExtend, FDigits[0].Width, FDigits[0].Height);
- inc(aLeft, FDigits[0].Width + FLEDSpace);
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.AdjustBounds;
- var
- W, H: Integer;
- begin
- W := Width;
- H := Height;
- AdjustSize (W, H);
- if (W <> Width) or (H <> Height) then
- inherited SetBounds(Left, Top, W, H)
- else Invalidate;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.WMSize(var Message: TWMSize);
- begin
- inherited;
- AdjustBounds;
- Message.Result := 0;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLEDPanel.Changed;
- begin
- AdjustBounds;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetNumDigits(aValue: integer);
- begin
- if (aValue <> FNumDigits) AND (aValue > 0) AND (aValue < 10) then
- begin
- DestroyAllDigits;
- FNumDigits := aValue;
- CreateAllDigits;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetLEDSpace(aValue: integer);
- begin
- if (aValue <> FLEDSpace) AND (aValue > 0) then
- begin
- FLEDSpace := aValue;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetLEDColor(aValue: TColor);
- Var
- i: integer;
- begin
- if (aValue <> FLEDColor) then
- begin
- FLEDColor := aValue;
- for i := 0 to FNumDigits-1 do
- FDigits[i].LEDColor := FLEDColor;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetInactiveColor(aValue: TColor);
- Var
- i: integer;
- begin
- if (aValue <> FInactiveColor) then
- begin
- FInactiveColor := aValue;
- for i := 0 to FNumDigits-1 do
- FDigits[i].InactiveColor := FInactiveColor;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetDrawInactive(aValue: Boolean);
- Var
- i: integer;
- begin
- if (FDrawInactive <> aValue) then
- begin
- FDrawInactive := aValue;
- for i := 0 to FNumDigits-1 do
- FDigits[i].DrawInactive := FDrawInactive;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetEnabled(aValue: Boolean);
- Var
- i: integer;
- begin
- if (aValue <> inherited Enabled) then
- begin
- inherited Enabled := aValue;
- for i := 0 to FNumDigits-1 do
- FDigits[i].Enabled := Enabled;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- function TMMLEDPanel.GetEnabled: Boolean;
- begin
- Result := inherited Enabled;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetZeroBlank(aValue: Boolean);
- Var
- i: Longint;
- j: integer;
- begin
- FZeroBlank := aValue;
- if FZeroBlank then
- begin
- i := 10;
- j := 1;
- while (i < abs(FValue)) AND (j < FNumDigits-1) do
- begin
- FDigits[j].ZeroBlank := False;
- inc(j);
- i := i * 10;
- end;
- for j := j to FNumDigits-1 do FDigits[j].ZeroBlank := True;
- end
- else for i := 1 to FNumDigits-1 do FDigits[i].ZeroBlank := False;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLEDPanel.SetSize(aValue: TMMLEDSize);
- Var
- i: integer;
- begin
- if (FSize <> aValue) then
- begin
- FSize := aValue;
- for i := 0 to FNumDigits-1 do
- FDigits[i].DigitSize := FSize;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetValue(aValue: Longint);
- begin
- aValue := MinMax(aValue, FMinValue, FMaxValue);
- if (aValue <> FValue) then
- begin
- FValue := aValue;
- SetZeroBlank(FZeroBlank);
- FDigits[0].Value := abs(FValue);
- if (FValue < 0) then FDigits[FNumDigits-1].DisplayType := ltMinus
- else FDigits[FNumDigits-1].DisplayType := ltDigit;
- Change;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetMinValue(aValue: Longint);
- begin
- if (aValue <> FMinValue) then
- begin
- FMinValue := aValue;
- if (FValue < FMinValue) then Value := FMinValue;
- Invalidate;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.SetMaxValue(aValue: Longint);
- begin
- if (aValue <> FMaxValue) then
- begin
- FMaxValue := aValue;
- if (FValue > FMaxValue) then Value := FMaxValue;
- Invalidate;
- end;
- end;
- {-- TMMLEDPanel ----------------------------------------------------------}
- procedure TMMLedPanel.Loaded;
- begin
- inherited Loaded;
- AdjustBounds;
- end;
- {== TMMLEDSpin ===========================================================}
- constructor TMMLEDSpin.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle - [csSetCaption];
- FButton := TMMSpinButton.Create(Self);
- FLEDPanel := TMMLEDPanel.Create(Self);
- FLEDPanel.Parent := Self;
- FLEDPanel.TabStop := False;
- FLEDPanel.OnClick := BtnClick;
- FLEDPanel.OnDblClick := BtnDblClick;
- FLEDPanel.OnMouseDown := MsDown;
- FLEDPanel.OnMouseMove := MsMove;
- FLEDPanel.OnMouseUp := MsUp;
- FLEDPanel.OnChange := ChildChange;
- FLEDPanel.Color := clBlack;
- FLEDPanel.ParentShowHint := False;
- FButton.Parent := Self;
- FButton.FocusControl := Self;
- FButton.Bevel.OnChange := GetChanged;
- FButton.TabOrder := 0;
- FButton.OnUpClick := UpClick;
- FButton.OnDownClick := DownClick;
- FButton.OnChange := ChildChange;
- FButton.ParentShowHint := False;
- ParentColor := True;
- TabStop := True;
- FSpace := 2;
- FLEDPanel.OnResize := GetChanged;
- AdjustBounds;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- destructor TMMLEDSpin.Destroy;
- begin
- FLEDPanel.OnResize := Nil;
- FLEDPanel.Free;
- FButton.Free;
- inherited Destroy;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- {$IFDEF WIN32}
- {$IFDEF DELPHI3}
- procedure TMMLEDSpin.GetChildren(Proc: TGetChildProc; Root: TComponent);
- {$ELSE}
- procedure TMMLEDSpin.GetChildren(Proc: TGetChildProc);
- {$ENDIF}
- begin
- end;
- {$ENDIF}
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.WMSetFocus(var Message: TWMSetFocus);
- begin
- if TabStop AND FButton.CanFocus AND (GetFocus <> FButton.Handle) then
- FButton.SetFocus;
- Message.Result := 0;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.Click;
- begin
- if TabStop AND FButton.CanFocus AND (GetFocus <> FButton.Handle) then
- FButton.SetFocus;
- inherited Click;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.BtnClick(Sender: TObject);
- begin
- Click;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.BtnDblClick(Sender: TObject);
- begin
- DblClick;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.MsDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- MouseDown(Button, Shift, X, Y);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.MsUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- MouseUp(Button, Shift, X, Y);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.MsMove(Sender: TObject; Shift: TShiftState;
- X, Y: Integer);
- begin
- MouseMove(Shift, X, Y);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetTabStop(aValue: Boolean);
- begin
- inherited TabStop := aValue;
- FButton.TabStop := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetTabStop: Boolean;
- begin
- Result := inherited TabStop;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.AdjustSize (var W, H: integer);
- begin
- FButton.Height := 1; { reset the SpinButton size standard }
- FButton.Width := 1;
- W := FLEDPanel.Width + FButton.Width + FSpace;
- H := Max(FButton.Height,FLEDPanel.Height);
- FButton.SetBounds(W-FButton.Width,0,FButton.Width,H);
- FLEDPanel.SetBounds(0,H-FLEDPanel.Height,FLEDPanel.Width,FLEDPanel.Height);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.AdjustBounds;
- var
- W, H: Integer;
- begin
- W := Width;
- H := Height;
- AdjustSize (W, H);
- if (W <> Width) or (H <> Height) then
- inherited SetBounds(Left, Top, W, H)
- else Invalidate;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.WMSize(var Message: TWMSize);
- begin
- inherited;
- AdjustBounds;
- Message.Result := 0;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLedSpin.SetBounds(aLeft, aTop, aWidth, aHeight: Integer);
- var
- W, H: Integer;
- begin
- W := aWidth;
- H := aHeight;
- AdjustSize (W, H);
- inherited SetBounds (aLeft, aTop, W, H);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.GetChanged;
- begin
- AdjustBounds;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.UpClick(Sender: TObject);
- begin
- if Assigned(FOnUpClick) then FOnUpClick(Self);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.DownClick(Sender: TObject);
- begin
- if Assigned(FOnDownClick) then FOnDownClick(Self);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.ChildChange(Sender: TObject);
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if Sender = FButton then
- Value := FButton.Value;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.Change;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if assigned(FOnChange) then FOnChange(Self);
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetSpace(aValue: integer);
- begin
- if (aValue <> FSpace) then
- begin
- FSpace := aValue;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetLEDBevel(aBevel: TMMBevel);
- begin
- FLEDPanel.Bevel := aBevel;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetLEDBevel: TMMBevel;
- begin
- Result := FLEDPanel.Bevel;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetNumDigits(aValue: integer);
- begin
- FLEDPanel.NumDigits := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetNumDigits: integer;
- begin
- Result := FLEDPanel.NumDigits;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetLEDSpace(aValue: integer);
- begin
- FLEDPanel.LEDSpace := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetLEDSpace: integer;
- begin
- Result := FLEDPanel.LEDSpace;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLedSpin.SetColor(aValue: TColor);
- begin
- FLEDPanel.Color := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetColor: TColor;
- begin
- Result := FLEDPanel.Color;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetLEDColor(aValue: TColor);
- begin
- FLEDPanel.LEDColor := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetLEDColor: TColor;
- begin
- Result := FLEDPanel.LEDColor;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetInactiveColor(aValue: TColor);
- begin
- FLEDPanel.InactiveColor := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetInactiveColor: TColor;
- begin
- Result := FLEDPanel.InactiveColor;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetDrawInactive(aValue: Boolean);
- begin
- FLEDPanel.DrawInactive := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetDrawInactive: Boolean;
- begin
- Result := FLEDPanel.DrawInactive;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetEnabled(aValue: Boolean);
- begin
- inherited Enabled := aValue;
- FButton.Enabled := aValue;
- FLEDPanel.Enabled := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetEnabled: Boolean;
- begin
- Result := inherited Enabled;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetSize(aValue: TMMLEDSize);
- begin
- FLEDPanel.DigitSize := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetSize: TMMLEDSize;
- begin
- Result := FLEDPanel.DigitSize;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetZeroBlank(aValue: Boolean);
- begin
- FLEDPanel.ZeroBlank := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetZeroBlank: Boolean;
- begin
- Result := FLEDPanel.ZeroBlank;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetIncrement(aValue: Longint);
- begin
- FButton.Increment := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetIncrement: Longint;
- begin
- Result := FButton.Increment;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetUpGlyph(Value: TBitmap);
- begin
- FButton.UpGlyph := Value;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetUpGlyph: TBitmap;
- begin
- Result := FButton.UpGlyph;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetDownGlyph(Value: TBitmap);
- begin
- FButton.DownGlyph := Value;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetDownGlyph: TBitmap;
- begin
- Result := FButton.DownGlyph;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetDownNumGlyphs(Value: TNumGlyphs);
- begin
- FButton.DownNumGlyphs := Value;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetDownNumGlyphs: TNumGlyphs;
- begin
- Result := FButton.DownNumGlyphs;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetUpNumGlyphs(Value: TNumGlyphs);
- begin
- FButton.UpNumGlyphs := Value;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetUpNumGlyphs: TNumGlyphs;
- begin
- Result := FButton.UpNumGlyphs;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetButtonFace(Value: Boolean);
- begin
- if (Value <> FButton.ButtonFace) then
- begin
- FButton.ButtonFace := Value;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetButtonFace: Boolean;
- begin
- Result := FButton.ButtonFace;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetMiddleButton(Value: Boolean);
- begin
- if (Value <> FButton.MiddleButton) then
- begin
- FButton.MiddleButton := Value;
- AdjustBounds;
- end;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetMiddleButton: Boolean;
- begin
- Result := FButton.MiddleButton;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetSpinBevel(aValue: TMMBevel);
- begin
- FButton.Bevel := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetSpinBevel: TMMBevel;
- begin
- Result := FButton.Bevel;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetMinValue(aValue: Longint);
- begin
- FLEDPanel.MinValue := aValue;
- FButton.MinValue := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetMinValue: Longint;
- begin
- Result := FLEDPanel.MinValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetMaxValue(aValue: Longint);
- begin
- FLEDPanel.MaxValue := aValue;
- FButton.MaxValue := aValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetMaxValue: Longint;
- begin
- Result := FLEDPanel.MaxValue;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- procedure TMMLEDSpin.SetValue(aValue: Longint);
- begin
- if (aValue <> FLEDPanel.Value) And Enabled then
- begin
- aValue := MinMax(aValue, MinValue, MaxValue);
- FLEDPanel.Value := aValue;
- FButton.Value := aValue;
- Change;
- end;
- end;
- {-- TMMLEDSpin -----------------------------------------------------------}
- function TMMLEDSpin.GetValue: Longint;
- begin
- Result := FLEDPanel.Value;
- end;
- end.