am2000button.pas
上传用户:powellwoo
上传日期:2007-01-07
资源大小:109k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

C++ Builder

  1. {*******************************************************}
  2. {                                                       }
  3. {       AnimatedMenus/2000                              }
  4. {       T_AM2000_ButtonOptions                          }
  5. {                                                       }
  6. {       Copyright (c) 1997-99 AnimatedMenus.com         }
  7. {       All rights reserved.                            }
  8. {                                                       }
  9. {*******************************************************}
  10. unit am2000button;
  11. {$I am2000.inc}
  12. interface
  13. uses
  14.   SysUtils, Windows, Graphics, Menus,
  15.   am2000options;
  16. type
  17.   // TButtonOptions - options for ControlType = ctButton
  18.   T_AM2000_ButtonOptions = class(T_AM2000_ControlOptions)
  19.   private
  20.     FAllowAllUp   : Boolean;
  21.     FBorderFrame  : Boolean;
  22.     FDown         : Boolean;
  23.     procedure SetDown(Value: Boolean);
  24.   public
  25.     constructor Create(AParent: TMenuItem); override;
  26.     procedure Draw(DrawRect: P_AM2000_DrawMenuItemRect); override;
  27.     function GetHeight(ItemHeight: Integer): Integer; override;
  28.   published
  29.     property AllowAllUp   : Boolean
  30.       read FAllowAllUp write FAllowAllUp default True;
  31.     property BorderFrame  : Boolean
  32.       read FBorderFrame write FBorderFrame default True;
  33.     property Down         : Boolean
  34.       read FDown write SetDown default False;
  35.   end;
  36. implementation
  37. uses
  38.   am2000menuitem, am2000utils;
  39. // draws TMenuItem2000 with ControlStyle = ctlButton
  40. procedure DrawMenuItemButton(Canvas: TCanvas;
  41.             Item: TMenuItem2000;
  42.             Options: T_AM2000_BaseOptions;
  43.             State: T_AM2000_ItemState;
  44.             MouseState: T_AM2000_MouseState;
  45.             mir: T_AM2000_MenuItemRect);
  46. var
  47.   R: TRect;
  48. begin
  49.   if not (Item.ControlOptions is T_AM2000_ButtonOptions) then Exit;
  50.   // clear background
  51.   R:= mir.LineRect;
  52.   DrawBackground(Canvas, [], Options, R);
  53.   InflateRect(R, -2, -1); Dec(R.Bottom, 2);
  54.   with Item.ControlOptions as T_AM2000_ButtonOptions do begin
  55.     if (msLeftButton in MouseState)
  56.     or (Down and not (isSelected in State))
  57.     then begin
  58.       DrawPatternBackground(Canvas, R);
  59.       DrawEdge(Canvas.Handle, R, bdr_SunkenOuter, bf_Rect);
  60.     end
  61.     else
  62.       if isSelected in State then
  63.         if Down
  64.         then DrawEdge(Canvas.Handle, R, bdr_SunkenOuter, bf_Rect)
  65.         else DrawEdge(Canvas.Handle, R, bdr_RaisedInner, bf_Rect);
  66.     Canvas.Brush.Style:= bsClear;
  67.     Canvas.Font.Color:= Options.Colors.MenuText;
  68.     DrawCaption(Canvas, Item.Caption, am2000options.taCenter, R);
  69.     if BorderFrame then begin
  70.       Canvas.Brush.Color:= clBtnShadow;
  71.       if Canvas.Brush.Style <> bsSolid then
  72.         Canvas.Brush.Style:= bsSolid;
  73.       InflateRect(R, -5, -3);
  74.       Canvas.FrameRect(R);
  75.     end;
  76.   end;
  77. end;
  78. { T_AM2000_ButtonOptions }
  79. constructor T_AM2000_ButtonOptions.Create;
  80. begin
  81.   inherited;
  82.   FAllowAllUp:= True;
  83.   FBorderFrame:= True;
  84. end;
  85. procedure T_AM2000_ButtonOptions.Draw(DrawRect: P_AM2000_DrawMenuItemRect);
  86. begin
  87.   with DrawRect^ do
  88.     DrawMenuItemButton(Canvas, TMenuItem2000(Parent), Options, State, MouseState, mir)
  89. end;
  90. function T_AM2000_ButtonOptions.GetHeight(ItemHeight: Integer): Integer;
  91. begin
  92.   Result:= ItemHeight +6;
  93. end;
  94. procedure T_AM2000_ButtonOptions.SetDown(Value: Boolean);
  95. begin
  96.   if Value <> False
  97.   then TMenuItem2000(Parent).TurnSiblingsOff;
  98.   if FAllowAllUp or Value
  99.   then FDown:= Value;
  100.   RepaintFloatingMenus;
  101. end;
  102. end.