cxblobedit.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,542 行 · 第 1/4 页

PAS
1,542
字号
          EditValue := Self.EditValue;
          Style.LookAndFeel.MasterLookAndFeel := Self.PopupControlsLookAndFeel;
          Style.Font.Assign(Self.ActiveStyle.GetVisibleFont);
          Style.Color := Self.ActiveStyle.Color;
        end;
        InitControls;
      end;
  end;
end;

procedure TcxCustomBlobEdit.DoAssignPicture;
begin
  if FStorage is TcxPopupImage then
  begin
    LockEditValueChanging(True);
    try
      DoOnAssignPicture(TcxPopupImage(FStorage).Picture);
      SaveModified;
      try
        EditModified := False;
        DoEditing;
      finally
        RestoreModified;
      end;
    finally
      LockEditValueChanging(False);
    end;
  end;
end;

procedure TcxCustomBlobEdit.DoEditKeyPress(var Key: Char);
begin
//  if (Key >= #32) and (Key <= #255) and ActiveProperties.ImmediateDropDown and
//    not ActiveProperties.ReadOnly and not HasPopupWindow then
//      FSaveKey := Key;
  inherited DoEditKeyPress(Key);
end;

procedure TcxCustomBlobEdit.DoOnAssignPicture(APicture: TPicture);
begin
  with Properties do
    if Assigned(OnAssignPicture) then
      OnAssignPicture(Self, APicture);
  if RepositoryItem <> nil then
    with ActiveProperties do
      if Assigned(OnAssignPicture) then
        OnAssignPicture(Self, APicture);
end;

procedure TcxCustomBlobEdit.FontChanged;
begin
  inherited FontChanged;
  if not IsDestroying and HasPopupWindow then
  begin
    if FStorage is TcxPopupMemo then
      TcxPopupMemo(FStorage).Style.Font.Assign(ActiveStyle.GetVisibleFont);
    if FOkButton <> nil then
      FOkButton.Font.Assign(ActiveStyle.GetVisibleFont);
    if FCancelButton <> nil then
      FCancelButton.Font.Assign(ActiveStyle.GetVisibleFont);
  end;
end;

function TcxCustomBlobEdit.GetDisplayValue: string;
begin
  if (ActiveProperties.BlobEditKind = bekMemo) and (FStorage <> nil) then
    Result := TcxPopupMemo(FStorage).Text
  else
    Result := inherited GetDisplayValue;
end;

function TcxCustomBlobEdit.GetEditingValue: TcxEditValue;
begin
  if HasPopupWindow and (ActiveProperties.BlobEditKind in [bekMemo, bekPict]) then
    if ActiveProperties.BlobEditKind = bekMemo then
      Result := TcxPopupMemo(FStorage).Text
    else
      Result := TcxPopupImage(FStorage).EditValue
  else
    Result := EditValue;
end;

function TcxCustomBlobEdit.GetPopupFocusedControl: TWinControl;
begin
  if FStorage <> nil then
    Result := FStorage
  else
    Result := inherited GetPopupFocusedControl;
end;

function TcxCustomBlobEdit.GetPopupWindowClientPreferredSize: TSize;
begin
  with ActiveProperties do
    if (BlobEditKind = bekPict) and PictureAutoSize then
    begin
      with TcxPopupImage(FStorage).Picture do
        Result := Size(Width + 4, Height + 4);
    end
    else
      Result := inherited GetPopupWindowClientPreferredSize;
end;

procedure TcxCustomBlobEdit.InternalValidateDisplayValue(const ADisplayValue: TcxEditValue);
begin
  if (ActiveProperties.BlobEditKind = bekMemo) and (FStorage <> nil) then
    TcxPopupMemo(FStorage).Text := ADisplayValue;
  inherited InternalValidateDisplayValue(ADisplayValue);
end;

procedure TcxCustomBlobEdit.DestroyPopupControls;
begin
  ActiveProperties.PopupControl := nil;
  FreeAndNil(FOkButton);
  FreeAndNil(FCancelButton);
  FreeAndNil(FStorage);
end;

procedure TcxCustomBlobEdit.DoInitPopup;
begin
  inherited DoInitPopup;
  CreatePopupControls;
end;

function TcxCustomBlobEdit.GetPictureGraphicClass(
  APastingFromClipboard: Boolean = False): TGraphicClass;
begin
  if IsInplace then
    with InplaceParams do
      Result := ActiveProperties.GetPictureGraphicClass(Position.Item,
        Position.RecordIndex, APastingFromClipboard)
  else
  begin
    Result := ActiveProperties.PictureGraphicClass;
    if Result = nil then
    begin
      if APastingFromClipboard then
        Result := TBitmap;
      if Assigned(FOnGetGraphicClass) then
        FOnGetGraphicClass(Self, APastingFromClipboard, Result);
    end;
  end;
end;

procedure TcxCustomBlobEdit.Initialize;
begin
  inherited Initialize;
  ControlStyle := ControlStyle - [csSetCaption];
  TabStop := True;
end;

function TcxCustomBlobEdit.InternalGetText: string;
begin
  if IsDesigning then
  begin
    Result := VarToStr(EditValue);
    Exit;
  end;
  Result := '';
  if ActiveProperties.BlobEditKind = bekMemo then
    if HasPopupWindow then
      Result := TcxPopupMemo(FStorage).Text
    else
      if VarIsStr(EditValue) then
        Result := VarToStr(EditValue);
end;

function TcxCustomBlobEdit.InternalSetText(const Value: string): Boolean;
begin
  if IsDesigning then
  begin
    EditValue := Value;
    Result := True;
    Exit;
  end;
  Result := ActiveProperties.BlobEditKind = bekMemo;
  if not Result then
    Exit;
  if HasPopupWindow then
    TcxPopupMemo(FStorage).EditingText := Value
  else
    EditValue := Value;
end;

procedure TcxCustomBlobEdit.PopupWindowClosed(Sender: TObject);
begin
  LockChangeEvents(True);
  try
    SaveStorage;
    inherited PopupWindowClosed(Sender);
    ShortRefreshContainer(False);
  finally
    LockChangeEvents(False);
  end;
end;

procedure TcxCustomBlobEdit.PropertiesChanged(Sender: TObject);
begin
  if IsDestroying then
    Exit;
  inherited PropertiesChanged(Sender);
  ShortRefreshContainer(False);
  if HasPopupWindow and (FStorage is TcxPopupImage) then
    TcxPopupImage(FStorage).ActiveProperties.GraphicClass :=
      ActiveProperties.PictureGraphicClass;
  if HasPopupWindow and (FStorage is TcxPopupMemo) then
  begin
    TcxPopupMemo(FStorage).ActiveProperties.ImeMode := ActiveProperties.ImeMode;
    TcxPopupMemo(FStorage).ActiveProperties.ImeName := ActiveProperties.ImeName;
  end;
end;

procedure TcxCustomBlobEdit.SetEditingText(const Value: TCaption);
begin
  if ActiveProperties.BlobEditKind = bekMemo then
    if HasPopupWindow then
      Text := Value
    else
      inherited SetEditingText(Value);
end;

procedure TcxCustomBlobEdit.SetupPopupWindow;
var
  AHeight, ADelta: Integer;
  R: TRect;
begin
  if FCancelButton = nil then
  begin
    inherited SetupPopupWindow;
    Exit;
  end;
  TcxEditStyleAccess(Style).PopupCloseButton := False;
  inherited SetupPopupWindow;
  AHeight := FCancelButton.Height;
  ADelta := FButtonWidth + AHeight div 6;

  R := PopupWindow.ViewInfo.SizeGripRect;
  if PopupWindow.ViewInfo.SizeGripCorner in [ecoTopRight, ecoBottomRight] then
    Inc(ADelta, PopupWindow.Width - R.Left)
  else
  begin
    Inc(ADelta, AHeight div 6);
    if ADelta - FButtonWidth < R.Left then
      ADelta := R.Left + FButtonWidth;
  end;
  if PopupWindow.ViewInfo.SizeGripCorner in [ecoTopLeft, ecoTopRight] then
  begin
    FCancelButton.SetBounds(PopupWindow.Width - ADelta,
      R.Top + (PopupWindow.MinSysPanelHeight - AHeight) div 2 - 2, FButtonWidth, AHeight);
    FCancelButton.Anchors := [akTop, akRight];
  end
  else
  begin
    FCancelButton.SetBounds(PopupWindow.Width - ADelta,
      R.Bottom - (AHeight + (PopupWindow.MinSysPanelHeight - AHeight) div 2 - 2),
      FButtonWidth, AHeight);
    FCancelButton.Anchors := [akBottom, akRight];
  end;

  if FOkButton <> nil then
  begin
    FOkButton.SetBounds(FCancelButton.Left - (FButtonWidth + (AHeight div 3)),
      FCancelButton.Top, FButtonWidth, AHeight);
    FOkButton.Anchors := FCancelButton.Anchors;
  end;
end;

procedure TcxCustomBlobEdit.StorageEditingHandler(Sender: TObject;
  var CanEdit: Boolean);
begin
  CanEdit := CanModify;
end;

procedure TcxCustomBlobEdit.SynchronizeDisplayValue;
begin
  ShortRefreshContainer(False);
end;

procedure TcxCustomBlobEdit.SynchronizeEditValue;
begin
  if (ActiveProperties.BlobEditKind = bekMemo) and (FStorage <> nil) then
    inherited SynchronizeEditValue;
end;

class function TcxCustomBlobEdit.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxCustomBlobEditProperties;
end;

function TcxCustomBlobEdit.IsEditClass: Boolean;
begin
  Result := False;
end;

{ TcxBlobEdit }

class function TcxBlobEdit.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
  Result := TcxBlobEditProperties;
end;

function TcxBlobEdit.GetActiveProperties: TcxBlobEditProperties;
begin
  Result := TcxBlobEditProperties(InternalGetActiveProperties);
end;

function TcxBlobEdit.GetProperties: TcxBlobEditProperties;
begin
  Result := TcxBlobEditProperties(FProperties);
end;

procedure TcxBlobEdit.SetProperties(Value: TcxBlobEditProperties);
begin
  FProperties.Assign(Value);
end;

{ TcxFilterBlobEditHelper }

class function TcxFilterBlobEditHelper.GetSupportedFilterOperators(
  AProperties: TcxCustomEditProperties;
  AValueTypeClass: TcxValueTypeClass;
  AExtendedSet: Boolean = False): TcxFilterControlOperators;
begin
  Result := [fcoBlanks, fcoNonBlanks];
  if (AProperties is TcxBlobEditProperties) and
    (TcxBlobEditProperties(AProperties).BlobEditKind = bekMemo) then
  Result := Result + [fcoLike, fcoNotLike];
end;

{ TcxBlobEditPopupWindow }

procedure TcxBlobEditPopupWindow.DoPopupControlKey(Key: Char);
var
  AStorage: TcxCustomEdit;
begin
  AStorage := TcxCustomBlobEdit(Edit).FStorage;
  if AStorage is TcxMemo then
    if not TcxMemo(AStorage).ActiveProperties.ReadOnly then
      if TcxCustomBlobEdit(Edit).ActiveProperties.MemoAutoReplace then
      begin
        TcxMemoAccess(AStorage).InnerEdit.EditValue := Key;
        TcxMemo(AStorage).SelStart := 1;
        TcxMemo(AStorage).ModifiedAfterEnter := True;
      end
      else
        inherited DoPopupControlKey(Key);
end;

procedure LoadBlobImages;
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.LoadFromResourceName(HInstance, cxbmBlobNull);
    imgBlobImages := TImageList.CreateSize(Bmp.Width, Bmp.Height);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmBlob);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmMemoNull);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmMemo);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmPictNull);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmPict);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmOleNull);
    imgBlobImages.AddMasked(Bmp, clOlive);
    Bmp.LoadFromResourceName(HInstance, cxbmOle);
    imgBlobImages.AddMasked(Bmp, clOlive);
  finally
    Bmp.Free;
  end;
end;

initialization
  LoadBlobImages;
  GetRegisteredEditProperties.Register(TcxBlobEditProperties, scxSEditRepositoryBlobItem);

finalization
  FreeAndNil(imgBlobImages);

end.

⌨️ 快捷键说明

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