📄 cxbaredititem.pas
字号:
Result := 0;
end;
function TcxBarEditItemControl.GetDefaultHeight: Integer;
var
AEditHeight: Integer;
begin
Result := inherited GetDefaultHeight;
AEditHeight := GetEditSize.cy;
if Result < AEditHeight then
Result := AEditHeight;
if Result < Item.Height then
Result := Item.Height;
end;
function TcxBarEditItemControl.GetMinEditorWidth: Integer;
begin
Result := GetEditSize.cx;
end;
function TcxBarEditItemControl.GetPartCount: Integer;
begin
Result := inherited GetPartCount;
if Item.UseBarPaintingStyle then
Inc(Result);
end;
function TcxBarEditItemControl.GetShowCaption: Boolean;
begin
if Item.CaptionIsEditValue then
Result := False
else
Result := inherited GetShowCaption;
end;
function TcxBarEditItemControl.GetCaptionAreaWidth: Integer;
begin
if NeedEditShowCaption then
if (GetPaintType = ptMenu) and Painter.SubMenuControlHasBand and not (cpIcon in GetViewStructure) then
Result := TdxBarSubMenuControlAccess(SubMenuParent).BandSize
else
Result := 0
else
Result := inherited GetCaptionAreaWidth;
end;
function TcxBarEditItemControl.GetControlAreaWidth: Integer;
begin
if NeedEditShowCaption then
Result := GetMinEditorWidth
else
Result := inherited GetControlAreaWidth;
end;
function TcxBarEditItemControl.GetPossibleViewLevels: TdxBarItemViewLevels;
begin
Result := inherited GetPossibleViewLevels;
if Item.CaptionIsEditValue then
Result := Result - [ivlSmallIconWithText];
end;
procedure TcxBarEditItemControl.Hide(AStoreDisplayValue: Boolean);
begin
if Edit <> nil then
if not (csDestroying in BarManager.ComponentState) then
begin
if not IsWindowEnabled then
begin
Item.FPrevOnEditValueChanged := Edit.InternalProperties.OnEditValueChanged;
Edit.InternalProperties.OnEditValueChanged := Item.DoEditValueChanged;
end;
FakeWinControl.Parent := nil;
EditorParentForm.SetBounds(0, 0, 0, 0);
DisableAppWindows(not IsApplicationActive);
try
EditorParentForm.FocusControl(nil); // must be before Parent:=nil because DoEnter in WinControl Activate
Edit.Parent := nil; // must be before DefocusControl
if IsDropDownEdit then
DropDownEdit.PopupWindow.ActiveControl := nil;
finally
EnableAppWindows;
end;
EditorParentForm.DefocusControl(Edit, True); // must be before ClearEditEvents;
ClearEditEvents;
ClearViewInfoEvents(Edit.ViewInfo);
EditorParentForm.Visible := False;
EditorParentForm.ParentWindow := 0;
Item.DoExit;
if AStoreDisplayValue then
StoreDisplayValue;
FEdit := nil;
end
else
begin
ClearEditEvents;
ClearViewInfoEvents(Edit.ViewInfo);
end;
end;
procedure TcxBarEditItemControl.InitEdit;
procedure SetEditButtonsWidth;
var
AButton: TcxEditButton;
I: Integer;
begin
Edit.InternalProperties.BeginUpdate;
try
for I := 0 to Edit.InternalProperties.Buttons.Count - 1 do
begin
AButton := Edit.InternalProperties.Buttons[I];
if AButton.Visible and (AButton.Width = 0) then
AButton.Width := GetDefaultEditButtonWidth(I);
end;
finally
Edit.InternalProperties.EndUpdate;
end;
end;
procedure InitEditProperties;
begin
Edit.LockChangeEvents(True);
try
Edit.InternalProperties.Assign(Properties);
finally
Edit.LockChangeEvents(False, False);
end;
SetEditButtonsWidth;
end;
procedure AssignEditEvents;
begin
SaveEditEvents;
Edit.InternalProperties.OnChange := DoEditPropertiesChange;
Edit.InternalProperties.OnClosePopup := DoEditClosePopup;
Edit.InternalProperties.OnValidate := DoValidate;
Edit.OnFocusChanged := DoFocusChanged;
Edit.OnKeyDown := DoKeyDown;
Edit.OnKeyPress := DoKeyPress;
Edit.OnKeyUp := DoKeyUp;
Edit.OnMouseMove := DoMouseMove;
Edit.OnPostEditValue := DoPostEditValue;
if IsDropDownEdit then
begin
DropDownEdit.OnAfterKeyDown := DoAfterKeyDown;
DropDownEdit.Properties.OnInitPopup := DoInitPopup;
DropDownEdit.PopupWindow.ViewInfo.OnCustomDrawBorder := DoCustomDrawPopupBorder;
end;
end;
var
ISpellCheckerEdit: IdxSpellCheckerSupport;
begin
FEdit := EditList.GetEdit(TcxCustomEditPropertiesClass(Properties.ClassType));
// #SC todo:
if Supports(TObject(FEdit), IdxSpellCheckerSupport, ISpellCheckerEdit) then
ISpellCheckerEdit.SetIsBarControl(True);
//#DG (RichEdit want handle) RestoreDisplayValue;
InitEditProperties;
Edit.Style := EditStyle;
InitEditContentParams(Edit.ContentParams);
AssignViewInfoEvents(Edit.ViewInfo);
AssignEditEvents;
end;
function TcxBarEditItemControl.IsChildWindow(AWnd: HWND): Boolean;
begin
Result := inherited IsChildWindow(AWnd) or (Edit <> nil) and (Edit.IsChildWindow(AWnd));
end;
function TcxBarEditItemControl.IsEditTransparent: Boolean;
begin
Result := esoTransparency in Properties.GetSupportedOperations;
end;
function TcxBarEditItemControl.IsTransparentOnGlass: Boolean;
begin
Result := IsEditTransparent;
end;
procedure TcxBarEditItemControl.KeyDown(var Key: Word; Shift: TShiftState);
begin
if not Focused then
begin
Click(False, Char(Key));
Key := 0;
end
else
inherited KeyDown(Key, Shift);
end;
procedure TcxBarEditItemControl.ParentVisibleChange(AIsShowing: Boolean);
const
AShowParams: array[Boolean] of Integer = (SW_HIDE, SW_SHOWNOACTIVATE);
begin
if IsDropDownEdit and DropDownEdit.HasPopupWindow then
ShowWindow(DropDownEdit.PopupWindow.Handle, AShowParams[AIsShowing]);
end;
procedure TcxBarEditItemControl.RestoreDisplayValue;
begin
Edit.LockChangeEvents(True);
try
if CanSelect then
begin
Edit.EditValue := Item.EditValue;
if esoShowingCaption in Properties.GetSupportedOperations then
if NeedEditShowCaption then
TControlAccess(Edit).Caption := Caption
else
TControlAccess(Edit).Caption := '';
end;
finally
Edit.LockChangeEvents(False, False);
end;
end;
procedure TcxBarEditItemControl.Show;
begin
inherited Show;
InternalShowEdit;
RestoreDisplayValue;
Item.DoEnter;
end;
procedure TcxBarEditItemControl.StoreDisplayValue;
begin
Edit.Deactivate;
Item.GetProperties.BeginUpdate;
try
Edit.ActiveProperties.Update(Item.GetProperties);
finally
Item.GetProperties.EndUpdate(False);
end;
Item.EditValue := Edit.EditValue;
end;
function TcxBarEditItemControl.WantsKey(Key: Word): Boolean;
begin
Result := inherited WantsKey(Key) or Properties.IsActivationKey(Char(Key));
end;
procedure TcxBarEditItemControl.CalculateEditViewInfo(const ABounds: TRect;
P: TPoint; AIsMouseEvent: Boolean; AEditViewInfo: TcxCustomEditViewInfo; AFull: Boolean);
function CanHotTrack: Boolean;
begin
Result := not (Item.IsDesigning or Parent.IsCustomizing) and IsWindowEnabled and Painter.EditButtonAllowHotTrack(FDrawParams);
end;
var
AViewData: TcxCustomEditViewData;
AViewInfo: TcxCustomEditViewInfo;
begin
if AEditViewInfo <> nil then
AViewInfo := AEditViewInfo
else
AViewInfo := EditViewInfo;
AViewData := CreateEditViewData(AFull);
try
if not CanHotTrack then
P := Point(-1, -1);
AssignViewInfoEvents(AViewInfo);
if Item.CaptionIsEditValue then
AViewData.EditValueToDrawValue(Canvas, Caption, AViewInfo)
else
AViewData.EditValueToDrawValue(Canvas, Item.EditValue, AViewInfo);
if not Item.CaptionIsEditValue and NeedEditShowCaption then
TcxCustomTextEditViewInfo(AViewInfo).Text := Caption;
BarCanvas.BeginPaint(Canvas.Canvas);
try
AViewData.Calculate(BarCanvas, ABounds, P, cxmbNone, [], AViewInfo, AIsMouseEvent);
finally
BarCanvas.EndPaint;
end;
if AFull then
CalcParts;
finally
AViewData.Free;
end;
end;
function TcxBarEditItemControl.CreateEditViewData(AFull: Boolean = True): TcxCustomEditViewData;
begin
Result := Properties.CreateViewData(EditStyle, True);
Result.Enabled := Enabled;
if AFull then
InitEditContentParams(Result.EditContentParams);
Result.OnGetDefaultButtonWidth := DoGetEditDefaultButtonWidth;
end;
function TcxBarEditItemControl.CreateEditViewInfo: TcxCustomEditViewInfo;
begin
Result := TcxCustomEditViewInfo(Properties.GetViewInfoClass.Create);
end;
procedure TcxBarEditItemControl.ClearEditEvents;
begin
Edit.InternalProperties.OnChange := nil;
Edit.InternalProperties.OnClosePopup := nil;
Edit.InternalProperties.OnValidate := nil;
Edit.OnFocusChanged := nil;
Edit.OnKeyDown := nil;
Edit.OnKeyPress := nil;
Edit.OnKeyUp := nil;
Edit.OnMouseMove := nil;
Edit.OnPostEditValue := nil;
if IsDropDownEdit then
begin
DropDownEdit.OnAfterKeyDown := nil;
DropDownEdit.Properties.OnInitPopup := nil;
DropDownEdit.PopupWindow.ViewInfo.OnCustomDrawBorder := nil;
end;
end;
procedure TcxBarEditItemControl.InternalShowEdit;
begin
EditorParentForm.ParentWindow := Parent.Handle;
EditorParentForm.BoundsRect := GetBoundsRect;
Edit.Align := alClient;
Edit.Parent := EditorParentForm;
Edit.Visible := True; {#DG TODO: MUST BE CHECKED BY SERG}
TControl(EditorParentForm).Visible := True;
end;
procedure TcxBarEditItemControl.SaveEditEvents;
begin
FSavedEditEvents.OnChange := Edit.InternalProperties.OnChange;
FSavedEditEvents.OnClosePopup := Edit.InternalProperties.OnClosePopup;
FSavedEditEvents.OnValidate := Edit.InternalProperties.OnValidate;
FSavedEditEvents.OnFocusChanged := Edit.OnFocusChanged;
FSavedEditEvents.OnKeyDown := Edit.OnKeyDown;
FSavedEditEvents.OnKeyPress := Edit.OnKeyPress;
FSavedEditEvents.OnKeyUp := Edit.OnKeyUp;
FSavedEditEvents.OnMouseMove := Edit.OnMouseMove;
FSavedEditEvents.OnPostEditValue := Edit.OnPostEditValue;
if IsDropDownEdit then
begin
FSavedEditEvents.OnAfterKeyDown := DropDownEdit.OnAfterKeyDown;
FSavedEditEvents.OnInitPopup := DropDownEdit.Properties.OnInitPopup;
end;
end;
procedure TcxBarEditItemControl.DoAfterKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Assigned(FSavedEditEvents.OnAfterKeyDown) then
FSavedEditEvents.OnAfterKeyDown(Sender, Key, Shift);
if Key = VK_TAB then
KeyDown(Key, Shift);
end;
procedure TcxBarEditItemControl.DoCustomDrawPopupBorder(AViewInfo: TcxContainerViewInfo; ACanvas: TcxCanvas; const R: TRect; var AHandled: Boolean;
out ABorderWidth: Integer);
begin
AHandled := True;
ABorderWidth := Painter.GetPopupWindowBorderWidth;
if (ACanvas <> nil) then
Painter.DropDownListBoxDrawBorder(ACanvas.Handle, AViewInfo.BackgroundColor, R);
end;
procedure TcxBarEditItemControl.DoDrawEditBackground(
Sender: TcxCustomEditViewInfo; ACanvas: TcxCanvas; var AHandled: Boolean);
var
APrevWindowOrg: TPoint;
ABounds: TRect;
begin
AHandled := IsEditTransparent;
if AHandled and (ACanvas <> nil) then
begin
ABounds := Sender.Bounds;
BeforeDrawBackground(Sender.Edit, Edit, ACanvas.Handle, ABounds, APrevWindowOrg);
try
DrawEditBackground(ACanvas, ABounds, Sender.BackgroundColor);
finally
AfterDrawBackground(ACanvas.Handle, APrevWindowOrg);
end;
end;
end;
procedure TcxBarEditItemControl.DoDrawEditButton(Sender: TcxCustomEditViewInfo;
ACanvas: TcxCanvas; AButtonVisibleIndex: Integer; var AHandled: Boolean);
var
APrevWindowOrg: TPoint;
AOriginalCanvas: TcxCanvas;
ARect: TRect;
AUseParentCanvas: Boolean;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -