cxgriduihelper.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 749 行 · 第 1/2 页
PAS
749 行
begin
AParameter.View.DataController.GotoPrev;
end;
procedure TcxCustomGridViewOperationHelper.DoInsert(const AParameter: TcxCustomGridOperationHelperParameters);
begin
AParameter.View.DataController.Insert;
end;
procedure TcxCustomGridViewOperationHelper.DoDelete(const AParameter: TcxCustomGridOperationHelperParameters);
begin
if AParameter.View.DataController.GetSelectedCount > 0 then
AParameter.View.DataController.DeleteSelection
else AParameter.View.DataController.DeleteFocused;
end;
{ TcxCustomGridToolBarHelper }
constructor TcxCustomGridOperationHelper.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FFocusedViewChangedNotification := TcxGridNotifications.Create;
TcxGridNotifications(FFocusedViewChangedNotification).FGridOperationHelper := Self;
end;
destructor TcxCustomGridOperationHelper.Destroy;
begin
Grid := nil;
FreeAndNil(FFocusedViewChangedNotification);
inherited Destroy;
end;
procedure TcxCustomGridOperationHelper.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = Grid) then
FGrid := nil;
end;
procedure TcxCustomGridOperationHelper.DoUpdateOperations;
begin
if Assigned(FOnUpdateOperations) then
FOnUpdateOperations(self);
end;
procedure TcxCustomGridOperationHelper.DoFocusedRecordChanged;
begin
if Assigned(FOnFocusedRecordChanged) then
FOnFocusedRecordChanged(self);
end;
procedure TcxCustomGridOperationHelper.DoCustomizationFormVisibleChanged;
begin
if Assigned(FonCustomizationFormVisibleChanged) then
FonCustomizationFormVisibleChanged(self);
end;
function TcxCustomGridOperationHelper.FocusedView: TcxCustomGridView;
begin
if Grid <> nil then
Result := Grid.FocusedView
else Result := nil;
end;
function TcxCustomGridOperationHelper.FocusedViewClass: TcxCustomGridViewClass;
begin
if FocusedView <> nil then
Result := TcxCustomGridViewClass(FocusedView.ClassType)
else Result := nil;
end;
procedure TcxCustomGridOperationHelper.PerformOperation(AOperationIndex: Integer;
const AParameters: TcxCustomGridOperationHelperParameters);
begin
if IsOperationEnabled[AOperationIndex] then
GetGridViewOperationHelperByGridViewClass(
FocusedViewClass).PerformOperation(AOperationIndex, AParameters);
end;
function TcxCustomGridOperationHelper.GetIsOperationAccessible(AOperationIndex: Integer): Boolean;
var
AGridViewHelper: TcxCustomGridViewOperationHelper;
begin
if FocusedView <> nil then
begin
AGridViewHelper := GetGridViewOperationHelperByGridViewClass(FocusedViewClass);
Result := (AGridViewHelper <> nil) and AGridViewHelper.IsOperationAccessible(AOperationIndex);
end else Result := False;
end;
function TcxCustomGridOperationHelper.GetIsOperationEnabled(AOperationIndex: Integer): Boolean;
begin
Result := IsOperationAccessible[AOperationIndex] and
GetGridViewOperationHelperByGridViewClass(
FocusedViewClass).IsOperationEnabled(FocusedView, AOperationIndex);
end;
procedure TcxCustomGridOperationHelper.DoFocusedViewChanged;
begin
if not (csDestroying in ComponentState) and not (csDesigning in ComponentState) and
(Grid <> nil) and not (csDestroying in Grid.ComponentState) then
DoUpdateOperations;
end;
procedure TcxCustomGridOperationHelper.SetGrid(const Value: TcxGrid);
begin
if FGrid <> Value then
begin
if (FGrid <> nil) and not (csDestroying in FGrid.ComponentState) then
begin
FGrid.RemoveFreeNotification(self);
FGrid.UnregisterNotification(FFocusedViewChangedNotification);
end;
FGrid := Value;
if FGrid <> nil then
begin
FGrid.FreeNotification(self);
FGrid.RegisterNotification(FFocusedViewChangedNotification);
end;
end;
end;
procedure TcxCustomGridOperationHelper.PerformStarndardOperation(AOperationIndex: Integer);
var
AParameters: TcxCustomGridOperationHelperParameters;
begin
AParameters := TcxCustomGridOperationHelperParameters.Create(FocusedView);
try
PerformOperation(AOperationIndex, AParameters);
finally
AParameters.Free;
end;
end;
procedure TcxCustomGridOperationHelper.PerformShowingOperation(AOperationIndex: Integer; AShow: Boolean);
var
AParameters: TcxShowingGridOperationHelperParameters;
begin
AParameters := TcxShowingGridOperationHelperParameters.Create(FocusedView);
AParameters.Showing := AShow;
try
PerformOperation(AOperationIndex, AParameters);
finally
AParameters.Free;
end;
end;
function TcxCustomGridOperationHelper.GetIsOperationShowing(AOperationIndex: Integer): Boolean;
var
AParameters: TcxShowingGridOperationHelperParameters;
begin
AParameters := TcxShowingGridOperationHelperParameters.Create(FocusedView, False);
try
PerformOperation(AOperationIndex, AParameters);
Result := AParameters.Showing;
finally
AParameters.Free;
end;
end;
procedure TcxCustomGridOperationHelper.DoFirst;
begin
PerformStarndardOperation(GROP_FIRST);
end;
procedure TcxCustomGridOperationHelper.DoLast;
begin
PerformStarndardOperation(GROP_LAST);
end;
procedure TcxCustomGridOperationHelper.DoNext;
begin
PerformStarndardOperation(GROP_NEXT);
end;
procedure TcxCustomGridOperationHelper.DoPrev;
begin
PerformStarndardOperation(GROP_PREV);
end;
procedure TcxCustomGridOperationHelper.DoInsert;
begin
PerformStarndardOperation(GROP_INSERT);
end;
procedure TcxCustomGridOperationHelper.DoDelete;
begin
PerformStarndardOperation(GROP_DELETE);
end;
procedure TcxCustomGridOperationHelper.CopyToClipboard;
begin
PerformStarndardOperation(GROP_COPYTOCLIPBOARD);
end;
procedure TcxCustomGridOperationHelper.DoShowColumnCustomizing(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWCOLUMNCUSTOMIZING, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowGroupingPanel(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWGROUPINGPANEL, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowHeaders(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWHEADERS, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowBands(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWBANDS, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowSummaryFooter(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWSUMMARYFOOTER, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowGrid(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWGRID, AShow);
end;
procedure TcxCustomGridOperationHelper.DoColumnAutoWidth(AShow: Boolean);
begin
PerformShowingOperation(GROP_COLUMNAUTOWIDTH, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowPreview(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWPREVIEW, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowEditButtons(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWEDITBUTTONS, AShow);
end;
procedure TcxCustomGridOperationHelper.DoLayoutDirection(AShow: Boolean);
begin
PerformShowingOperation(GROP_LAYOUTDIRECTION, AShow);
end;
procedure TcxCustomGridOperationHelper.DoInvertSelect(AShow: Boolean);
begin
PerformShowingOperation(GROP_INVERTSELECT, AShow);
end;
procedure TcxCustomGridOperationHelper.DoShowIndicator(AShow: Boolean);
begin
PerformShowingOperation(GROP_SHOWINDICATOR, AShow);
end;
function TcxCustomGridOperationHelper.IsColumnsCustomizingShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWCOLUMNCUSTOMIZING];
end;
function TcxCustomGridOperationHelper.IsGroupingPanelShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWGROUPINGPANEL];
end;
function TcxCustomGridOperationHelper.IsHeadersShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWHEADERS];
end;
function TcxCustomGridOperationHelper.IsBandsShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWBANDS];
end;
function TcxCustomGridOperationHelper.IsSummaryFooterShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWSUMMARYFOOTER];
end;
function TcxCustomGridOperationHelper.IsGridShowing: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWGRID];
end;
function TcxCustomGridOperationHelper.IsColumnAutoWidth: Boolean;
begin
Result := IsOperationShowing[GROP_COLUMNAUTOWIDTH];
end;
function TcxCustomGridOperationHelper.IsShowPreview: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWPREVIEW];
end;
function TcxCustomGridOperationHelper.IsShowEditButtons: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWEDITBUTTONS];
end;
function TcxCustomGridOperationHelper.IsVertLayoutDirection: Boolean;
begin
Result := IsOperationShowing[GROP_LAYOUTDIRECTION];
end;
function TcxCustomGridOperationHelper.IsInvertSelect: Boolean;
begin
Result := IsOperationShowing[GROP_INVERTSELECT];
end;
function TcxCustomGridOperationHelper.IsShowIndicator: Boolean;
begin
Result := IsOperationShowing[GROP_SHOWINDICATOR];
end;
var
FGridViewOperationHelperList: TList = nil;
procedure RegisterGridViewOperationHelper(AGridViewOperationHelperClass: TcxCustomGridViewOperationHelperClass);
begin
FGridViewOperationHelperList.Add(AGridViewOperationHelperClass.Create);
end;
procedure UnregisterGridViewOperationHelper(AGridViewOperationHelperClass: TcxCustomGridViewOperationHelperClass);
var
I: Integer;
begin
for I := 0 to FGridViewOperationHelperList.Count - 1 do
if TcxCustomGridViewOperationHelper(FGridViewOperationHelperList[I]).ClassType = AGridViewOperationHelperClass then
begin
TcxCustomGridViewOperationHelper(FGridViewOperationHelperList[I]).Free;
FGridViewOperationHelperList.Delete(I);
end;
end;
function GetGridViewOperationHelperByGridViewClass(const AGridViewClass: TcxCustomGridViewClass): TcxCustomGridViewOperationHelper;
var
AItem: TcxCustomGridViewOperationHelper;
I: Integer;
begin
Result := nil;
for I := 0 to FGridViewOperationHelperList.Count - 1 do
begin
AItem := TcxCustomGridViewOperationHelper(FGridViewOperationHelperList[I]);
if AItem.GetViewClass = AGridViewClass then
begin
Result := AItem;
break;
end;
if AGridViewClass.InheritsFrom(AItem.GetViewClass) then
if (Result = nil) or not Result.InheritsFrom(AItem.GetViewClass) then
Result := AItem;
end;
end;
procedure ClearGridViewOperationHelperList;
var
I: Integer;
begin
for I := 0 to FGridViewOperationHelperList.Count - 1 do
TcxCustomGridViewOperationHelper(FGridViewOperationHelperList[I]).Free;
FGridViewOperationHelperList.Clear;
end;
initialization
FGridViewOperationHelperList := TList.Create;
RegisterGridViewOperationHelper(TcxCustomGridViewOperationHelper);
finalization
ClearGridViewOperationHelperList;
FGridViewOperationHelperList.Free;
FGridViewOperationHelperList := nil;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?