From: Robert M. <mar...@us...> - 2003-12-31 17:39:29
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1:/tmp/cvs-serv30963/JVCL3/run Modified Files: JvgSpeedButton.pas Log Message: the last commit of 2003 is of course a style cleaning ;-) May the Source be with you also in 2004 Index: JvgSpeedButton.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvgSpeedButton.pas,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** JvgSpeedButton.pas 28 Dec 2003 16:19:10 -0000 1.8 --- JvgSpeedButton.pas 31 Dec 2003 17:39:24 -0000 1.9 *************** *** 33,73 **** uses ! Windows, Messages, Classes, Controls, Graphics, JvgTypes, JvgCommClasses, JvgUtils, ! ExtCtrls, Buttons, JVCLVer, StdCtrls, Forms; type TJvgSpeedButton = class(TSpeedButton) private FCanvas: TControlCanvas; ! fMouseEnter: boolean; FColor: TColor; ! IsDown: boolean; FControl: TControl; ! FFrame: boolean; FCaptionLabel: TLabel; ! FDefaultStyle: boolean; FModalResult: TModalResult; FFrameColor: TColor; FActiveColor: TColor; ! FAboutJVCL: TJVCLAboutInfo; ! procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER; ! procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE; function GetCanvas: TCanvas; procedure SetControl(const Value: TControl); ! procedure SetFrame(const Value: boolean); procedure SetCaptionLabel(const Value: TLabel); ! procedure SetDefaultStyle(const Value: boolean); procedure SetColor(const Value: TColor); procedure SetFrameColor(const Value: TColor); protected ! { (rb) Better respond to CM_ENABLEDCHANGED, but don't know if that works ! on D5,D6 } ! procedure SetEnabled(Value: boolean); override; ! function GetEnabled: boolean; override; procedure Paint; override; ! procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: ! integer); override; ! procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); ! override; public constructor Create(AOwner: TComponent); override; --- 33,71 ---- uses ! Windows, Messages, Classes, Controls, Graphics, ! ExtCtrls, Buttons, StdCtrls, Forms, ! JVCLVer, JvgTypes, JvgCommClasses, JvgUtils; type TJvgSpeedButton = class(TSpeedButton) private + FAboutJVCL: TJVCLAboutInfo; FCanvas: TControlCanvas; ! FMouseEnter: Boolean; FColor: TColor; ! FIsDown: Boolean; FControl: TControl; ! FFrame: Boolean; FCaptionLabel: TLabel; ! FDefaultStyle: Boolean; FModalResult: TModalResult; FFrameColor: TColor; FActiveColor: TColor; ! procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER; ! procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE; function GetCanvas: TCanvas; procedure SetControl(const Value: TControl); ! procedure SetFrame(const Value: Boolean); procedure SetCaptionLabel(const Value: TLabel); ! procedure SetDefaultStyle(const Value: Boolean); procedure SetColor(const Value: TColor); procedure SetFrameColor(const Value: TColor); protected ! { (rb) Better respond to CM_ENABLEDCHANGED, but don't know if that works on D5,D6 } ! procedure SetEnabled(Value: Boolean); override; ! function GetEnabled: Boolean; override; procedure Paint; override; ! procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; ! procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; public constructor Create(AOwner: TComponent); override; *************** *** 76,89 **** property Canvas: TCanvas read GetCanvas; published ! property AboutJVCL: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored ! false; property Color: TColor read FColor write SetColor; property ActiveColor: TColor read FActiveColor write FActiveColor; property Control: TControl read FControl write SetControl; property CaptionLabel: TLabel read FCaptionLabel write SetCaptionLabel; ! property Frame: boolean read FFrame write SetFrame default true; property FrameColor: TColor read FFrameColor write SetFrameColor; ! property DefaultStyle: boolean read FDefaultStyle write SetDefaultStyle; ! property Enabled: boolean read GetEnabled write SetEnabled; property ModalResult: TModalResult read FModalResult write FModalResult; end; --- 74,86 ---- property Canvas: TCanvas read GetCanvas; published ! property AboutJVCL: TJVCLAboutInfo read FAboutJVCL write FAboutJVCL stored False; property Color: TColor read FColor write SetColor; property ActiveColor: TColor read FActiveColor write FActiveColor; property Control: TControl read FControl write SetControl; property CaptionLabel: TLabel read FCaptionLabel write SetCaptionLabel; ! property Frame: Boolean read FFrame write SetFrame default True; property FrameColor: TColor read FFrameColor write SetFrameColor; ! property DefaultStyle: Boolean read FDefaultStyle write SetDefaultStyle; ! property Enabled: Boolean read GetEnabled write SetEnabled; property ModalResult: TModalResult read FModalResult write FModalResult; end; *************** *** 94,99 **** FStyleActive: TJvgSpeedButtonStyle; FStylePushed: TJvgSpeedButtonStyle; ! procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER; ! procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE; procedure SetColor(const Value: TColor); procedure SetActiveColor(const Value: TColor); --- 91,96 ---- FStyleActive: TJvgSpeedButtonStyle; FStylePushed: TJvgSpeedButtonStyle; ! procedure CMMouseEnter(var Msg: TMessage); message CM_MOUSEENTER; ! procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE; procedure SetColor(const Value: TColor); procedure SetActiveColor(const Value: TColor); *************** *** 102,122 **** function GetActiveColor: TColor; function GetColor: TColor; protected procedure Paint; override; - procedure OnChanged(Sender: TObject); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Style: TJvgSpeedButtonStyle read FStyle write FStyle; property StyleActive: TJvgSpeedButtonStyle read FStyleActive write FStyleActive; property StylePushed: TJvgSpeedButtonStyle read FStylePushed write FStylePushed; property Font: TFont read GetFont write SetFont; - property Color: TColor read GetColor write SetColor stored false; - property ActiveColor: TColor read GetActiveColor write SetActiveColor stored false; end; implementation constructor TJvgSpeedButton.Create(AOwner: TComponent); begin --- 99,121 ---- function GetActiveColor: TColor; function GetColor: TColor; + procedure ButtonChanged(Sender: TObject); protected procedure Paint; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; published + property ActiveColor: TColor read GetActiveColor write SetActiveColor stored False; + property Color: TColor read GetColor write SetColor stored False; property Style: TJvgSpeedButtonStyle read FStyle write FStyle; property StyleActive: TJvgSpeedButtonStyle read FStyleActive write FStyleActive; property StylePushed: TJvgSpeedButtonStyle read FStylePushed write FStylePushed; property Font: TFont read GetFont write SetFont; end; implementation + //=== TJvgSpeedButton ======================================================== + constructor TJvgSpeedButton.Create(AOwner: TComponent); begin *************** *** 127,131 **** FColor := IncColor(GetSysColor(COLOR_BTNFACE), 30); FActiveColor := IncColor(FColor, 10); ! FFrame := true; end; --- 126,130 ---- FColor := IncColor(GetSysColor(COLOR_BTNFACE), 30); FActiveColor := IncColor(FColor, 10); ! FFrame := True; end; *************** *** 154,170 **** R := ClientRect; ! if IsDown and fMouseEnter then BevelOuter := bvLowered else BevelOuter := bvRaised; ! if Flat and not IsDown then BevelOuter := bvNone; if FFrame then InflateRect(R, -1, -1); ! dec(R.Right); ! dec(R.Bottom); ! DrawBoxEx(FCanvas.Handle, R, ALLGLSIDES, bvNone, BevelOuter, false, ! iif(fMouseEnter, ActiveColor, Color), false); if Transparent then --- 153,169 ---- R := ClientRect; ! if FIsDown and FMouseEnter then BevelOuter := bvLowered else BevelOuter := bvRaised; ! if Flat and not FIsDown then BevelOuter := bvNone; if FFrame then InflateRect(R, -1, -1); ! Dec(R.Right); ! Dec(R.Bottom); ! DrawBoxEx(FCanvas.Handle, R, ALLGLSIDES, bvNone, BevelOuter, False, ! IIF(FMouseEnter, ActiveColor, Color), False); if Transparent then *************** *** 179,183 **** Inc(R.Left, Glyph.Width); ! if IsDown then OffsetRect(R, 1, 1); DrawText(FCanvas.Handle, PChar(Caption), Length(Caption), R, DT_SINGLELINE or --- 178,182 ---- Inc(R.Left, Glyph.Width); ! if FIsDown then OffsetRect(R, 1, 1); DrawText(FCanvas.Handle, PChar(Caption), Length(Caption), R, DT_SINGLELINE or *************** *** 185,189 **** R := ClientRect; ! FCanvas.Brush.Color := 0; if FFrame then begin --- 184,188 ---- R := ClientRect; ! FCanvas.Brush.Color := clBlack; if FFrame then begin *************** *** 194,217 **** if Assigned(Glyph) then CreateBitmapExt(FCanvas.Handle, Glyph, ClientRect, (Width - Glyph.Width - ! FCanvas.TextWidth(Caption)) div 2 + integer(IsDown) - 1 - Spacing, 1 + ! (Height - Glyph.Height) div 2 + integer(IsDown), fwoNone, fdsDefault, ! true, GetTransparentColor(Glyph, ftcLeftBottomPixel), 0); end; ! procedure TJvgSpeedButton.CMMouseEnter(var Message: TMessage); begin inherited; ! fMouseEnter := true; ! if IsDown or (Color <> ActiveColor) then Invalidate; end; ! procedure TJvgSpeedButton.CMMouseLeave(var Message: TMessage); begin inherited; ! fMouseEnter := false; ! if IsDown or (Color <> ActiveColor) then Invalidate; end; --- 193,216 ---- if Assigned(Glyph) then CreateBitmapExt(FCanvas.Handle, Glyph, ClientRect, (Width - Glyph.Width - ! FCanvas.TextWidth(Caption)) div 2 + Integer(FIsDown) - 1 - Spacing, 1 + ! (Height - Glyph.Height) div 2 + Integer(FIsDown), fwoNone, fdsDefault, ! True, GetTransparentColor(Glyph, ftcLeftBottomPixel), 0); end; ! procedure TJvgSpeedButton.CMMouseEnter(var Msg: TMessage); begin inherited; ! FMouseEnter := True; ! if FIsDown or (Color <> ActiveColor) then Invalidate; end; ! procedure TJvgSpeedButton.CMMouseLeave(var Msg: TMessage); begin inherited; ! FMouseEnter := False; ! if FIsDown or (Color <> ActiveColor) then Invalidate; end; *************** *** 222,238 **** end; ! procedure TJvgSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, ! Y: integer); begin ! inherited; ! IsDown := true; Invalidate; end; procedure TJvgSpeedButton.MouseUp(Button: TMouseButton; Shift: TShiftState; ! X, Y: integer); begin ! inherited; ! IsDown := false; Invalidate; end; --- 221,237 ---- end; ! procedure TJvgSpeedButton.MouseDown(Button: TMouseButton; Shift: TShiftState; ! X, Y: Integer); begin ! inherited MouseDown(Button, Shift, X, Y); ! FIsDown := True; Invalidate; end; procedure TJvgSpeedButton.MouseUp(Button: TMouseButton; Shift: TShiftState; ! X, Y: Integer); begin ! inherited MouseUp(Button, Shift, X, Y); ! FIsDown := False; Invalidate; end; *************** *** 242,246 **** Form: TCustomForm; begin ! inherited; if ModalResult = mrNone then Exit; --- 241,245 ---- Form: TCustomForm; begin ! inherited Click; if ModalResult = mrNone then Exit; *************** *** 255,271 **** end; ! procedure TJvgSpeedButton.SetFrame(const Value: boolean); begin ! FFrame := Value; ! Invalidate; end; procedure TJvgSpeedButton.SetCaptionLabel(const Value: TLabel); begin ! FCaptionLabel := Value; ! Invalidate; end; ! procedure TJvgSpeedButton.SetDefaultStyle(const Value: boolean); begin FDefaultStyle := Value; --- 254,276 ---- end; ! procedure TJvgSpeedButton.SetFrame(const Value: Boolean); begin ! if FFrame <> Value then ! begin ! FFrame := Value; ! Invalidate; ! end; end; procedure TJvgSpeedButton.SetCaptionLabel(const Value: TLabel); begin ! if FCaptionLabel <> Value then ! begin ! FCaptionLabel := Value; ! Invalidate; ! end; end; ! procedure TJvgSpeedButton.SetDefaultStyle(const Value: Boolean); begin FDefaultStyle := Value; *************** *** 273,277 **** end; ! procedure TJvgSpeedButton.SetEnabled(Value: boolean); begin inherited SetEnabled(Value); --- 278,282 ---- end; ! procedure TJvgSpeedButton.SetEnabled(Value: Boolean); begin inherited SetEnabled(Value); *************** *** 280,284 **** end; ! function TJvgSpeedButton.GetEnabled: boolean; begin Result := inherited GetEnabled; --- 285,289 ---- end; ! function TJvgSpeedButton.GetEnabled: Boolean; begin Result := inherited GetEnabled; *************** *** 287,314 **** procedure TJvgSpeedButton.SetColor(const Value: TColor); begin ! FColor := Value; ! Invalidate; end; procedure TJvgSpeedButton.SetFrameColor(const Value: TColor); begin ! FFrameColor := Value; ! Invalidate; end; ! { TJvgExtSpeedButton } ! constructor TJvgExtSpeedButton.Create( AOwner : TComponent ); begin ! inherited; FStyle := TJvgSpeedButtonStyle.Create; FStyleActive := TJvgSpeedButtonStyle.Create; FStylePushed := TJvgSpeedButtonStyle.Create; ! FStyle.OnChanged := OnChanged; ! FStyleActive.OnChanged := OnChanged; ! FStylePushed.OnChanged := OnChanged; //..defaults ! FStyle.Color := incColor(clBtnFace, 30); FStyleActive.Color := IncColor(FStyle.Color, 10); FStylePushed.Color := DecColor(FStyle.Color, 10); --- 292,325 ---- procedure TJvgSpeedButton.SetColor(const Value: TColor); begin ! if FColor <> Value then ! begin ! FColor := Value; ! Invalidate; ! end; end; procedure TJvgSpeedButton.SetFrameColor(const Value: TColor); begin ! if FFrameColor <> Value then ! begin ! FFrameColor := Value; ! Invalidate; ! end; end; ! //=== TJvgExtSpeedButton ===================================================== ! constructor TJvgExtSpeedButton.Create(AOwner: TComponent); begin ! inherited Create(AOwner); FStyle := TJvgSpeedButtonStyle.Create; FStyleActive := TJvgSpeedButtonStyle.Create; FStylePushed := TJvgSpeedButtonStyle.Create; ! FStyle.OnChanged := ButtonChanged; ! FStyleActive.OnChanged := ButtonChanged; ! FStylePushed.OnChanged := ButtonChanged; //..defaults ! FStyle.Color := IncColor(clBtnFace, 30); FStyleActive.Color := IncColor(FStyle.Color, 10); FStylePushed.Color := DecColor(FStyle.Color, 10); *************** *** 323,327 **** FStyleActive.Free; FStylePushed.Free; ! inherited; end; --- 334,338 ---- FStyleActive.Free; FStylePushed.Free; ! inherited Destroy; end; *************** *** 329,377 **** var R: TRect; ! offset: integer; ! _Style: TJvgSpeedButtonStyle; function TextStyle: TglTextStyle; begin ! if Enabled then Result := _Style.TextStyle else Result := fstPushed; end; begin if DefaultStyle then begin inherited Paint; ! exit; end; R := ClientRect; ! if IsDown and fMouseEnter then ! _Style := StylePushed ! else if fMouseEnter then ! _Style := StyleActive else ! _Style := Style; ! if FFrame then InflateRect(R, -1, -1); ! dec(R.Right); dec(R.Bottom); ! with _Style do begin ! R := DrawBoxEx(Canvas.Handle, R, Bevel.Sides, Bevel.Inner, Bevel.Outer, Bevel.Bold, Color, Gradient.Active ); if Gradient.Active then begin ! inc(R.Right); inc(R.Bottom); ! Gradient.Draw(Canvas.Handle, R, integer(psSolid), 1); ! dec(R.Right); dec(R.Bottom); end; end; if not Glyph.Empty then ! inc(R.Left, Glyph.Width); ! Canvas.Font.Assign(_Style.Font); ! if IsDown then offset := 1 else offset := 0; ! ExtTextOutExt(Canvas.Handle, R.Left+offset+(R.Right - R.Left -Canvas.TextWidth(Caption)) div 2, R.Top+offset+(R.Bottom - R.Top - Canvas.TextHeight(Caption)) div 2, R, Caption, ! TextStyle, false { fcoDelineatedText in Options}, ! false, _Style.Font.Color, _Style.DelineateColor, ! _Style.HighlightColor, _Style.ShadowColor, ! nil, _Style.TextGradient, _Style.Font ); R := ClientRect; --- 340,402 ---- var R: TRect; ! Offset: Integer; ! LStyle: TJvgSpeedButtonStyle; ! function TextStyle: TglTextStyle; begin ! if Enabled then ! Result := LStyle.TextStyle ! else ! Result := fstPushed; end; + begin if DefaultStyle then begin inherited Paint; ! Exit; end; R := ClientRect; ! if FIsDown and FMouseEnter then ! LStyle := StylePushed else ! if FMouseEnter then ! LStyle := StyleActive ! else ! LStyle := Style; ! if FFrame then ! InflateRect(R, -1, -1); ! Dec(R.Right); ! Dec(R.Bottom); ! with LStyle do begin ! R := DrawBoxEx(Canvas.Handle, R, Bevel.Sides, Bevel.Inner, Bevel.Outer, Bevel.Bold, Color, Gradient.Active); if Gradient.Active then begin ! Inc(R.Right); ! Inc(R.Bottom); ! Gradient.Draw(Canvas.Handle, R, Integer(psSolid), 1); ! Dec(R.Right); ! Dec(R.Bottom); end; end; if not Glyph.Empty then ! Inc(R.Left, Glyph.Width); ! Canvas.Font.Assign(LStyle.Font); ! if FIsDown then ! Offset := 1 ! else ! Offset := 0; ! ExtTextOutExt(Canvas.Handle, R.Left + Offset + (R.Right - R.Left - Canvas.TextWidth(Caption)) div 2, R.Top + Offset + ! (R.Bottom - R.Top - Canvas.TextHeight(Caption)) div 2, R, Caption, ! TextStyle, False { fcoDelineatedText in Options}, ! False, LStyle.Font.Color, LStyle.DelineateColor, ! LStyle.HighlightColor, LStyle.ShadowColor, ! nil, LStyle.TextGradient, LStyle.Font); R := ClientRect; *************** *** 384,426 **** if Assigned(Glyph) then ! CreateBitmapExt( Canvas.Handle, Glyph, ClientRect, (Width - Glyph.Width - Canvas.TextWidth(Caption))div 2 + integer(IsDown) - 1-Spacing, 1+(Height - Glyph.Height)div 2 + integer(IsDown), fwoNone, fdsDefault, ! true, GetTransparentColor(Glyph, ftcLeftBottomPixel), 0 ); ! end; ! procedure TJvgExtSpeedButton.CMMouseEnter(var Message: TMessage); begin inherited; ! if not Enabled then exit; ! fMouseEnter := true; ! Paint; end; ! procedure TJvgExtSpeedButton.CMMouseLeave(var Message: TMessage); begin inherited; ! if not Enabled then exit; ! fMouseEnter := false; ! Paint; end; ! ! procedure TJvgExtSpeedButton.OnChanged(Sender: TObject); begin ! if csLoading in ComponentState then exit; ! Invalidate; end; procedure TJvgExtSpeedButton.SetColor(const Value: TColor); begin ! Style.Color := Value; ! Invalidate; end; procedure TJvgExtSpeedButton.SetActiveColor(const Value: TColor); begin ! StyleActive.Color := Value; ! Invalidate; end; --- 409,460 ---- if Assigned(Glyph) then ! CreateBitmapExt(Canvas.Handle, Glyph, ClientRect, (Width - Glyph.Width - Canvas.TextWidth(Caption)) div 2 + ! Integer(FIsDown) - 1 - Spacing, 1 + (Height - Glyph.Height) div 2 + Integer(FIsDown), fwoNone, fdsDefault, ! True, GetTransparentColor(Glyph, ftcLeftBottomPixel), 0); end; ! procedure TJvgExtSpeedButton.CMMouseEnter(var Msg: TMessage); begin inherited; ! if Enabled then ! begin ! FMouseEnter := True; ! Paint; ! end; end; ! procedure TJvgExtSpeedButton.CMMouseLeave(var Msg: TMessage); begin inherited; ! if Enabled then ! begin ! FMouseEnter := False; ! Paint; ! end; end; ! procedure TJvgExtSpeedButton.ButtonChanged(Sender: TObject); begin ! if not (csLoading in ComponentState) then ! Invalidate; end; procedure TJvgExtSpeedButton.SetColor(const Value: TColor); begin ! if Style.Color <> Value then ! begin ! Style.Color := Value; ! Invalidate; ! end; end; procedure TJvgExtSpeedButton.SetActiveColor(const Value: TColor); begin ! if StyleActive.Color <> Value then ! begin ! StyleActive.Color := Value; ! Invalidate; ! end; end; |