cxgrideditor.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 769 行 · 第 1/2 页
PAS
769 行
WriteInteger(GetRegSectionName, 'Top', Top);
WriteInteger(GetRegSectionName, 'Width', Width);
WriteInteger(GetRegSectionName, 'Height', Height);
WriteInteger(GetRegSectionName, 'PLeft.Width', PLeft.Width);
// TODO: splitters
finally
Free;
end;
end;
function TcxGridEditor.UniqueName(Component: TComponent): string;
begin
if Component is TcxGridLevel then
begin
if Grid <> nil then
Result := GenLevelName(Grid, Component as TcxGridLevel)
else
Result := inherited UniqueName(Component); // TODO
end
else
if Component is TcxCustomGridView then
Result := GenViewName(Self.Component, Component as TcxCustomGridView)
else
Result := inherited UniqueName(Component); // TODO
end;
procedure TcxGridEditor.UpdateContent;
begin
inherited UpdateContent;
UpdateGridStructureControl;
UpdateViewList;
UpdateButtons;
UpdateViewFrame(True);
end;
procedure TcxGridEditor.CreateViewClick(Sender: TObject);
var
AViewClass: TcxCustomGridViewClass;
AView: TcxCustomGridView;
begin
AViewClass := TcxCustomGridViewClass(
cxGridRegisteredViews[((Sender as TMenuItem).Tag)]);
FGridStructureControl.BeginUpdate;
try
ListBoxClearSelection(LBViews);
if Grid <> nil then
AView := Grid.CreateView(AViewClass)
else
AView := ViewRepository.CreateItem(AViewClass);
AView.Name := GenViewName(Component, AView);
RestoreViewFromTemplate(GetViewTemplateRegKey, AView);
UpdateViewList;
ListBoxSelectByObject(LBViews, AView);
UpdateDesigner(nil);
finally
FGridStructureControl.EndUpdate;
end;
LBViewsClick(nil);
end;
function TcxGridEditor.GetGrid: TcxCustomGrid;
begin
if Component is TcxCustomGrid then
Result := TcxCustomGrid(Component)
else
Result := nil;
end;
function TcxGridEditor.GetView(Index: Integer): TcxCustomGridView;
begin
if Grid <> nil then
Result := Grid.Views[Index]
else
Result := ViewRepository[Index];
end;
function TcxGridEditor.GetViewCount: Integer;
begin
if Grid <> nil then
Result := Grid.ViewCount
else
Result := ViewRepository.Count;
end;
function TcxGridEditor.GetViewRepository: TcxGridViewRepository;
begin
if Component is TcxGridViewRepository then
Result := TcxGridViewRepository(Component)
else
Result := nil;
end;
procedure TcxGridEditor.GridStructureControlKeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#13, #33..#126:
begin
if Key = #13 then Key := #0;
ActivateInspector(Key);
Key := #0;
end;
end;
end;
procedure TcxGridEditor.GridStructureControlSelectionChanged(Sender: TObject);
var
AList: TList;
begin
BeginUpdate;
try
AList := TList.Create;
try
FGridStructureControl.GetSelection(AList);
SelectComponents(AList, Component.Owner);
finally
AList.Free;
end;
finally
EndUpdate;
end;
end;
procedure TcxGridEditor.HideViewFrame;
begin
if FViewEditor <> nil then
begin
FViewEditor.PViewEditor.Parent := FViewEditor;
FViewEditor.Release;
end;
FViewEditor := nil;
end;
procedure TcxGridEditor.ShowViewFrame(AView: TcxCustomGridView; AMultiView: Boolean;
ARefreshNeeded: Boolean);
function IsExist(AView: TcxCustomGridView): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to ViewCount - 1 do
if Views[I] = AView then
begin
Result := True;
Break;
end;
end;
var
AViewEditorClass: TcxViewEditorClass;
begin
if (FViewEditor <> nil) and
(AView <> nil) and (FViewEditor.ClassType = GetViewEditorClass(AView)) and
(FViewEditor.View = AView) then
FViewEditor.SetView(AView, ARefreshNeeded)
else
begin
SendMessage(PViewFrame.Handle, WM_SETREDRAW, 0, 0);
try
HideViewFrame;
if AView <> nil then
begin
AViewEditorClass := GetViewEditorClass(AView);
if AViewEditorClass <> nil then
begin
FViewEditor := AViewEditorClass.Create(Self);
InitLookAndFeel(FViewEditor);
FViewEditor.FormEditor := Self;
FViewEditor.SetView(AView, True);
FViewEditor.PViewEditor.Parent := PViewFrame;
{$IFDEF DELPHI10} // should be DELPHI105
MakeColoredControlsOpaque(PViewFrame);
{$ENDIF}
end;
end;
finally
SendMessage(PViewFrame.Handle, WM_SETREDRAW, 1, 0);
RedrawWindow(PViewFrame.Handle, nil, 0, RDW_INVALIDATE or RDW_ALLCHILDREN or RDW_UPDATENOW);
end;
end;
UpdateViewFrameCaption;
end;
procedure TcxGridEditor.UpdateButtons;
var
ASelectionLevelCount: Integer;
begin
ASelectionLevelCount := FGridStructureControl.GetSelectionLevelCount;
BAddLevel.Enabled := CanAddComponent and (ASelectionLevelCount <= 1);
BDeleteLevel.Enabled := CanDeleteComponent(nil) and (ASelectionLevelCount > 0);
BAddView.Enabled := CanAddComponent;
BDeleteView.Enabled := CanDeleteComponent(nil) and (LBViews.SelCount > 0);
BEditView.Enabled := LBViews.SelCount = 1;
miDeleteView.Enabled := BDeleteView.Enabled;
miEditLayout.Enabled := BEditView.Enabled;
// TODO: Popup Menu
end;
procedure TcxGridEditor.UpdateDesigner(Sender: TObject);
begin
Designer.Modified;
end;
procedure TcxGridEditor.UpdateGridStructureControl;
begin
FGridStructureControl.Changed;
end;
procedure TcxGridEditor.UpdateGridStructureControlSelection;
var
AList: TList;
begin
AList := TList.Create;
try
GetSelectionList(AList);
FGridStructureControl.SyncSelection(AList);
finally
AList.Free;
end;
end;
procedure TcxGridEditor.UpdateViewFrame(ARefreshNeeded: Boolean);
var
ASelectionInfo: TSelectionInfo;
begin
ASelectionInfo := GetSelectionInfo;
ShowViewFrame(ASelectionInfo.View, ASelectionInfo.MultiSelect, ARefreshNeeded);
end;
procedure TcxGridEditor.UpdateViewFrameCaption;
begin
if FViewEditor <> nil then
LSelectedView.Caption := FViewEditor.View.Name
else
LSelectedView.Caption := 'none';
end;
procedure TcxGridEditor.UpdateViewList;
var
I, AItemIndex, ATopIndex: Integer;
ASelection: TStringList;
begin
ListBoxSaveSelection(LBViews, ASelection, AItemIndex, ATopIndex);
try
LBViews.Items.Clear;
for I := 0 to ViewCount - 1 do
LBViews.Items.AddObject(Views[I].Name, Views[I]);
finally
ListBoxRestoreSelection(LBViews, ASelection, AItemIndex, ATopIndex);
end;
end;
procedure TcxGridEditor.BCloseClick(Sender: TObject);
begin
Close;
end;
// Levels
procedure TcxGridEditor.BAddLevelClick(Sender: TObject);
var
ALevel: TcxGridLevel;
begin
if Grid = nil then Exit;
FGridStructureControl.BeginUpdate;
try
ALevel := FGridStructureControl.GetSelectedLevel;
if ALevel <> nil then
ALevel := ALevel.Add
else
ALevel := Grid.Levels.Add;
ALevel.Name := GenLevelName(Grid, ALevel);
UpdateDesigner(nil);
finally
FGridStructureControl.EndUpdate;
end;
GridStructureControlSelectionChanged(nil);
end;
function LevelsCompare(
AItem1, AItem2: Pointer): Integer;
var
ALevel1, ALevel2: TcxGridLevel;
begin
ALevel1 := TcxGridLevel(AItem1);
ALevel2 := TcxGridLevel(AItem2);
Result := ALevel1.Level - ALevel2.Level;
if Result = 0 then
begin
if not ALevel1.IsTop then
Result := LevelsCompare(ALevel1.Parent, ALevel2.Parent);
if Result = 0 then
Result := ALevel1.Index - ALevel2.Index;
end;
end;
procedure TcxGridEditor.BDeleteLevelClick(Sender: TObject);
var
AList: TList;
ALevel: TcxGridLevel;
I: Integer;
begin
AList := TList.Create;
try
FGridStructureControl.GetSelectionLevels(AList);
AList.Sort(LevelsCompare);
for I := AList.Count - 1 downto 0 do
begin
ALevel := TcxGridLevel(AList[I]);
if not CanDeleteComponent(ALevel) then
AList.Delete(I);
end;
if AList.Count > 0 then
begin
FGridStructureControl.BeginUpdate;
try
for I := AList.Count - 1 downto 0 do
TcxGridLevel(AList[I]).Free;
UpdateDesigner(nil);
finally
FGridStructureControl.EndUpdate;
end;
end;
finally
AList.Free;
end;
GridStructureControlSelectionChanged(nil);
end;
// Views
procedure TcxGridEditor.LBViewsClick(Sender: TObject);
begin
ListBoxApplySelection(LBViews, Component);
end;
procedure TcxGridEditor.BAddViewClick(Sender: TObject);
var
P: TPoint;
begin
// TODO: cxButton
PMViews.Items.Clear;
FillRegisteredViewsMenu(PMViews.Items, CreateViewClick);
P.X := 0;
P.Y := BAddView.Height;
P := BAddView.ClientToScreen(P);
PMViews.Popup(P.X, P.Y);
end;
procedure TcxGridEditor.BDeleteViewClick(Sender: TObject);
begin
if LBViews.SelCount > 0 then
begin
BeginUpdate;
try
ListBoxDeleteSelection(LBViews, True);
UpdateViewList;
LBViewsClick(nil);
UpdateDesigner(nil);
finally
EndUpdate;
end;
end;
end;
procedure TcxGridEditor.miEditLayoutClick(Sender: TObject);
var
ASelectionInfo: TSelectionInfo;
begin
ASelectionInfo := GetSelectionInfo;
if not ASelectionInfo.MultiSelect and (ASelectionInfo.View <> nil) then
if ShowGridViewEditor(ASelectionInfo.View) then
UpdateDesigner(nil);
end;
procedure TcxGridEditor.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
SaveSettings;
inherited;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?