📄 cxbaredititem.pas
字号:
{*******************************************************************}
{ }
{ Developer Express Visual Component Library }
{ ExpressBars components }
{ }
{ Copyright (c) 1998-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSBARS AND ALL ACCOMPANYING VCL }
{ CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{*******************************************************************}
unit cxBarEditItem;
{$I cxVer.inc}
interface
uses
{$IFDEF DELPHI6}
Types,
{$ENDIF}
Windows, Classes, Controls, Graphics, Messages, cxContainer, cxControls,
cxDropDownEdit, cxEdit, cxEditConsts, cxGraphics, cxLookAndFeels, dxBar, cxGeometry;
type
{ TcxItemsEditorEx }
TcxItemsEditorEx = class(TdxItemsEditorEx)
protected
class procedure InitSubItem(AItemLinks: TdxBarItemLinks); override;
class function GetAddedItemClass(const AAddedItemName: string): TdxBarItemClass; override;
class function GetPopupItemCaption: string; override;
class procedure InitializeAddedItem(AItemLink: TdxBarItemLink; AAddedItemName: string); override;
end;
{ TcxCustomBarEditItem }
TcxCustomBarEditItem = class(TdxCustomBarEdit, IcxEditRepositoryItemListener)
private
FEditData: TcxCustomEditData;
FEditValue: TcxEditValue;
FHeight: Integer;
FPrevIsBlobEditValue: Boolean;
FPrevOnEditValueChanged: TNotifyEvent;
FProperties: TcxCustomEditProperties;
FPropertiesEvents: TNotifyEvent;
FPropertiesValue: TcxCustomEditProperties;
FRepositoryItem: TcxEditRepositoryItem;
FRepositoryItemValue: TcxEditRepositoryItem;
FBarStyleDropDownButton: Boolean;
// IcxEditRepositoryItemListener
procedure IcxEditRepositoryItemListener.ItemRemoved = RepositoryItemItemRemoved;
procedure IcxEditRepositoryItemListener.PropertiesChanged = RepositoryItemPropertiesChanged;
procedure RepositoryItemItemRemoved(Sender: TcxEditRepositoryItem);
procedure RepositoryItemPropertiesChanged(Sender: TcxEditRepositoryItem);
procedure CustomizingDoDrawEditButtonBackground(Sender: TcxCustomEditViewInfo;
ACanvas: TcxCanvas; const ARect: TRect; AButtonVisibleIndex: Integer;
var AHandled: Boolean);
procedure CustomizingDoGetEditDefaultButtonWidth(Sender: TcxCustomEditViewData;
AIndex: Integer; var ADefaultWidth: Integer);
procedure CheckIsBlobEditValue;
procedure CreateProperties(APropertiesClass: TcxCustomEditPropertiesClass);
procedure DestroyProperties;
function GetCurEditValue: TcxEditValue;
function GetPropertiesClass: TcxCustomEditPropertiesClass;
function GetPropertiesClassName: string;
function GetPropertiesValue: TcxCustomEditProperties;
function GetRepositoryItemValue: TcxEditRepositoryItem;
function IsBarCompatibleEdit(AEditProperties: TcxCustomEditProperties = nil): Boolean;
function IsBlobEditValue: Boolean;
function IsEditValueStored(AFiler: TFiler): Boolean;
procedure PropertiesChangedHandler(Sender: TObject);
procedure PropertiesValueChanged;
procedure ReadEditValue(AReader: TReader); overload;
{$HINTS OFF}
procedure ReadEditValue(AStream: TStream); overload;
{$HINTS ON}
procedure SetEditValue(const Value: TcxEditValue);
procedure SetHeight(Value: Integer);
procedure SetProperties(Value: TcxCustomEditProperties);
procedure SetPropertiesClass(Value: TcxCustomEditPropertiesClass);
procedure SetPropertiesClassName(const Value: string);
procedure SetRepositoryItem(Value: TcxEditRepositoryItem);
procedure SetRepositoryItemValue(Value: TcxEditRepositoryItem);
procedure SetBarStyleDropDownButton(Value: Boolean);
procedure UpdateRepositoryItemValue;
function UseBarPaintingStyle: Boolean;
procedure WriteEditValue(AWriter: TWriter); overload;
{$HINTS OFF}
procedure WriteEditValue(AStream: TStream); overload;
{$HINTS ON}
protected
procedure DefineProperties(Filer: TFiler); override;
procedure DrawCustomizingImage(ACanvas: TCanvas; const ARect: TRect;
AState: TOwnerDrawState); override;
procedure DrawCustomizingImageContent(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean); override;
function GetControlClass(AIsVertical: Boolean): TdxBarItemControlClass; override;
function HasAccel(AItemLink: TdxBarItemLink): Boolean; override;
function CanEdit: Boolean;
function CaptionIsEditValue: Boolean;
procedure DoEditValueChanged(Sender: TObject);
procedure PropertiesChanged; virtual;
procedure UpdatePropertiesValue;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DoClick; override;
function GetProperties: TcxCustomEditProperties;
property CurEditValue: TcxEditValue read GetCurEditValue;
property EditValue: TcxEditValue read FEditValue write SetEditValue
stored False;
property Height: Integer read FHeight write SetHeight default 0;
property Properties: TcxCustomEditProperties read FProperties
write SetProperties;
property PropertiesClass: TcxCustomEditPropertiesClass
read GetPropertiesClass write SetPropertiesClass;
property RepositoryItem: TcxEditRepositoryItem read FRepositoryItem
write SetRepositoryItem;
published
property PropertiesClassName: string read GetPropertiesClassName
write SetPropertiesClassName;
property PropertiesEvents: TNotifyEvent read FPropertiesEvents
write FPropertiesEvents;
property BarStyleDropDownButton: Boolean read FBarStyleDropDownButton write SetBarStyleDropDownButton default True;
end;
{ TcxBarEditItem }
TcxBarEditItem = class(TcxCustomBarEditItem)
published
property CanSelect;
property EditValue;
property Height;
property Properties;
property RepositoryItem;
property StyleEdit;
end;
TcxBarEditItemControlEditEvents = record
OnAfterKeyDown: TKeyEvent;
OnChange: TNotifyEvent;
OnClosePopup: TcxEditClosePopupEvent;
OnFocusChanged: TNotifyEvent;
OnInitPopup: TNotifyEvent;
OnKeyDown: TKeyEvent;
OnKeyPress: TKeyPressEvent;
OnKeyUp: TKeyEvent;
OnMouseMove: TMouseMoveEvent;
OnPostEditValue: TNotifyEvent;
OnValidate: TcxEditValidateEvent;
end;
{ TcxBarEditItemControl }
TcxBarEditItemControl = class(TdxBarCustomEditControl)
private
FEdit: TcxCustomEdit;
FEditViewInfo: TcxCustomEditViewInfo;
FSavedEditEvents: TcxBarEditItemControlEditEvents;
procedure ClearEditEvents;
procedure InternalShowEdit;
procedure SaveEditEvents;
procedure DoAfterKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DoCustomDrawPopupBorder(AViewInfo: TcxContainerViewInfo; ACanvas: TcxCanvas; const R: TRect; var AHandled: Boolean;
out ABorderWidth: Integer);
procedure DoDrawEditBackground(Sender: TcxCustomEditViewInfo;
ACanvas: TcxCanvas; var AHandled: Boolean);
procedure DoDrawEditButton(Sender: TcxCustomEditViewInfo;
ACanvas: TcxCanvas; AButtonVisibleIndex: Integer; var AHandled: Boolean);
procedure DoDrawEditButtonBackground(Sender: TcxCustomEditViewInfo;
ACanvas: TcxCanvas; const ARect: TRect; AButtonVisibleIndex: Integer;
var AHandled: Boolean);
procedure DoDrawEditButtonBorder(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; AButtonVisibleIndex: Integer;
out ABackgroundRect, AContentRect: TRect; var AHandled: Boolean);
procedure DoEditPaint(Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas);
procedure DoEditClosePopup(Sender: TcxControl; AReason: TcxEditCloseUpReason);
procedure DoEditPropertiesChange(Sender: TObject);
procedure DoGetEditButtonState(Sender: TcxCustomEditViewInfo;
AButtonVisibleIndex: Integer; var AState: TcxEditButtonState);
procedure DoGetEditDefaultButtonWidth(Sender: TcxCustomEditViewData;
AIndex: Integer; var ADefaultWidth: Integer);
procedure DoFocusChanged(Sender: TObject);
procedure DoInitPopup(Sender: TObject);
procedure DoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DoKeyPress(Sender: TObject; var Key: Char);
procedure DoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure DoPostEditValue(Sender: TObject);
procedure DoValidate(Sender: TObject; var DisplayValue: TcxEditValue;
var ErrorText: TCaption; var Error: Boolean);
function GetEditButtonState(AButtonViewInfo: TcxEditButtonViewInfo): Integer;
procedure AssignViewInfoEvents(AViewInfo: TcxCustomEditViewInfo);
procedure ClearViewInfoEvents(AViewInfo: TcxCustomEditViewInfo);
procedure DrawEditBackground(ACanvas: TcxCanvas; ARect: TRect; AColor: TColor);
function GetBoundsRect: TRect;
function GetCurEditValue: TcxEditValue;
function GetDefaultEditButtonWidth(AIndex: Integer): Integer;
function GetDropDownEdit: TcxCustomDropDownEdit;
function GetEditSize: TSize;
function GetEditStyle: TcxEditStyle;
function GetEditViewInfo: TcxCustomEditViewInfo;
function GetItem: TcxCustomBarEditItem;
function GetProperties: TcxCustomEditProperties;
procedure InitEditContentParams(var AParams: TcxEditContentParams);
function IsDropDownEdit: Boolean;
function IsPopupSideward: Boolean;
function NeedEditShowCaption: Boolean;
property DropDownEdit: TcxCustomDropDownEdit read GetDropDownEdit;
protected
procedure ActivateEdit(AByMouse: Boolean; AKey: Char = #0); override;
procedure CalcDrawParams(AFull: Boolean = True); override;
procedure CalcParts; override;
function CanHide: Boolean; override;
function CanSelect: Boolean; override;
procedure CheckHotTrack(APoint: TPoint); override;
procedure ControlInactivate(Immediately: Boolean); override;
procedure DoPaint(ARect: TRect; PaintType: TdxBarPaintType); override;
procedure DoMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure DrawTextField; override;
function GetControl: TControl; override;
function GetHandle: HWND; override;
function GetDefaultHeight: Integer; override;
function GetMinEditorWidth: Integer; override;
function GetPartCount: Integer; override;
function GetShowCaption: Boolean; override;
function GetCaptionAreaWidth: Integer; override;
function GetControlAreaWidth: Integer; override;
function GetPossibleViewLevels: TdxBarItemViewLevels; override;
procedure Hide(AStoreDisplayValue: Boolean); override;
procedure InitEdit; override;
function IsChildWindow(AWnd: HWND): Boolean; override;
function IsEditTransparent: Boolean; override;
function IsTransparentOnGlass: Boolean; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure ParentVisibleChange(AIsShowing: Boolean); override;
procedure RestoreDisplayValue; override;
procedure Show; override;
procedure StoreDisplayValue; override;
function WantsKey(Key: Word): Boolean; override;
procedure CalculateEditViewInfo(const ABounds: TRect; P: TPoint;
AIsMouseEvent: Boolean; AEditViewInfo: TcxCustomEditViewInfo = nil; AFull: Boolean = True);
function CreateEditViewData(AFull: Boolean = True): TcxCustomEditViewData;
function CreateEditViewInfo: TcxCustomEditViewInfo;
property EditStyle: TcxEditStyle read GetEditStyle;
property EditViewInfo: TcxCustomEditViewInfo read GetEditViewInfo;
property Item: TcxCustomBarEditItem read GetItem;
property Properties: TcxCustomEditProperties read GetProperties;
public
destructor Destroy; override;
function IsDroppedDown: Boolean; override;
property CurEditValue: TcxEditValue read GetCurEditValue;
property Edit: TcxCustomEdit read FEdit;
end;
implementation
uses
{$IFDEF DELPHI6}
Variants,
{$ELSE}
Consts, TypInfo,
{$ENDIF}
Forms, SysUtils, cxBarEditItemValueEditor, cxClasses, cxEditPaintUtils,
cxEditRepositoryItems, cxEditUtils, cxLookAndFeelPainters, cxTextEdit,
cxVariants, dxBarCustForm, dxOffice11, dxBarStrs, dxBarSkinConsts;//, cxDWMApi;
const
MinContentWidth = 9;
type
TControlAccess = class(TControl);
{$IFNDEF DELPHI6}
TReaderAccess = class(TReader);
TWriterAccess = class(TWriter);
{$ENDIF}
TdxBarManagerAccess = class(TdxBarManager);
TdxBarSubMenuControlAccess = class(TdxBarSubMenuControl);
{ TFakeWinControl }
TFakeWinControl = class(TWinControl)
protected
procedure CreateWnd; override;
procedure DestroyWindowHandle; override;
procedure DestroyWnd; override;
public
destructor Destroy; override;
end;
{ TEditorParentForm }
TEditorParentForm = class(TCustomForm)
public
destructor Destroy; override;
procedure GetTabOrderList(List: TList); override;
function SetFocusedControl(Control: TWinControl): Boolean; override;
end;
{ TcxBarEditItemVerticalButtonControl }
TcxBarEditItemVerticalButtonControl = class(TdxBarButtonControl)
private
function CanEdit: Boolean;
protected
function CanClicked: Boolean; override;
function CanSelect: Boolean; override;
function GetPaintStyle: TdxBarPaintStyle; override;
end;
var
FDefaultRepositoryItem: TcxEditRepositoryItem;
FEditList: TcxInplaceEditList;
FEditorParentForm: TEditorParentForm;
FEditStyle: TcxEditStyle;
FFakeWinControl: TFakeWinControl;
function DefaultRepositoryItem: TcxEditRepositoryItem;
procedure CreateDefaultRepositoryItem;
begin
FDefaultRepositoryItem := TcxEditRepositoryTextItem.Create(nil);
end;
begin
if FDefaultRepositoryItem = nil then
CreateDefaultRepositoryItem;
Result := FDefaultRepositoryItem;
end;
function EditList: TcxInplaceEditList;
begin
if FEditList = nil then
FEditList := TcxInplaceEditList.Create;
Result := FEditList;
end;
function EditorParentForm: TEditorParentForm;
begin
if FEditorParentForm = nil then
begin
FEditorParentForm := TEditorParentForm.CreateNew(nil);
FEditorParentForm.Position := poDesigned;
FEditorParentForm.Name := 'EditorParentForm';
FEditorParentForm.BorderStyle := bsNone;
end;
Result := FEditorParentForm;
end;
function FakeWinControl: TFakeWinControl;
begin
if FFakeWinControl = nil then
begin
FFakeWinControl := TFakeWinControl.Create(nil); //#!!!
FFakeWinControl.Name := 'FakeWinControl';
end;
Result := FFakeWinControl;
end;
function InternalGetEditStyle(AEditProperties: TcxCustomEditProperties; ABarManager: TdxBarManager;
APainter: TdxBarPainter; AFont: TFont; AColor, ATextColor: TColor; ADrawSelected: Boolean): TcxEditStyle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -