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

📄 ucxpstyle.pas

📁 delphi 控件有需要的可以下载看看,可以用的,希望对你用 帮助
💻 PAS
📖 第 1 页 / 共 5 页
字号:
{
Class UCXPStyle:
Based on XPMenu 3.1 for Delphi


XPMenu for Delphi
Author: Khaled Shagrouni
URL: http://www.shagrouni.com/english/software/xpmenu.html
e-mail: khaled@shagrouni.com

Version 3.1 - 22.02.2004



XPMenu is a Delphi component to mimic Office XP menu and toolbar style.
Copyright (C) 2001, 2003 Khaled Shagrouni.

This component is FREEWARE with source code. I still hold the copyright, but
you can use it for whatever you like: freeware, shareware or commercial software.
If you have any ideas for improvement or bug reports, don't hesitate to e-mail
me <khaled@shagrouni.com> (Please state the XPMenu version and OS information).

--------------------------------------------------------------------------------
changes by QmD 30/11/2003 - qmd@usercontrol.com.br
* Add BitBtnColor / BitBtnSelectColor by QmD 30/11/2003 - qmd@usercontrol.com.br
* BitBtn Button multi-line corrected
* 29/03/2004 - XPmenu 2.21 incorporated in User Control Package. Class renamed to UCXPMenu to prevent conflicts (http://usercontrol.sourceforge.net)

changes by fduenas 29/12/2004 - fduenas@outm.net, fduenas@flashmail.com
* XPMenu.pas 3.1 Ported to UCXPStyle.pas by Francisco Due馻s fduenas@outm.net.
* File UCXPMenu.pas renamed to UCXPStyle.pas
* Class UCXPSet renamed to UCXPSettings
* File UCXPSet.pas renamed to UCXPSettings.pas
}

{$IFDEF VER130}
{$DEFINE VER5U}
{$ENDIF}

{$IFDEF VER140}
{$DEFINE VER5U}
{$DEFINE VER6U}
{$ENDIF}

{$IFDEF VER150}
{$DEFINE VER5U}
{$DEFINE VER6U}
{$DEFINE VER7U}
{$ENDIF}

unit UCXPStyle;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, ComCtrls, Forms,
  Menus, Commctrl, ExtCtrls, StdCtrls, Buttons, UCXPSettings, UCBase;

type
  { moved to UCXPSettings.pas and renamed TXP* to TUCXP*
  TXPContainer = (xccForm, xccFrame, xccToolbar, xccCoolbar, xccControlbar, xccPanel,
                  xccScrollBox, xccGroupBox, xccTabSheet, xccPageScroller);
  TXPContainers = set of TXPContainer;

  TXPControl = (xcMainMenu, xcPopupMenu, xcToolbar, xcControlbar, xcCombo, xcListBox,
                xcEdit, xcMaskEdit, xcMemo, xcRichEdit, xcMiscEdit, xcCheckBox,
                xcRadioButton, xcButton, xcBitBtn, xcSpeedButton, xcUpDown, xcPanel,
                xcGroupBox, xcTreeView, xcListView, xcProgressBar, xcHotKey);
                {xcStringGrid, xcDrawGrid, xcDBGrid);
  }


  TUCAboutXpStyleVar=String[10];

  TUCXPStyle = class;

  TControlSubClass = class(TComponent)   //:   "Fabian Jakubowski" <fj@sambreville.com>
  private
    Control: TControl;
    FBuilding: boolean;
    FMouseInControl: boolean;
    FLButtonBressed: boolean;
    FBressed: boolean;
    FIsKeyDown: boolean;
    FIsFocused: boolean;
    orgWindowProc: TWndMethod;
    FXPStyle: TUCXPStyle;
    FCtl3D: boolean;
    FBorderStyle: TBorderStyle;
  {FOnDrawCell: TDrawCellEvent;}
    FDefaultDrawing: boolean;
    FSelCol, FSelRow: integer;
    FMsg: Cardinal;
    procedure ControlSubClass(var Message: TMessage);
    procedure PaintControlXP;
    procedure PaintCombo;
    procedure PaintDBLookupCombo;
    procedure PaintEdit;
    procedure PaintRichEdit;
    procedure PaintCheckBox;
    procedure PaintRadio;
    procedure PaintButton;
    procedure PaintBitButn;
    procedure PaintUpDownButton;
    procedure PaintSpeedButton;
    procedure PaintPanel;
    procedure PaintGroupBox;
    procedure PaintNCWinControl;
    procedure PaintProgressBar;
    procedure PaintHotKey;
  end;

  TUCXPStyle = class(TComponent)
  private
    FActive: boolean;
    {Changes MMK FForm to TScrollingWinControl}
    FForm: TScrollingWinControl;

    {moved to UCXPsettings
    FFont: TFont;
    FColor: TColor;
    FIconBackColor: TColor;
    FMenuBarColor: TColor;
    FCheckedColor: TColor;
    FSeparatorColor: TColor;
    FSelectBorderColor: TColor;
    FSelectColor: TColor;
    FDisabledColor: TColor;
    FSelectFontColor: TColor;
    FIconWidth: integer;
    FDrawSelect: boolean;
    FUseSystemColors: boolean;
    FColorsChanged: boolean; // +jt
    }

    FFColor, FFIconBackColor, FFSelectColor, FFSelectBorderColor,
    FFSelectFontColor, FCheckedAreaColor, FCheckedAreaSelectColor,
    FFCheckedColor, FFMenuBarColor, FFDisabledColor, FFSeparatorColor,
    FMenuBorderColor, FMenuShadowColor: TColor;

    Is16Bit: boolean;
    { moved to UCXPSettings.pas
    FOverrideOwnerDraw: boolean;
    FGradient: boolean;
    FFlatMenu: boolean;
    FAutoDetect: boolean;
    FUCXPContainers: TUCXPContainers;
    FUCXPControls: TUCXPControls;
    FGrayLevel: byte;
    FDimLevel: byte;
    FDrawMenuBar: boolean;
    FUseDimColor: boolean;
    }

    FDimParentColor, FDimParentColorSelect: integer;

    FAutoDetect: boolean;
   // FUseParentClor: boolean;

    FSettingWindowRng: boolean;
    FIsW2k:            boolean;
    FIsWXP:            boolean;
    FIsWNT:            boolean;
//   FTransparentColor: TColor;

   // Do not allow the component to be used for subclassing
    FDisableSubclassing: boolean;

    FUCSettings: TUCSettings;
    FUCXPSettings: TUCXPSettings;
    FUCAboutXpStyleVar: TUCAboutXpStyleVar;  {+qmd}

    procedure SetDisableSubclassing(const Value: boolean);

    procedure SetActive(const Value: boolean);

    procedure SetForm(const Value: TScrollingWinControl);
    { moved to UCXPSettings
    procedure SetFont(const Value: TFont);
    procedure SetColor(const Value: TColor);
    procedure SetIconBackColor(const Value: TColor);
    procedure SetMenuBarColor(const Value: TColor);
    procedure SetCheckedColor(const Value: TColor);
    procedure SetDisabledColor(const Value: TColor);
    procedure SetSelectColor(const Value: TColor);
    procedure SetSelectBorderColor(const Value: TColor);
    procedure SetSeparatorColor(const Value: TColor);
    procedure SetSelectFontColor(const Value: TColor);
    procedure SetIconWidth(const Value: integer);
    procedure SetDrawSelect(const Value: boolean);
    procedure SetUseSystemColors(const Value: boolean);
    procedure SetOverrideOwnerDraw(const Value: boolean);
    procedure SetGradient(const Value: boolean);
    procedure SetFlatMenu(const Value: boolean);
    procedure SetUCXPContainers(const Value: TUCXPContainers);
    procedure SetUCXPControls(const Value: TUCXPControls);
    procedure SetDrawMenuBar(const Value: boolean);
    procedure SetUseDimColor(const Value: boolean);
    }

    procedure SetUCSettings(const Value: TUCSettings); {+qmd}
  protected
    procedure Loaded; override; //add by Cunha, liyang.
    procedure InitItems(wForm: TWinControl; Enable, Update: boolean);
    procedure InitItem(Comp: TComponent; Enable, Update: boolean); // Tom: "Thomas Knoblauch" <thomas@tom-the-bomb.de> 27.08
    procedure DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
      Selected: Boolean);
    procedure MenueDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
      Selected: Boolean);
    {$IFDEF VER5U}
    procedure ToolBarDrawButton(Sender: TToolBar;
      Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean);
    {$ENDIF}
    procedure ControlBarPaint(Sender: TObject; Control: TControl;
      Canvas: TCanvas; var ARect: TRect; var Options: TBandPaintOptions);

    procedure SetGlobalColor(ACanvas: TCanvas);
    procedure DrawTopMenuItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
      BckColor:Tcolor; IsRightToLeft: boolean);
    procedure DrawCheckedItem(FMenuItem: TMenuItem; Selected, Enabled,
     HasImgLstBitmap: boolean; ACanvas: TCanvas; CheckedRect: TRect);
    procedure DrawTheText(Sender: TObject; txt, ShortCuttext: string;
       ACanvas: TCanvas; TextRect: TRect;
       Selected, Enabled, Default, TopMenu, IsRightToLeft: boolean;
       var TxtFont: TFont; TextFormat: integer);
    procedure DrawIcon(Sender: TObject; ACanvas: TCanvas; B: TBitmap;
     IconRect: Trect; Hot, Selected, Enabled, Checked, FTopMenu,
     IsRightToLeft: boolean);

    procedure MeasureItem(Sender: TObject; ACanvas: TCanvas;
      var Width, Height: Integer);

    //function GetImageExtent(MenuItem: TMenuItem): TPoint;
    function GetImageExtent(MenuItem: TMenuItem; FTopMenu: TMenu): TPoint; // +jt
    function TopMenuFontColor(ACanvas: TCanvas; Color: TColor): TColor;
    procedure DrawGradient(ACanvas: TCanvas; ARect: TRect;
     IsRightToLeft: boolean);

    procedure DrawWindowBorder(hWnd: HWND; IsRightToLeft: boolean);

    procedure Notification(AComponent: TComponent;
      AOperation: TOperation); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure InitComponent(Comp: TComponent); // Tom: Added for usage by the main program ."Thomas Knoblauch" <thomas@tom-the-bomb.de> 27.08
    procedure ActivateMenuItem(MenuItem: TMenuItem; SubMenus: boolean); // +jt
    property Form: TScrollingWinControl read FForm write SetForm;// +jt
    property IsWXP: boolean read FIsWXP;
    property IsW2k: boolean read FIsW2k;
    property IsWNT: boolean read FIsWNT;
{   property TransparentColor: TColor read FTransparentColor write FTransparentColor;}
    published
    {moved to UCXPSettings
    property DimLevel: Byte read FDimLevel write FDimLevel;
    property GrayLevel: Byte read FGrayLevel write FGrayLevel;
    property Font: TFont read FFont write SetFont;
    property Color: TColor read FColor write SetColor;
    property DrawMenuBar: boolean read FDrawMenuBar write SetDrawMenuBar;
    property IconBackColor: TColor read FIconBackColor write SetIconBackColor;
    property MenuBarColor: TColor read FMenuBarColor write SetMenuBarColor;
    property SelectColor: TColor read FSelectColor write SetSelectColor;
    property SelectBorderColor: TColor read FSelectBorderColor
     write SetSelectBorderColor;
    property SelectFontColor: TColor read FSelectFontColor
     write SetSelectFontColor;
    property DisabledColor: TColor read FDisabledColor write SetDisabledColor;
    property SeparatorColor: TColor read FSeparatorColor
     write SetSeparatorColor;
    property CheckedColor: TColor read FCheckedColor write SetCheckedColor;
    property IconWidth: integer read FIconWidth write SetIconWidth;
    property DrawSelect: boolean read FDrawSelect write SetDrawSelect;
    property UseSystemColors: boolean read FUseSystemColors
     write SetUseSystemColors;
    property UseDimColor: boolean read FUseDimColor write SetUseDimColor;
    property OverrideOwnerDraw: boolean read FOverrideOwnerDraw
     write SetOverrideOwnerDraw;

    property Gradient: boolean read FGradient write SetGradient;
    property FlatMenu: boolean read FFlatMenu write SetFlatMenu;
    property AutoDetect: boolean read FAutoDetect write SetAutoDetect;

    property XPContainers: TUCXPContainers read FUCXPContainers write SetUCXPContainers
      default [xccForm, xccFrame, xccToolbar, xccCoolbar, xccControlbar, xccPanel,
                  xccScrollBox, xccGroupBox, xccTabSheet, xccPageScroller];
    property XPControls :TUCXPControls read FUCXPControls write SetUCXPControls
      default [xcMainMenu, xcPopupMenu, xcToolbar, xcControlbar, xcCombo, xcListBox,
               xcEdit, xcMaskEdit, xcMemo, xcRichEdit, xcMiscEdit, xcCheckBox,
               xcRadioButton, xcButton, xcBitBtn, xcSpeedButton, xcUpDown, xcPanel,
               xcGroupBox, xcTreeView, xcListView, xcProgressBar, xcHotKey];
               {xcStringGrid, xcDrawGrid, xcDBGrid];
    }
    property About: TUCAboutXpStyleVar read FUCAboutXpStyleVar write FUCAboutXpStyleVar;
    property Active: boolean read FActive write SetActive;
    property DisableSubclassing: boolean read FDisableSubclassing write SetDisablesubclassing
      default false;
    property XPSettings : TUCXPSettings read FUCXPSettings write FUCXPSettings;
    property UCSettings : TUCSettings read FUCSettings write SetUCSettings;
  end;

  TUCXPStyleManager = class(TPersistent)
  private
    FXPStyleList: TList;
    FPendingFormsList: TList;
    FFormList: TList;
    FActiveXPStyle: TUCXPStyle;
    FDisableSubclassing: boolean;

    function MainWindowHook(var Message: TMessage): boolean;
    procedure CollectForms;
    procedure RemoveChildSubclassing(AForm: TCustomForm);
    procedure SetDisableSubclassing(AValue: boolean);
    function FindSubclassingXPStyle(Exclude: TUCXPStyle): TUCXPStyle;

  protected
    procedure Notification(AComponent: TComponent;
      AOperation: TOperation);

  public
    constructor Create;
    destructor Destroy; override;
    procedure Add(AXPStyle: TUCXPStyle);
    procedure Delete(AXPStyle: TUCXPStyle);
    procedure UpdateActiveXPStyle(AXPStyle: TUCXPStyle);
    procedure AddForm(AForm: TCustomForm);
    procedure RemoveForm(AForm: TCustomForm);
    function IsFormSubclassed(AForm: TCustomForm): boolean;
    function IsComponentSubclassed(AComponent: TComponent): boolean;

    property ActiveXPStyle: TUCXPStyle read FActiveXPStyle;
    property DisableSubclassing: boolean read FDisableSubclassing write SetDisableSubclassing
      default false;
  end;

function GetShadeColor(ACanvas: TCanvas; clr: TColor; Value: integer): TColor;
function MergColor(Colors: Array of TColor): TColor;
function NewColor(ACanvas: TCanvas; clr: TColor; Value: integer): TColor;
procedure DimBitmap(ABitmap: TBitmap; Value: integer);

procedure DrawArrow(ACanvas: TCanvas; X, Y: integer); overload;
procedure DrawArrow(ACanvas: TCanvas; X, Y, Orientation: integer); overload;
function GrayColor(ACanvas: TCanvas; clr: TColor; Value: integer): TColor;
function GetInverseColor(AColor: TColor): TColor;

procedure GrayBitmap(ABitmap: TBitmap; Value: integer);
procedure DrawBitmapShadow(B: TBitmap; ACanvas: TCanvas; X, Y: integer;
  ShadowColor: TColor);
procedure DrawCheckMark(ACanvas: TCanvas; X, Y: integer);

procedure GetSystemMenuFont(Font: TFont);
//procedure Register;

const
  WM_DRAWMENUBORDER     = CN_NOTIFY + 101;   // +jt
  WM_DRAWMENUBORDER2    = CN_NOTIFY + 102;   // +jt

// Gloabal access to the UCXPStyleManager
var
  UCXPStyleManager: TUCXPStyleManager;

