From: <ah...@us...> - 2006-10-11 16:38:53
|
Revision: 10972 http://svn.sourceforge.net/jvcl/?rev=10972&view=rev Author: ahuser Date: 2006-10-11 09:38:43 -0700 (Wed, 11 Oct 2006) Log Message: ----------- - Fixed: ColEnter and ColExit aren't called when the row was changed but not not column. - Fixed: When the CM_EXIT message handler of the FCurrentControl raised an exception and set the focus back to the control, a EInvalidOperation was raised (Disabled or invisible control cannot get the focus) Modified Paths: -------------- trunk/jvcl/run/JvDBGrid.pas Modified: trunk/jvcl/run/JvDBGrid.pas =================================================================== --- trunk/jvcl/run/JvDBGrid.pas 2006-10-11 14:44:30 UTC (rev 10971) +++ trunk/jvcl/run/JvDBGrid.pas 2006-10-11 16:38:43 UTC (rev 10972) @@ -272,6 +272,7 @@ FChangeLinks: TObjectList; FShowMemos: Boolean; FAlwaysShowEditor: Boolean; + FInColExit: Boolean; procedure SetAutoSizeRows(Value: Boolean); procedure SetRowResize(Value: Boolean); @@ -538,7 +539,7 @@ {$IFDEF HAS_UNIT_VARIANTS} Variants, {$ENDIF HAS_UNIT_VARIANTS} - SysUtils, Math, TypInfo, Forms, Dialogs, DBConsts, + SysUtils, Math, TypInfo, Forms, Dialogs, DBConsts, {$IFDEF COMPILER6_UP} StrUtils, JvDBLookup, @@ -601,6 +602,23 @@ Grid.InvalidateCell(I, Row); end; +type + TPublishedGrid = class(TDBGrid) + published + property Col; + property Row; + end; + +procedure SetIntGetterProp(Instance: TObject; const PropName: string; Value: Integer); +var + Info: PPropInfo; +begin + Info := GetPropInfo(TPublishedGrid, PropName); + if Info <> nil then + if Cardinal(Info.GetProc) and $FF000000 = $FF000000 then + PInteger(Cardinal(Instance) + (Cardinal(Info.GetProc) and $00FFFFFF))^ := Value; +end; + //=== { TInternalInplaceEdit } =============================================== {$IFDEF COMPILER6_UP} @@ -2023,7 +2041,7 @@ procedure TJvDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var - Cell: TGridCoord; + Cell, LastCell: TGridCoord; MouseDownEvent: TMouseEvent; EnableClick: Boolean; CursorPos: TPoint; @@ -2044,6 +2062,8 @@ else begin Cell := MouseCoord(X, Y); + LastCell.X := Col; + LastCell.Y := Row; if (Button = mbRight) and (dgTitles in Options) and (dgIndicator in Options) and @@ -2115,6 +2135,28 @@ inherited MouseDown(Button, Shift, 1, Y) else inherited MouseDown(Button, Shift, X, Y); + if (Cell.X = LastCell.X) and (Cell.Y <> LastCell.Y) then + begin + // invoke missing ColExit and ColEnter + if not FInColExit then + begin + FInColExit := True; + try + SetIntGetterProp(Self, 'Col', LastCell.X); + SetIntGetterProp(Self, 'Row', LastCell.Y); + ColExit; + finally + FInColExit := False; + end; + if (Row <> LastCell.Y) then + Exit; + SetIntGetterProp(Self, 'Col', Cell.X); + SetIntGetterProp(Self, 'Row', Cell.Y); + end; + if not (dgAlwaysShowEditor in Options) then + HideEditor; + ColEnter; + end; end; MouseDownEvent := OnMouseDown; if Assigned(MouseDownEvent) then @@ -3928,9 +3970,20 @@ procedure TJvDBGrid.CloseControl; begin - HideCurrentControl; - if Self.Visible then - Self.SetFocus; + { Do not hide the control if it has the focus because then the WM_KILLFOCUS + ControlWndProc hook will hide it. } + if not Visible or (FCurrentControl = nil) or not FCurrentControl.HandleAllocated or + not FCurrentControl.Focused then + HideCurrentControl; + if Visible then + begin + SetFocus; + { If the grid does not have the focus after a SetFocus, one of the executed + CM_EXIT has failed with an exception or has set the focus to another control. + In that case the CurrentControl is still active. } + if (FCurrentControl <> nil) and FCurrentControl.Focused then + Abort; + end; end; procedure TJvDBGrid.ControlWndProc(var Message: TMessage); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |