cxgridpopupmenu.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 482 行 · 第 1/2 页
PAS
482 行
{********************************************************************}
{ }
{ Developer Express Visual Component Library }
{ ExpressQuantumGrid Utils }
{ }
{ Copyright (c) 1998-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSQUANTUMGRID AND ALL }
{ ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{********************************************************************}
unit cxGridPopupMenu;
{$I cxVer.inc}
interface
uses
Windows, Messages,
{$IFDEF DELPHI6}
Types,
{$ENDIF}
SysUtils, Classes, Controls, cxGrid, cxGridCustomView,
cxGridUIHelper, cxGridUICustomTableHelper, cxGridUITableHelper,
cxGridUIBandedTableHelper, cxGridUICardHelper, cxGridCustomPopupMenu;
type
TcxGridPopupMenu = class(TcxCustomGridPopupMenu)
private
FAlwaysFireOnPopup: Boolean;
FGrid: TcxGrid;
FGridDefaultPopupMenu: TcxGridDefaultPopupMenu;
FGridOperationHelper: TcxGridOperationHelper;
FHitGridView: TcxCustomGridView;
FHitPoint: TPoint;
FHitTest: TcxCustomGridHitTest;
FHitType: TcxGridViewHitType;
FMouseupNotification: TcxCustomGridNotification;
FOnClick: TcxGridPopupMenuItemClickProc;
FOnPopup: TcxGridBeforePopupProc;
FUseBuiltInPopupMenus: Boolean;
procedure CreateBuiltInPopupMenus;
procedure FreeBuiltInPopupMenus;
function GetPopupMenus: TcxPopupMenuInfos;
procedure SetUseBuiltInPopupMenus(const Value: Boolean);
procedure SetGrid(const AValue: TcxGrid);
procedure SetPopupMenus(const AValue: TcxPopupMenuInfos);
function TryPopupAsIcxPopupMenuIntf(APopupMenu: TComponent;
AHitTest: TcxCustomGridHitTest; APoint: TPoint): Boolean;
function TryPopupAsIDoPopupIntf(APopupMenu: TComponent;
AHitTest: TcxCustomGridHitTest; APoint: TPoint): Boolean;
function TryPopupAsVCLPopupMenu(APopupMenu: TComponent;
AHitTest: TcxCustomGridHitTest; APoint: TPoint): Boolean;
protected
function DoOnPopup(ASenderMenu: TComponent;
AHitTest: TcxCustomGridHitTest; X,Y: Integer): Boolean; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function DoPopup(AAPPSKeyPressed: Boolean): Boolean; virtual;
function GetPopupMenuInfo(const AMenu: TComponent; const AView: TcxCustomGridView;
SearchDefault: Boolean = True): TcxPopupMenuInfo; override;
property GridOperationHelper: TcxGridOperationHelper read FGridOperationHelper;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function CheckShortCuts(var Message: TWMKeyDown): Boolean; override;
function FindPopupMenuInfo(const AView: TcxCustomGridView;
AHitType: TcxGridViewHitType; AHitTest: TcxCustomGridHitTest): TcxPopupMenuInfo; override;
function GetBuiltInPopupMenuByClass(const AMenuClass: TcxPopupMenuClass): TComponent;
procedure RegisterPopupMenu(const AMenu: TComponent; AHitTypes: TcxGridViewHitTypes;
ADoPopupProc: TcxGridOnPopupProc; const AView: TcxCustomGridView); overload; virtual;
procedure RegisterPopupMenu(const AMenu: TComponent; AHitTypes: TcxGridViewHitTypes;
ADoPopupProc: TcxGridOnPopupProc; AViewClass: TcxCustomGridViewClass); overload; virtual;
procedure UnregisterPopupMenu(const AMenu: TComponent; const AGridView: TcxCustomGridView;
AHitTypes: TcxGridViewHitTypes = []); overload; virtual;
procedure UnregisterPopupMenu(const AMenu: TComponent; AGridViewClass: TcxCustomGridViewClass;
AHitTypes: TcxGridViewHitTypes = []); overload; virtual;
property BuiltInPopupMenus: TcxGridDefaultPopupMenu read FGridDefaultPopupMenu;
property HitGridView: TcxCustomGridView read FHitGridView;
property HitPoint: TPoint read FHitPoint;
property HitTest: TcxCustomGridHitTest read FHitTest;
property HitType: TcxGridViewHitType read FHitType;
published
property Grid: TcxGrid read FGrid write SetGrid;
property PopupMenus: TcxPopupMenuInfos read GetPopupMenus write SetPopupMenus;
property UseBuiltInPopupMenus: Boolean read FUseBuiltInPopupMenus write
SetUseBuiltInPopupMenus default True;
property OnMenuItemClick: TcxGridPopupMenuItemClickProc read FOnClick write FOnClick;
property OnPopup: TcxGridBeforePopupProc read FOnPopup write FOnPopup;
property AlwaysFireOnPopup: Boolean read FAlwaysFireOnPopup write FAlwaysFireOnPopup default False;
end;
var
ActiveGridPopupMenu: TcxGridPopupMenu;
implementation
uses
Forms, cxGridLevel, Dialogs, cxGridStdPopupMenu, Menus, cxGridCustomTableView, cxControls;
type
TcxGridContextPopupNotification = class(TcxCustomGridNotification)
private
FGridPopupMenu: TcxGridPopupMenu;
protected
procedure Notify(AKind: TcxGridNotificationKind; AData: TObject; var AHandled: Boolean); override;
function NotificationKinds: TcxGridNotificationKinds; override;
end;
PWMKeyDown = ^TWMKeyDown;
TcxCustomGridCellViewInfoAccess = class(TcxCustomGridCellViewInfo);
TcxCustomGridViewInfoAccess = class(TcxCustomGridViewInfo);
procedure TcxGridContextPopupNotification.Notify(AKind: TcxGridNotificationKind;
AData: TObject; var AHandled: Boolean);
begin
case (AKind) of
gnkContextMenu:
begin
Application.ProcessMessages;
AHandled := FGridPopupMenu.DoPopup(Boolean(AData));
end;
gnkKeyDown:
begin
FGridPopupMenu.CheckShortCuts(PWMKeyDown(AData)^);
end;
end;
end;
function TcxGridContextPopupNotification.NotificationKinds: TcxGridNotificationKinds;
begin
Result := [gnkContextMenu, gnkKeyDown];
end;
{TcxGridPopupMenu}
constructor TcxGridPopupMenu.Create (AOwner: TComponent);
begin
inherited Create(AOwner);
FAlwaysFireOnPopup := False;
FGridDefaultPopupMenu := TcxGridDefaultPopupMenu.Create(Self);
FUseBuiltInPopupMenus := True;
CreateBuiltInPopupMenus;
FGridOperationHelper := TcxGridOperationHelper.Create(Self);
FMouseupNotification := TcxGridContextPopupNotification.Create;
TcxGridContextPopupNotification(FMouseupNotification).FGridPopupMenu := self;
end;
destructor TcxGridPopupMenu.Destroy;
begin
FreeBuiltInPopupMenus;
FreeAndNil(FGridOperationHelper);
FreeAndNil(FGridDefaultPopupMenu);
if Grid <> nil then
Grid.UnregisterNotification(FMouseupNotification);
FreeAndNil(FMouseupNotification);
inherited Destroy;
end;
function TcxGridPopupMenu.CheckShortCuts(var Message: TWMKeyDown): Boolean;
begin
Result := inherited CheckShortCuts(Message);
if not Result then
Result := FGridDefaultPopupMenu.CheckShortCuts(Message);
end;
function TcxGridPopupMenu.GetBuiltInPopupMenuByClass(
const AMenuClass: TcxPopupMenuClass): TComponent;
var
I: Integer;
begin
Result := nil;
for I := 0 to FGridDefaultPopupMenu.Count - 1 do
if Assigned(FGridDefaultPopupMenu[i].PopupMenu) and
(FGridDefaultPopupMenu[i].PopupMenu.ClassType = AMenuClass) then
begin
Result := FGridDefaultPopupMenu[i].PopupMenu;
break;
end;
end;
function TcxGridPopupMenu.FindPopupMenuInfo(const AView: TcxCustomGridView;
AHitType: TcxGridViewHitType; AHitTest: TcxCustomGridHitTest): TcxPopupMenuInfo;
begin
Result := inherited FindPopupMenuInfo(AView, AHitType, AHitTest);
if Result = nil then
Result := FGridDefaultPopupMenu.FindPopupMenuInfo(AView, AHitType, AHitTest);
end;
function TcxGridPopupMenu.GetPopupMenuInfo(const AMenu: TComponent;
const AView: TcxCustomGridView; SearchDefault: Boolean = True): TcxPopupMenuInfo;
var
I : Integer;
begin
Result := nil;
for I := 0 to Count - 1 do
If (AMenu = MenuInfos[I].PopupMenu) and (AView = MenuInfos[I].GridView) then
begin
Result := MenuInfos[I];
Result.Index := I;
break;
end;
if SearchDefault and not Assigned(Result) then
Result := FGridDefaultPopupMenu.GetPopupMenuInfo(AMenu,
TcxCustomGridViewClass(AView.ClassType));
end;
procedure TcxGridPopupMenu.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = Grid) then
FGrid := nil;
end;
procedure TcxGridPopupMenu.RegisterPopupMenu(const AMenu: TComponent;
AHitTypes: TcxGridViewHitTypes; ADoPopupProc: TcxGridOnPopupProc;
const AView: TcxCustomGridView);
begin
if not Assigned(AView) then exit;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?