implementation

{ moved to UCReg.pas
procedure Register;
begin
  RegisterComponents('XP', [TUCXPStyle]);
end;
}
// Set up the global variable that represents the UCXPStyleManager
procedure InitControls;
begin
  //added by fduenas
  if (csDesigning in Application.ComponentState) then
      exit;

  if (Not assigned(UCXPStyleManager)) or
     (UCXPStyleManager = nil) then
    UCXPStyleManager := TUCXPStyleManager.Create;
end;

// Delete the global variable that represents the UCXPStyleManager
procedure DoneControls;
begin
  FreeAndNil(UCXPStyleManager);
  {
  if (UCXPStyleManager <> nil) then
  begin
    UCXPStyleManager.Free;
    UCXPStyleManager := nil;
  end;
  }
end;

// Test if mouse cursor is in the given rect of the application's main form
function IsMouseInRect(TheForm: TScrollingWinControl; DestRect: TRect): boolean;
var
  p: TPoint;

begin

  if Assigned(TheForm) then
  begin
    p := Mouse.CursorPos;
    p.x := p.x - TheForm.Left;
    p.y := p.y - TheForm.Top;

    Dec(DestRect.Right);
    Dec(DestRect.Bottom, 2);
    Result := (p.x >= DestRect.Left) and (p.x <= DestRect.Right) and
              (p.y >= DestRect.Top) and (p.y <= DestRect.Bottom);
  end
  else Result := false;
end;

{ TUCXPStyle }

constructor TUCXPStyle.Create(AOwner: TComponent);
var
  OSVersionInfo: TOSVersionInfo; // +jt
begin
  inherited Create(AOwner);
  {moved to UCXPSettings
  FFont := TFont.Create;
  }

⌨️ 快捷键说明

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