📄 cxbaredititem.pas
字号:
procedure InitEditStyle;
procedure SetStyleColors;
begin
FEditStyle.Font := AFont;
FEditStyle.Color := AColor;
FEditStyle.TextColor := ATextColor;
end;
procedure SetLookAndFeel;
begin
if APainter <> nil then
APainter.EditGetRealLookAndFeel(ABarManager, FEditStyle.LookAndFeel)
else
TdxBarManagerAccess(ABarManager).GetRealLookAndFeel(FEditStyle.LookAndFeel);
if (FEditStyle.LookAndFeel.ActiveStyle = lfsFlat) and
((AEditProperties.Buttons.VisibleCount <> 0) and not ADrawSelected) then
FEditStyle.LookAndFeel.SetStyle(lfsUltraFlat);
end;
begin
SetStyleColors;
SetLookAndFeel;
FEditStyle.GradientButtons := True;
FEditStyle.ButtonTransparency := ebtNone;
end;
begin
if FEditStyle = nil then
FEditStyle := TcxEditStyle.Create(nil, True);
InitEditStyle;
Result := FEditStyle;
end;
{$IFNDEF DELPHI6}
procedure WriteVariantProperty(AWriter: TWriter; AInstance: TObject;
const APropName: string);
procedure WriteValue(AValue: TValueType);
begin
AWriter.Write(AValue, SizeOf(AValue));
end;
function IsAncestorValid: Boolean;
begin
Result := (AWriter.Ancestor <> nil) and ((AInstance.ClassType = AWriter.Ancestor.ClassType) or
(AInstance = AWriter.Root));
end;
function IsDefaultValue(const AValue: Variant): Boolean;
begin
if IsAncestorValid then
Result := AValue = GetVariantProp(AWriter.Ancestor, GetPropInfo(AInstance, APropName))
else
Result := VarIsEmpty(AValue);
end;
var
AValue: Variant;
begin
AValue := GetVariantProp(AInstance, GetPropInfo(AInstance, APropName));
if IsDefaultValue(AValue) then
Exit;
if VarIsArray(AValue) then
raise EWriteError.CreateRes(@SWriteError);
case VarType(AValue) and varTypeMask of
varEmpty:
WriteValue(vaNil);
varNull:
WriteValue(vaNull);
varOleStr:
AWriter.WriteWideString(AValue);
varString:
AWriter.WriteString(AValue);
varByte, varSmallInt, varInteger:
AWriter.WriteInteger(AValue);
varSingle:
AWriter.WriteSingle(AValue);
varDouble:
AWriter.WriteFloat(AValue);
varCurrency:
AWriter.WriteCurrency(AValue);
varDate:
AWriter.WriteDate(AValue);
varBoolean:
if AValue then
WriteValue(vaTrue)
else
WriteValue(vaFalse);
else
try
AWriter.WriteString(AValue);
except
raise EWriteError.CreateRes(@SWriteError);
end;
end;
end;
{$ENDIF}
{ TFakeWinControl }
destructor TFakeWinControl.Destroy;
begin
inherited;
FFakeWinControl := nil; //#!!! because DoneApplication
end;
procedure TFakeWinControl.CreateWnd;
begin
// do nothing
end;
procedure TFakeWinControl.DestroyWindowHandle;
begin
WindowHandle := 0; //#!!! because DoneApplication
end;
procedure TFakeWinControl.DestroyWnd;
begin
WindowHandle := 0; // because WindowHandle := Edit.Handle
end;
{ TEditorParentForm }
destructor TEditorParentForm.Destroy;
begin
{$IFDEF DELPHI9}
PopupChildren.Clear; // for test framework
{$ENDIF}
inherited;
end;
procedure TEditorParentForm.GetTabOrderList(List: TList);
begin
//do nothing
end;
function TEditorParentForm.SetFocusedControl(Control: TWinControl): Boolean;
var
ALink: TcxObjectLink;
APopupWindow: TcxCustomPopupWindow;
begin
ALink := nil;
APopupWindow := GetParentPopupWindow(Self, True);
if APopupWindow <> nil then
begin
APopupWindow.LockDeactivate(True);
ALink := cxAddObjectLink(APopupWindow);
end;
try
Result := inherited SetFocusedControl(Control);
finally
if APopupWindow <> nil then
begin
if ALink.Ref <> nil then
APopupWindow.LockDeactivate(False);
cxRemoveObjectLink(ALink);
end;
end;
end;
{ TcxBarEditItemVerticalButtonControl }
function TcxBarEditItemVerticalButtonControl.CanClicked: Boolean;
begin
Result := CanEdit and inherited CanClicked;
end;
function TcxBarEditItemVerticalButtonControl.CanSelect: Boolean;
begin
Result := CanEdit and inherited CanSelect;
end;
function TcxBarEditItemVerticalButtonControl.GetPaintStyle: TdxBarPaintStyle;
begin
if CanEdit then
Result := inherited GetPaintStyle
else
if TcxCustomBarEditItem(Item).Glyph.Empty then
Result := psCaption
else
Result := psCaptionGlyph;
end;
function TcxBarEditItemVerticalButtonControl.CanEdit: Boolean;
begin
Result := TcxCustomBarEditItem(Item).CanEdit;
end;
{ TcxItemsEditorEx }
class procedure TcxItemsEditorEx.InitSubItem(AItemLinks: TdxBarItemLinks);
var
I: Integer;
begin
for I := 0 to GetRegisteredEditProperties.Count - 1 do
BarDesignController.AddInternalItem(AItemLinks, TdxBarButton, GetRegisteredEditProperties.Descriptions[I], OnButtonClick);
end;
class function TcxItemsEditorEx.GetAddedItemClass(const AAddedItemName: string): TdxBarItemClass;
begin
Result := TcxBarEditItem;
end;
class function TcxItemsEditorEx.GetPopupItemCaption: string;
begin
Result := dxSBAR_CP_ADDCXITEM;
end;
class procedure TcxItemsEditorEx.InitializeAddedItem(AItemLink: TdxBarItemLink; AAddedItemName: string);
var
APropertiesClass: TcxCustomEditPropertiesClass;
begin
APropertiesClass := TcxCustomEditPropertiesClass(GetRegisteredEditProperties.FindByDescription(AAddedItemName));
TcxBarEditItem(AItemLink.Item).PropertiesClass := APropertiesClass;
end;
{ TcxCustomBarEditItem }
constructor TcxCustomBarEditItem.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEditValue := Null;
UpdatePropertiesValue;
FPrevIsBlobEditValue := IsBlobEditValue;
FBarStyleDropDownButton := True;
end;
destructor TcxCustomBarEditItem.Destroy;
begin
RepositoryItem := nil;
PropertiesClass := nil;
SetRepositoryItemValue(nil);
FreeAndNil(FEditData);
inherited Destroy;
end;
procedure TcxCustomBarEditItem.DoClick;
begin
inherited DoClick;
if not (Assigned(OnClick) or GetProperties.ReadOnly) then
ShowValueEditor(ClickItemLink);
end;
function TcxCustomBarEditItem.GetProperties: TcxCustomEditProperties;
begin
Result := FPropertiesValue;
end;
procedure TcxCustomBarEditItem.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
if esfBlobEditValue in GetProperties.GetSpecialFeatures then
Filer.DefineBinaryProperty('InternalEditValue', ReadEditValue,
WriteEditValue, IsEditValueStored(Filer))
else
Filer.DefineProperty('InternalEditValue', ReadEditValue, WriteEditValue,
IsEditValueStored(Filer));
end;
procedure TcxCustomBarEditItem.DrawCustomizingImage(ACanvas: TCanvas;
const ARect: TRect; AState: TOwnerDrawState);
begin
if CaptionIsEditValue then
dxBarCustomizingForm.PainterClass.DrawButtonOrSubItem(ACanvas, ARect, Self,
GetTextOf(Caption), odSelected in AState)
else
dxBarCustomizingForm.PainterClass.DrawEdit(ACanvas, ARect, Self,
odSelected in AState, UseBarPaintingStyle);
end;
procedure TcxCustomBarEditItem.DrawCustomizingImageContent(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
var
AEditProperties: TcxCustomEditProperties;
AEditStyle: TcxEditStyle;
AEditViewData: TcxCustomEditViewData;
AEditViewInfo: TcxCustomEditViewInfo;
ATempCanvas: TcxCanvas;
begin
AEditProperties := nil;
AEditViewData := nil;
AEditViewInfo := nil;
ATempCanvas := nil;
try
AEditProperties := GetProperties.CreatePreviewProperties;
AEditStyle := InternalGetEditStyle(AEditProperties, BarManager, nil,
ACanvas.Font, clWindow, ACanvas.Font.Color, ASelected);
if UseBarPaintingStyle then
AEditStyle.ButtonTransparency := ebtHideInactive;
AEditViewData := AEditProperties.CreateViewData(AEditStyle, True, True);
AEditViewData.OnGetDefaultButtonWidth := CustomizingDoGetEditDefaultButtonWidth;
AEditViewData.EditContentParams.ExternalBorderBounds := ARect;
AEditViewInfo := TcxCustomEditViewInfo(AEditProperties.GetViewInfoClass.Create);
AEditViewInfo.Data := Integer(ASelected);
AEditViewInfo.OnDrawButtonBackground := CustomizingDoDrawEditButtonBackground;
ATempCanvas := TcxCanvas.Create(ACanvas);
AEditViewData.EditValueToDrawValue(ATempCanvas, Null, AEditViewInfo);
AEditViewData.Calculate(ATempCanvas, ARect, Point(-1, -1), cxmbNone, [], AEditViewInfo, False);
AEditViewInfo.Paint(ATempCanvas);
finally
FreeAndNil(AEditProperties);
FreeAndNil(AEditViewData);
FreeAndNil(AEditViewInfo);
FreeAndNil(ATempCanvas);
end;
end;
function TcxCustomBarEditItem.GetControlClass(AIsVertical: Boolean): TdxBarItemControlClass;
begin
if AIsVertical then
Result := TcxBarEditItemVerticalButtonControl
else
Result := TcxBarEditItemControl;
end;
function TcxCustomBarEditItem.HasAccel(AItemLink: TdxBarItemLink): Boolean;
begin
Result := inherited HasAccel(AItemLink) and CanEdit;
end;
function TcxCustomBarEditItem.CanEdit: Boolean;
begin
Result := esoEditing in GetProperties.GetSupportedOperations;
end;
function TcxCustomBarEditItem.CaptionIsEditValue: Boolean;
begin
Result := not CanEdit and
(esoShowingCaption in GetProperties.GetSupportedOperations);
end;
procedure TcxCustomBarEditItem.DoEditValueChanged(Sender: TObject);
begin
EditValue := TcxCustomEdit(Sender).EditValue;
if Assigned(FPrevOnEditValueChanged) then
FPrevOnEditValueChanged(Sender);
end;
procedure TcxCustomBarEditItem.PropertiesChanged;
begin
if FEditData <> nil then
FEditData.Clear;
CheckIsBlobEditValue;
UpdateEx;
end;
procedure TcxCustomBarEditItem.UpdatePropertiesValue;
begin
FPropertiesValue := GetPropertiesValue;
end;
procedure TcxCustomBarEditItem.RepositoryItemItemRemoved(
Sender: TcxEditRepositoryItem);
begin
RepositoryItem := nil;
end;
procedure TcxCustomBarEditItem.RepositoryItemPropertiesChanged(
Sender: TcxEditRepositoryItem);
begin
PropertiesChanged;
end;
procedure TcxCustomBarEditItem.CustomizingDoDrawEditButtonBackground(
Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; const ARect: TRect;
AButtonVisibleIndex: Integer; var AHandled: Boolean);
begin
AHandled := not Sender.NativeStyle;
if (ACanvas <> nil) and AHandled then
FillRectByColor(ACanvas.Handle, ARect,
dxBarCustomizingForm.PainterClass.GetButtonColor(Self, False));
end;
procedure TcxCustomBarEditItem.CustomizingDoGetEditDefaultButtonWidth(
Sender: TcxCustomEditViewData; AIndex: Integer; var ADefaultWidth: Integer);
begin
if IsBarCompatibleEdit(Sender.Properties) then
ADefaultWidth := dxBarCustomizingForm.PainterClass.GetComboBoxButtonWidth;
end;
procedure TcxCustomBarEditItem.CheckIsBlobEditValue;
begin
if FPrevIsBlobEditValue <> IsBlobEditValue then
begin
FPrevIsBlobEditValue := IsBlobEditValue;
EditValue := Null;
end;
end;
procedure TcxCustomBarEditItem.CreateProperties(
APropertiesClass: TcxCustomEditPropertiesClass);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -