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

📄 cxbaredititem.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  if APropertiesClass <> nil then
    FProperties := APropertiesClass.Create(Self);
end;

procedure TcxCustomBarEditItem.DestroyProperties;
begin
  FreeAndNil(FProperties);
end;

function TcxCustomBarEditItem.GetCurEditValue: TcxEditValue;
begin
  if (CurItemLink = nil) or (CurItemLink.Control = nil) then
    Result := EditValue
  else
    Result := TcxBarEditItemControl(CurItemLink.Control).CurEditValue;
end;

function TcxCustomBarEditItem.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  if FProperties = nil then
    Result := nil
  else
    Result := TcxCustomEditPropertiesClass(FProperties.ClassType);
end;

function TcxCustomBarEditItem.GetPropertiesClassName: string;
begin
  if FProperties = nil then
    Result := ''
  else
    Result := FProperties.ClassName;
end;

function TcxCustomBarEditItem.GetPropertiesValue: TcxCustomEditProperties;
begin
  UpdateRepositoryItemValue;
  if FRepositoryItemValue <> nil then
  begin
    Result := FRepositoryItemValue.Properties;
    if FProperties <> nil then
      FProperties.OnPropertiesChanged := nil;
  end
  else
  begin
    Result := FProperties;
    FProperties.OnPropertiesChanged := PropertiesChangedHandler;
  end;
end;

function TcxCustomBarEditItem.GetRepositoryItemValue: TcxEditRepositoryItem;
begin
  if FRepositoryItem <> nil then
    Result := FRepositoryItem
  else
    if FProperties = nil then
      Result := DefaultRepositoryItem
    else
      Result := nil;
end;

function TcxCustomBarEditItem.IsBarCompatibleEdit(
  AEditProperties: TcxCustomEditProperties = nil): Boolean;
var
  AButton: TcxEditButton;
  AProperties: TcxCustomEditProperties;
  I: Integer;
begin
  Result := False;
  AProperties := AEditProperties;
  if AProperties = nil then
    AProperties := GetProperties;
  if AProperties.Buttons.VisibleCount = 1 then
    for I := 0 to AProperties.Buttons.Count - 1 do
    begin
      AButton := AProperties.Buttons[I];
      if AButton.Visible then
      begin
        Result := AButton.Kind = bkDown;
        Break;
      end;
    end;
end;

function TcxCustomBarEditItem.IsBlobEditValue: Boolean;
begin
  Result := esfBlobEditValue in GetProperties.GetSpecialFeatures;
end;

function TcxCustomBarEditItem.IsEditValueStored(AFiler: TFiler): Boolean;

  function Equals(const V1, V2: TcxEditValue): Boolean;
  begin
    Result := (VarType(V1) = VarType(V2)) and VarEqualsExact(V1, V2);
  end;

begin
  if AFiler.Ancestor <> nil then
    Result := not (AFiler.Ancestor is TcxCustomBarEditItem) or
      not Equals(EditValue, TcxCustomBarEditItem(AFiler.Ancestor).EditValue)
  else
    Result := not VarIsNull(EditValue);
end;

procedure TcxCustomBarEditItem.PropertiesChangedHandler(Sender: TObject);
begin
  PropertiesChanged;
end;

procedure TcxCustomBarEditItem.PropertiesValueChanged;
begin
  UpdatePropertiesValue;
  if not (csDestroying in ComponentState) then
  begin
    CheckIsBlobEditValue;
    UpdateEx;
    Changed;
    dxBarDesignerModified(BarManager);
  end;
end;

procedure TcxCustomBarEditItem.ReadEditValue(AReader: TReader);
begin
{$IFDEF DELPHI6}
  EditValue := AReader.ReadVariant;
{$ELSE}
  TReaderAccess(AReader).ReadPropValue(Self, GetPropInfo(Self, 'EditValue'));
{$ENDIF}
end;

procedure TcxCustomBarEditItem.ReadEditValue(AStream: TStream);
var
  ASize: DWORD;
  S: string;
begin
  AStream.ReadBuffer(ASize, SizeOf(ASize));
  SetLength(S, ASize);
  AStream.ReadBuffer(S[1], ASize);
  EditValue := S;
end;

procedure TcxCustomBarEditItem.SetEditValue(const Value: TcxEditValue);
begin
  if not (GetProperties.CanCompareEditValue and (VarType(Value) = VarType(FEditValue)) and
    VarEqualsExact(Value, FEditValue)) then
  begin
    FEditValue := Value;
    Change;
    Update;
  end;
end;

procedure TcxCustomBarEditItem.SetHeight(Value: Integer);
begin
  if Value <> FHeight then
  begin
    FHeight := Value;
    if not IsLoading then // TODO
      UpdateEx;           // TODO
  end;
end;

procedure TcxCustomBarEditItem.SetProperties(Value: TcxCustomEditProperties);
begin
  if Value <> nil then
    FProperties.Assign(Value);
end;

procedure TcxCustomBarEditItem.SetPropertiesClass(
  Value: TcxCustomEditPropertiesClass);
begin
  if Value <> PropertiesClass then
  begin
    if FProperties <> nil then
      Properties.LockUpdate(True);
    DestroyProperties;
    CreateProperties(Value);
    if FProperties <> nil then
      Properties.LockUpdate(False);
    PropertiesValueChanged;
  end;
end;

procedure TcxCustomBarEditItem.SetPropertiesClassName(const Value: string);
begin
  PropertiesClass := TcxCustomEditPropertiesClass(
    GetRegisteredEditProperties.FindByClassName(Value));
end;

procedure TcxCustomBarEditItem.SetRepositoryItem(Value: TcxEditRepositoryItem);
begin
  if FRepositoryItem <> Value then
  begin
    FRepositoryItem := Value;
    PropertiesValueChanged;
  end;
end;

procedure TcxCustomBarEditItem.SetRepositoryItemValue(Value: TcxEditRepositoryItem);
begin
  if Value <> FRepositoryItemValue then
  begin
    if FRepositoryItemValue <> nil then
      FRepositoryItemValue.RemoveListener(Self);
    FRepositoryItemValue := Value;
    if FRepositoryItemValue <> nil then
      FRepositoryItemValue.AddListener(Self);
  end;
end;

procedure TcxCustomBarEditItem.SetBarStyleDropDownButton(Value: Boolean);
begin
  if FBarStyleDropDownButton <> Value then
  begin
    FBarStyleDropDownButton := Value;
    UpdateEx;
  end;
end;

procedure TcxCustomBarEditItem.UpdateRepositoryItemValue;
begin
  SetRepositoryItemValue(GetRepositoryItemValue);
end;

function TcxCustomBarEditItem.UseBarPaintingStyle: Boolean;
begin
  Result := BarStyleDropDownButton and IsBarCompatibleEdit;
end;

procedure TcxCustomBarEditItem.WriteEditValue(AWriter: TWriter);
begin
{$IFDEF DELPHI6}
  AWriter.WriteVariant(EditValue);
{$ELSE}
  WriteVariantProperty(AWriter, Self, 'EditValue');
{$ENDIF}
end;

procedure TcxCustomBarEditItem.WriteEditValue(AStream: TStream);
var
  ASize: DWORD;
  S: string;
begin
  S := EditValue;
  ASize := Length(S);
  AStream.WriteBuffer(ASize, SizeOf(ASize));
  AStream.WriteBuffer(S[1], ASize);
end;

{ TcxBarEditItemControl }

destructor TcxBarEditItemControl.Destroy;
begin
  Focused := False;
  FreeAndNil(FEditViewInfo);
  inherited Destroy;
end;

function TcxBarEditItemControl.IsDroppedDown: Boolean;
begin
  Result := (Edit <> nil) and Edit.HasPopupWindow;
end;

procedure TcxBarEditItemControl.ActivateEdit(AByMouse: Boolean; AKey: Char = #0);
var
  P: TPoint;
  AActiveWinControl: TWinControl;
begin
  AActiveWinControl := FindControl(GetActiveWindow);
  if AActiveWinControl is TCustomForm then
  begin
    FakeWinControl.Parent := AActiveWinControl;
    FakeWinControl.WindowHandle := Edit.Handle;
    TCustomForm(AActiveWinControl).SetFocusedControl(FakeWinControl);
  end;
  Edit.OnGlass := Parent.IsOnGlass;
  if not AByMouse then
    if AKey = #0 then
      Edit.Activate(Item.FEditData)
    else
      Edit.ActivateByKey(AKey, Item.FEditData)
  else
  begin
    P := Edit.Parent.ScreenToClient(GetMouseCursorPos);
    Edit.ActivateByMouse(InternalGetShiftState, P.X, P.Y, Item.FEditData);
  end;
  Edit.InplaceParams.MultiRowParent := False;
end;

procedure TcxBarEditItemControl.CalcDrawParams(AFull: Boolean = True);
begin
  inherited;
  if AFull then
    FDrawParams.DroppedDown := Focused and Edit.HasPopupWindow;
end;

procedure TcxBarEditItemControl.CalcParts;
begin
  inherited;
  if Item.UseBarPaintingStyle then
    Painter.CalculateComboParts(DrawParams, FParts, ItemBounds);
end;

function TcxBarEditItemControl.CanHide: Boolean;
begin
  Result := inherited CanHide and (not IsDropDownEdit or DropDownEdit.CanHide);
end;

function TcxBarEditItemControl.CanSelect: Boolean;
begin
  Result := inherited CanSelect and (Item.CanEdit or Parent.IsCustomizing);
end;

procedure TcxBarEditItemControl.CheckHotTrack(APoint: TPoint);
var
  ATempViewInfo: TcxCustomEditViewInfo;
begin
  inherited;
  ATempViewInfo := CreateEditViewInfo;
  try
    ATempViewInfo.Assign(EditViewInfo);
    CalculateEditViewInfo(GetBoundsRect, APoint, True);
    EditViewInfo.Repaint(Parent, ATempViewInfo);
  finally
    ATempViewInfo.Free;
  end;
end;

// TODO
procedure TcxBarEditItemControl.ControlInactivate(Immediately: Boolean);
begin
//  Focused := False;
  DisableAppWindows(not IsApplicationActive);
  try
    inherited ControlInactivate(Immediately); //#DG
  finally
    EnableAppWindows;
  end;
end;

procedure TcxBarEditItemControl.DoPaint(ARect: TRect; PaintType: TdxBarPaintType);
begin
  if Edit <> nil then
    Edit.InvalidateWithChildren;
  inherited;
end;

procedure TcxBarEditItemControl.DoMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  P: TPoint;
begin
  if Assigned(FSavedEditEvents.OnMouseMove) then
    FSavedEditEvents.OnMouseMove(Sender, Shift, X, Y);
  P := ClientToParent(Point(X, Y));
  MouseMove(Shift, P.X, P.Y);
end;

procedure TcxBarEditItemControl.DrawTextField;

  function HasEditButtonCompositeFrame: Boolean;
  begin
    Result := Painter.EditButtonAllowCompositeFrame and Item.UseBarPaintingStyle;
  end;

begin
  if not Focused or HasEditButtonCompositeFrame then
  begin
    CalculateEditViewInfo(GetBoundsRect, Parent.ScreenToClient(GetMouseCursorPos), False);
    EditViewInfo.Data := Integer(FDrawParams.PaintType);
//    BarCanvas.BeginPaint(Canvas);
    Canvas.SaveState;
    try
      EditViewInfo.Paint(Canvas);
//      EditViewInfo.Paint(BarCanvas);
    finally
      Canvas.RestoreState;
//      BarCanvas.EndPaint;
    end;
  end;
end;  

function TcxBarEditItemControl.GetControl: TControl;
begin
  Result := Edit;
end;

function TcxBarEditItemControl.GetHandle: HWND;
begin
  if (Edit <> nil) and Edit.HandleAllocated then
    Result := Edit.Handle
  else

⌨️ 快捷键说明

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