improved grids e.g. OnPrepareCanvas patch from Jesus

git-svn-id: trunk@5469 -
This commit is contained in:
mattias 2004-05-14 12:53:25 +00:00
parent f0b3974618
commit e1f1af3fb2
7 changed files with 409 additions and 340 deletions

View File

@ -33,21 +33,20 @@ todo: credit who created the TComponentDatalink idea (Johana ...)
unit DBGrids; unit DBGrids;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{.$define protodbgrid}
interface interface
uses uses
Classes, LCLProc, Graphics, SysUtils, LCLType, stdctrls, DB, LMessages, Grids, Classes, LCLProc, Graphics, SysUtils, LCLType, stdctrls, DB, LMessages, Grids,
Controls; Controls;
Type type
TDataSetScrolledEvent = Procedure(DataSet: TDataSet; Distance: Integer) of Object; TDataSetScrolledEvent = procedure(DataSet: TDataSet; Distance: Integer) of object;
Type type
TComponentDataLink=Class(TDatalink) TComponentDataLink=class(TDatalink)
private private
FDataSet: TDataSet; FDataSet: TDataSet;
FDataSetName: String; FDataSetName: string;
FModified: Boolean; FModified: Boolean;
FOnDatasetChanged: TDatasetNotifyEvent; FOnDatasetChanged: TDatasetNotifyEvent;
fOnDataSetClose: TDataSetNotifyEvent; fOnDataSetClose: TDataSetNotifyEvent;
@ -57,103 +56,98 @@ Type
fOnInvalidDataSource: TDataSetNotifyEvent; fOnInvalidDataSource: TDataSetNotifyEvent;
fOnNewDataSet: TDataSetNotifyEvent; fOnNewDataSet: TDataSetNotifyEvent;
FOnRecordChanged: TFieldNotifyEvent; FOnRecordChanged: TFieldNotifyEvent;
function GetDataSetName: String; function GetDataSetName: string;
function GetFields(Index: Integer): TField; function GetFields(Index: Integer): TField;
procedure SetDataSetName(const AValue: String); procedure SetDataSetName(const AValue: string);
Protected protected
procedure RecordChanged(Field: TField); override; procedure RecordChanged(Field: TField); override;
Procedure DataSetChanged; Override; procedure DataSetChanged; override;
procedure ActiveChanged; override; procedure ActiveChanged; override;
procedure LayoutChanged; override; procedure LayoutChanged; override;
procedure DataSetScrolled(Distance: Integer); override; procedure DataSetScrolled(Distance: Integer); override;
procedure FocusControl(Field: TFieldRef); override; procedure FocusControl(Field: TFieldRef); override;
// Testing Events // Testing Events
procedure CheckBrowseMode; Override; procedure CheckBrowseMode; override;
procedure EditingChanged; Override; procedure EditingChanged; override;
procedure UpdateData; Override; procedure UpdateData; override;
function MoveBy(Distance: Integer): Integer; Override; function MoveBy(Distance: Integer): Integer; override;
Public public
Procedure Modified; procedure Modified;
Property OnRecordChanged: TFieldNotifyEvent Read FOnRecordChanged Write FOnRecordChanged; Property OnRecordChanged: TFieldNotifyEvent read FOnRecordChanged write FOnRecordChanged;
Property OnDataSetChanged: TDatasetNotifyEvent Read FOnDatasetChanged Write FOnDataSetChanged; Property OnDataSetChanged: TDatasetNotifyEvent read FOnDatasetChanged write FOnDataSetChanged;
property OnNewDataSet: TDataSetNotifyEvent read fOnNewDataSet write fOnNewDataSet; property OnNewDataSet: TDataSetNotifyEvent read fOnNewDataSet write fOnNewDataSet;
property OnDataSetOpen: TDataSetNotifyEvent read fOnDataSetOpen write fOnDataSetOpen; property OnDataSetOpen: TDataSetNotifyEvent read fOnDataSetOpen write fOnDataSetOpen;
property OnInvalidDataSet: TDataSetNotifyEvent read fOnInvalidDataSet write fOnInvalidDataSet; property OnInvalidDataSet: TDataSetNotifyEvent read fOnInvalidDataSet write fOnInvalidDataSet;
property OnInvalidDataSource: TDataSetNotifyEvent read fOnInvalidDataSource write fOnInvalidDataSource; property OnInvalidDataSource: TDataSetNotifyEvent read fOnInvalidDataSource write fOnInvalidDataSource;
property OnDataSetClose: TDataSetNotifyEvent read fOnDataSetClose write fOnDataSetClose; property OnDataSetClose: TDataSetNotifyEvent read fOnDataSetClose write fOnDataSetClose;
Property OnDataSetScrolled: TDataSetScrolledEvent Read FOnDataSetScrolled Write FOnDataSetScrolled; Property OnDataSetScrolled: TDataSetScrolledEvent read FOnDataSetScrolled write FOnDataSetScrolled;
Property DataSetName:String Read GetDataSetName Write SetDataSetName; Property DataSetName:string read GetDataSetName write SetDataSetName;
Property Fields[Index: Integer]: TField read GetFields; Property Fields[Index: Integer]: TField read GetFields;
End; end;
TCustomDbGrid=Class(TCustomGrid) TCustomDbGrid=class(TCustomGrid)
Private private
FDataLink: TComponentDataLink; FDataLink: TComponentDataLink;
FKeepInBuffer: Boolean; FKeepInBuffer: Boolean;
FOnColEnter: TNotifyEvent; FOnColEnter: TNotifyEvent;
FOnColExit: TNotifyEvent; FOnColExit: TNotifyEvent;
FReadOnly: Boolean; FReadOnly: Boolean;
FColEnterPending: Boolean; FColEnterPending: Boolean;
FSelfScroll: Boolean; //FSelfScroll: Boolean;
FLayoutChanging: Boolean; FLayoutChanging: Boolean;
FVisualLock: Boolean; FVisualLock: Boolean;
FNumRecords: Integer; FNumRecords: Integer;
function GetDataSource: TDataSource; function GetDataSource: TDataSource;
Procedure OnRecordChanged(Field:TField); procedure OnRecordChanged(Field:TField);
Procedure OnDataSetChanged(aDataSet: TDataSet); procedure OnDataSetChanged(aDataSet: TDataSet);
Procedure OnDataSetOpen(aDataSet: TDataSet); procedure OnDataSetOpen(aDataSet: TDataSet);
Procedure OnDataSetClose(aDataSet: TDataSet); procedure OnDataSetClose(aDataSet: TDataSet);
Procedure OnInvalidDataSet(aDataSet: TDataSet); procedure OnInvalidDataSet(aDataSet: TDataSet);
Procedure OnInvalidDataSource(aDataSet: TDataset); procedure OnInvalidDataSource(aDataSet: TDataset);
Procedure OnNewDataSet(aDataSet: TDataset); procedure OnNewDataSet(aDataSet: TDataset);
Procedure OnDataSetScrolled(aDataSet:TDataSet; Distance: Integer); procedure OnDataSetScrolled(aDataSet:TDataSet; Distance: Integer);
procedure SetDataSource(const AValue: TDataSource); procedure SetDataSource(const AValue: TDataSource);
Procedure UpdateBufferCount; procedure UpdateBufferCount;
// Temporal // Temporal
Function DefaultFieldColWidth(FieldType: TFieldType): Integer; function DefaultFieldColWidth(FieldType: TFieldType): Integer;
Protected protected
procedure LinkActive(Value: Boolean); virtual; procedure LinkActive(Value: Boolean); virtual;
Procedure LayoutChanged; Virtual; procedure LayoutChanged; virtual;
Property ReadOnly: Boolean Read FReadOnly Write FReadOnly; procedure DefineProperties(Filer: TFiler); override;
property DataSource: TDataSource read GetDataSource write SetDataSource; procedure DrawByRows; override;
Procedure DrawByRows; Override; procedure DrawRow(ARow: Integer); override;
Procedure DrawRow(ARow: Integer); Override; procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override;
Procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); Override;
{$Ifdef protodbgrid} procedure MoveSelection; override;
Function BeyondRowCount(Count: Integer):Boolean; Override; procedure BeforeMoveSelection(const DCol,DRow: Integer); override;
Function BelowFirstRow(Count: Integer):Boolean; Override; procedure HeaderClick(IsColumn: Boolean; index: Integer); override;
procedure UpdateGridScrollPosition(DCol,DRow: Integer; InvAll: Boolean); Override; procedure KeyDown(var Key : Word; Shift : TShiftState); override;
{$endif protodbgrid}
Procedure MoveSelection; Override;
Procedure BeforeMoveSelection(Const DCol,DRow: Integer); Override;
procedure HeaderClick(IsColumn: Boolean; index: Integer); Override;
procedure KeyDown(var Key : Word; Shift : TShiftState); Override;
Procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
function ScrollBarAutomatic(Which: TScrollStyle): boolean; override; function ScrollBarAutomatic(Which: TScrollStyle): boolean; override;
{ {
Procedure MouseMove(Shift: TShiftState; X,Y: Integer);Override; procedure MouseMove(Shift: TShiftState; X,Y: Integer);override;
Procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override; procedure MouseUp(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
} }
Procedure VisualChange; Override; procedure VisualChange; override;
Procedure WMHScroll(var Message : TLMHScroll); message LM_HScroll; procedure WMVScroll(var Message : TLMVScroll); message LM_VScroll;
Procedure WMVScroll(var Message : TLMVScroll); message LM_VScroll;
procedure UpdateActive; procedure UpdateActive;
property DataSource: TDataSource read GetDataSource write SetDataSource;
Property KeepInBuffer: Boolean read FKeepInBuffer write FKeepInBuffer;
Property ReadOnly: Boolean read FReadOnly write FReadOnly;
property OnColEnter: TNotifyEvent read FOnColEnter write FOnColEnter; property OnColEnter: TNotifyEvent read FOnColEnter write FOnColEnter;
property OnColExit: TNotifyEvent read FOnColExit write FOnColExit; property OnColExit: TNotifyEvent read FOnColExit write FOnColExit;
Property KeepInBuffer: Boolean read FKeepInBuffer write FKeepInBuffer; public
Public Constructor Create(AOwner: TComponent); override;
Constructor Create(AOwner: TComponent); Override; Destructor Destroy; override;
Destructor Destroy; Override; end;
End;
TdbGrid=Class(TCustomDbGrid) TdbGrid=class(TCustomDbGrid)
public public
property Canvas; property Canvas;
//property SelectedRows; //property SelectedRows;
@ -213,9 +207,9 @@ Type
//property OnStartDock; //property OnStartDock;
//property OnStartDrag; //property OnStartDrag;
//property OnTitleClick; //property OnTitleClick;
End; end;
Procedure Register; procedure Register;
implementation implementation
@ -230,9 +224,9 @@ end;
procedure TCustomDbGrid.OnRecordChanged(Field: TField); procedure TCustomDbGrid.OnRecordChanged(Field: TField);
begin begin
{$IfDef dbgdbgrid} {$IfDef dbgdbgrid}
DBGOut('(',name,') ','TCustomDBGrid.OnRecordChanged(Field='); DBGOut('('+name+') ','TCustomDBGrid.OnRecordChanged(Field=');
If Field=nil Then DebugLn('nil)') if Field=nil then DebugLn('nil)')
Else DebugLn(Field.FieldName,')'); else DebugLn(Field.FieldName,')');
{$Endif} {$Endif}
end; end;
@ -244,9 +238,9 @@ end;
procedure TCustomDbGrid.OnDataSetChanged(aDataSet: TDataSet); procedure TCustomDbGrid.OnDataSetChanged(aDataSet: TDataSet);
begin begin
{$Ifdef dbgdbgrid} {$Ifdef dbgdbgrid}
DBGOut('(',name,') ','TCustomDBDrid.OnDataSetChanged(aDataSet='); DBGOut('('+name+') ','TCustomDBDrid.OnDataSetChanged(aDataSet=');
If aDataSet=nil Then DebugLn('nil)') if aDataSet=nil then DebugLn('nil)')
Else DebugLn(aDataSet.Name,')'); else DebugLn(aDataSet.Name,')');
{$endif} {$endif}
UpdateActive; UpdateActive;
end; end;
@ -296,10 +290,10 @@ end;
procedure TCustomDbGrid.OnDataSetScrolled(aDataset: TDataSet; Distance: Integer); procedure TCustomDbGrid.OnDataSetScrolled(aDataset: TDataSet; Distance: Integer);
begin begin
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn(ClassName, ' (',name,')', '.OnDataSetScrolled(',Distance,'), Invalidating'); DebugLn(ClassName, ' (',name,')', '.OnDataSetScrolled(',IntToStr(Distance),'), Invalidating');
{$endif} {$endif}
UpdateActive; UpdateActive;
If Distance<>0 Then Invalidate; if Distance<>0 then Invalidate;
end; end;
procedure TCustomDbGrid.SetDataSource(const AValue: TDataSource); procedure TCustomDbGrid.SetDataSource(const AValue: TDataSource);
@ -311,31 +305,27 @@ end;
procedure TCustomDbGrid.UpdateBufferCount; procedure TCustomDbGrid.UpdateBufferCount;
begin begin
If FDataLink.Active Then begin if FDataLink.Active then begin
//if FGCache.ValidGrid Then //if FGCache.ValidGrid then
FDataLink.BufferCount:= ClientHeight div DefaultRowHeight - 1; FDataLink.BufferCount:= ClientHeight div DefaultRowHeight - 1;
//Else //else
// FDataLink.BufferCount:=0; // FDataLink.BufferCount:=0;
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn(ClassName, ' (',name,')', ' FdataLink.BufferCount=',Fdatalink.BufferCount); DebugLn(ClassName, ' (',name,')', ' FdataLink.BufferCount=' + IntToStr(Fdatalink.BufferCount));
{$endif} {$endif}
End; end;
end;
procedure TCustomDbGrid.WMHScroll(var Message: TLMHScroll);
begin
inherited;
end; end;
procedure TCustomDbGrid.WMVScroll(var Message: TLMVScroll); procedure TCustomDbGrid.WMVScroll(var Message: TLMVScroll);
Var var
Num: Integer; Num: Integer;
C, TL: Integer; C, TL: Integer;
begin begin
Inherited; inherited;
if Not GCache.ValidGrid Then Exit; if not GCache.ValidGrid then Exit;
{$ifdef dbgdbgrid}
DebugLn('VSCROLL: Code=',dbgs(Message.ScrollCode),' Position=', dbgs(Message.Pos)); DebugLn('VSCROLL: Code=',dbgs(Message.ScrollCode),' Position=', dbgs(Message.Pos));
{$endif}
exit; exit;
C:=Message.Pos+GCache.Fixedheight; C:=Message.Pos+GCache.Fixedheight;
Num:=(FNumRecords + FixedRows) * DefaultRowHeight; Num:=(FNumRecords + FixedRows) * DefaultRowHeight;
@ -345,22 +335,22 @@ begin
end; end;
Function TCustomDbGrid.DefaultFieldColWidth(FieldType: TFieldType): Integer; function TCustomDbGrid.DefaultFieldColWidth(FieldType: TFieldType): Integer;
begin begin
Case FieldType of case FieldType of
ftString: Result:=150; ftString: Result:=150;
ftSmallInt..ftBoolean: Result:=60; ftSmallInt..ftBoolean: Result:=60;
Else Result:=DefaultColWidth; else Result:=DefaultColWidth;
End; end;
end; end;
procedure TCustomDbGrid.LinkActive(Value: Boolean); procedure TCustomDbGrid.LinkActive(Value: Boolean);
begin begin
//BeginUpdate; //BeginUpdate;
FVisualLock:= Value; // If Not Active Call Inherited visualchange y Active dont call it FVisualLock:= Value; // if not Active Call inherited visualchange y Active dont call it
If Not Value Then FDataLink.BufferCount:=0; if not Value then FDataLink.BufferCount:=0;
Clear; // This will call VisualChange and Finally -> LayoutChanged Clear; // This will call VisualChange and Finally -> LayoutChanged
//If Value Then LayoutChanged; //if Value then LayoutChanged;
//EndUpdate(uoFull); //EndUpdate(uoFull);
end; end;
@ -369,16 +359,16 @@ var
i: Integer; i: Integer;
FDefs: TFieldDefs; FDefs: TFieldDefs;
begin begin
If FDataLink.Active Then begin if FDataLink.Active then begin
FNumRecords:= FDataLink.DataSet.RecordCount; FNumRecords:= FDataLink.DataSet.RecordCount;
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('(',name,') ','TCustomGrid.LayoutChanged INIT'); DebugLn('(',name,') ','TCustomGrid.LayoutChanged INIT');
DebugLn('DataLink.DataSet.recordcount: ',FNumRecords); DebugLn('DataLink.DataSet.recordcount: ', IntToStr(FNumRecords));
{$endif} {$endif}
FLayoutChanging:=True; // Avoid infinit loop FLayoutChanging:=True; // Avoid infinit loop
FVisualLock:=True; // Avoid Calling Inherited visualchange FVisualLock:=True; // Avoid Calling inherited visualchange
UpdateBufferCount; UpdateBufferCount;
ColCount:= FDataLink.DataSet.FieldCount + 1; ColCount:= FDataLink.DataSet.FieldCount + 1;
RowCount:= FDataLink.RecordCount + 1; RowCount:= FDataLink.RecordCount + 1;
@ -386,10 +376,10 @@ begin
FixedCols:=1; FixedCols:=1;
ColWidths[0]:=12; ColWidths[0]:=12;
FDefs:=FDataLink.DataSet.FieldDefs; FDefs:=FDataLink.DataSet.FieldDefs;
For i:=0 to FDefs.Count-1 do Begin for i:=0 to FDefs.Count-1 do begin
//DebugLn('Field ',FDefs[i].Name, ' Size= ',FDefs[i].Size); //DebugLn('Field ',FDefs[i].Name, ' Size= ',FDefs[i].Size);
ColWidths[i+1]:= DefaultFieldColWidth(FDefs[i].DataType); ColWidths[i+1]:= DefaultFieldColWidth(FDefs[i].DataType);
End; end;
FVisualLock:=False; FVisualLock:=False;
VisualChange; // Now Call Visual Change VisualChange; // Now Call Visual Change
// Update Scrollbars // Update Scrollbars
@ -400,98 +390,44 @@ begin
//HorzScrollBar.Range:= GridWidth+2; //HorzScrollBar.Range:= GridWidth+2;
//VertScrollBar.Range:= (FNumRecords + FixedRows) * DefaultRowHeight + 2; //VertScrollBar.Range:= (FNumRecords + FixedRows) * DefaultRowHeight + 2;
{ {
For i:=1 to ColCount-1 do begin for i:=1 to ColCount-1 do begin
F:=FDataLink.Fields[i]; F:=FDataLink.Fields[i];
If F<>nil Then Begin if F<>nil then begin
W:=F.DisplayWidth; W:=F.DisplayWidth;
If W<0 Then W:=0; if W<0 then W:=0;
If W=0 Then W:=F.GetDefaultwidth; if W=0 then W:=F.GetDefaultwidth;
DebugLn('Field ',F.FieldName,' DisplayWidth=', W); DebugLn('Field ',F.FieldName,' DisplayWidth=', W);
End; end;
End; end;
} }
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('(',name,') ','TCustomGrid.LayoutChanged - DONE'); DebugLn('(',name,') ','TCustomGrid.LayoutChanged - DONE');
{$endif} {$endif}
FLayoutChanging:=False; FLayoutChanging:=False;
End; end;
end;
{$IfDef Protodbgrid}
Function TCustomDbGrid.BeyondRowCount(Count: Integer): Boolean;
Var
i: integer;
InMaxRow: Boolean;
begin
With FDataLink do begin
Result:=Active;
{$ifdef dbgdbgrid}
DebugLn('(',name,') ',
'BeyondRowCount Hitted here: Count=',Count,
' FDataLink.Active=', Result,
' FDataLink.EOF=',EOF);
{$Endif}
If Not result Then Exit;
If EOF And DataSet.CanModify And Not ReadOnly Then
Dataset.Append
Else
If not EOF Then begin
I:=MoveBy(Count);
{$Ifdef dbgdbgrid}
DebugLn('Scrolled by ',I);
{$Endif}
End;
End;
end; end;
Function TCustomDbGrid.BelowFirstRow(Count: Integer):Boolean; procedure TCustomDbGrid.DefineProperties(Filer: TFiler);
var
i: Integer;
begin begin
With FDataLink do Begin
Result:=Active;
{$ifdef dbgdbgrid}
DebugLn('(',name,') ',
'BelowFirstRow Hitted here: Count=',Count,
' FDataLink.Active=', Result,
' FDataLink.BOF=',BOF);
{$Endif}
If Result And Not BOF Then begin
If KeepInBuffer And (ActiveRecord<>0) Then
Result:=Inherited BelowFirstRow(Count)
Else begin
I:=MoveBy(-Count);
{$Ifdef dbgdbgrid}
DebugLn('Scrolled By ', I);
{$Endif}
End;
End;
End;
end; end;
procedure TCustomDbGrid.UpdateGridScrollPosition(DCol, DRow: Integer; InvAll: Boolean); procedure TCustomDbGrid.BeforeMoveSelection(const DCol,DRow: Integer);
begin begin
If DCol<>Col Then inherited; inherited BeforeMoveSelection(DCol, DRow);
end;
{$Endif Protodbgrid}
Procedure TCustomDbGrid.BeforeMoveSelection(Const DCol,DRow: Integer);
begin
Inherited BeforeMoveSelection(DCol, DRow);
FDatalink.UpdateData; FDatalink.UpdateData;
If DCol<>Col Then begin if DCol<>Col then begin
// Its a Column Movement // Its a Column Movement
If assigned(OnColExit) Then OnColExit(Self); if assigned(OnColExit) then OnColExit(Self);
FColEnterPending:=True; FColEnterPending:=True;
End; end;
{ {
Exit; Exit;
If (DRow<>Row) Then Begin if (DRow<>Row) then begin
// Its a Row Movement // Its a Row Movement
D:= DRow - Row; D:= DRow - Row;
FDatalink.MoveBy(D); FDatalink.MoveBy(D);
End; end;
} }
end; end;
@ -501,47 +437,47 @@ begin
end; end;
procedure TCustomDbGrid.KeyDown(var Key: Word; Shift: TShiftState); procedure TCustomDbGrid.KeyDown(var Key: Word; Shift: TShiftState);
Procedure MoveBy(Delta: Integer); procedure MoveBy(Delta: Integer);
Begin begin
FSelfScroll:=True; //FSelfScroll:=True;
FDatalink.MoveBy(Delta); FDatalink.MoveBy(Delta);
FSelfScroll:=False; //FSelfScroll:=False;
end; end;
begin begin
// inherited KeyDown(Key, Shift); // Fully override old KeyDown handler // inherited KeyDown(Key, Shift); // Fully override old KeyDown handler
Case Key of case Key of
VK_DOWN: MoveBy(1); VK_DOWN: MoveBy(1);
VK_UP: MoveBy(-1); VK_UP: MoveBy(-1);
VK_NEXT: MoveBy( VisibleRowCount ); VK_NEXT: MoveBy( VisibleRowCount );
VK_PRIOR: MoveBy( -VisibleRowCount ); VK_PRIOR: MoveBy( -VisibleRowCount );
else Inherited; else inherited;
End; end;
end; end;
procedure TCustomDbGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, procedure TCustomDbGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer); Y: Integer);
Var var
Gz: TGridZone; Gz: TGridZone;
P: TPoint; P: TPoint;
begin begin
If csDesigning in componentState Then Exit; if csDesigning in componentState then Exit;
If Not GCache.ValidGrid Then Exit; if not GCache.ValidGrid then Exit;
Gz:=MouseToGridZone(X,Y, False); Gz:=MouseToGridZone(X,Y, False);
Case Gz of case Gz of
gzFixedRows, gzFixedCols: inherited MouseDown(Button, Shift, X, Y); gzFixedRows, gzFixedCols: inherited MouseDown(Button, Shift, X, Y);
else else
Begin begin
P:=MouseToCell(Point(X,Y)); P:=MouseToCell(Point(X,Y));
If P.Y=Row Then Inherited MouseDown(Button, Shift, X, Y) if P.Y=Row then inherited MouseDown(Button, Shift, X, Y)
Else Begin else begin
BeginUpdate; BeginUpdate;
FDatalink.MoveBy(P.Y - Row); FDatalink.MoveBy(P.Y - Row);
Col:=P.X; Col:=P.X;
EndUpdate(uoQuick); EndUpdate(uoQuick);
End; end;
End; end;
End; end;
end; end;
function TCustomDbGrid.ScrollBarAutomatic(Which: TScrollStyle): boolean; function TCustomDbGrid.ScrollBarAutomatic(Which: TScrollStyle): boolean;
@ -555,29 +491,29 @@ end;
procedure TCustomDbGrid.MoveSelection; procedure TCustomDbGrid.MoveSelection;
begin begin
inherited MoveSelection; inherited MoveSelection;
If FColEnterPending And Assigned(OnColEnter) Then OnColEnter(Self); if FColEnterPending and Assigned(OnColEnter) then OnColEnter(Self);
FColEnterPending:=False; FColEnterPending:=False;
UpdateActive; UpdateActive;
end; end;
procedure TCustomDbGrid.DrawByRows; procedure TCustomDbGrid.DrawByRows;
Var var
CurActiveRecord: Integer; CurActiveRecord: Integer;
begin begin
If FDataLink.ACtive Then Begin if FDataLink.ACtive then begin
CurActiveRecord:=FDataLink.ActiveRecord; CurActiveRecord:=FDataLink.ActiveRecord;
//PrimerRecord:=FDataLink.FirstRecord; //PrimerRecord:=FDataLink.FirstRecord;
End; end;
Try try
inherited DrawByRows; inherited DrawByRows;
Finally finally
if FDataLink.Active Then FDataLink.ActiveRecord:=CurActiveRecord; if FDataLink.Active then FDataLink.ActiveRecord:=CurActiveRecord;
End; end;
end; end;
// 33 31 21 29 80 90 4 3 // 33 31 21 29 80 90 4 3
procedure TCustomDbGrid.DrawRow(ARow: Integer); procedure TCustomDbGrid.DrawRow(ARow: Integer);
begin begin
If Arow>=FixedRows then FDataLink.ActiveRecord:=ARow-FixedRows; if Arow>=FixedRows then FDataLink.ActiveRecord:=ARow-FixedRows;
inherited DrawRow(ARow); inherited DrawRow(ARow);
end; end;
@ -585,7 +521,7 @@ procedure DrawArrow(Canvas: TCanvas; R: TRect; Opt: TDataSetState);
var var
dx,dy, x, y: Integer; dx,dy, x, y: Integer;
begin begin
Case Opt of case Opt of
dsBrowse: dsBrowse:
begin // begin //
Canvas.Brush.Color:=clBlack; Canvas.Brush.Color:=clBlack;
@ -595,7 +531,7 @@ begin
y:= R.top+ (R.Bottom-R.Top) div 2; y:= R.top+ (R.Bottom-R.Top) div 2;
x:= R.Left+2; x:= R.Left+2;
Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]); Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]);
End; end;
dsEdit: dsEdit:
begin // Normal begin // Normal
Canvas.Brush.Color:=clRed; Canvas.Brush.Color:=clRed;
@ -605,7 +541,7 @@ begin
y:= R.top+ (R.Bottom-R.Top) div 2; y:= R.top+ (R.Bottom-R.Top) div 2;
x:= R.Left+2; x:= R.Left+2;
Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]); Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]);
End; end;
dsInsert: dsInsert:
begin // Normal begin // Normal
Canvas.Brush.Color:=clGreen; Canvas.Brush.Color:=clGreen;
@ -615,35 +551,46 @@ begin
y:= R.top+ (R.Bottom-R.Top) div 2; y:= R.top+ (R.Bottom-R.Top) div 2;
x:= R.Left+2; x:= R.Left+2;
Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]); Canvas.Polygon([point(x,y-dy),point(x+dx,y),point(x, y+dy),point(x,y-dy)]);
End; end;
End; end;
End; end;
procedure TCustomDbGrid.DrawCell(aCol, aRow: Integer; aRect: TRect; procedure TCustomDbGrid.DrawCell(aCol, aRow: Integer; aRect: TRect;
aState: TGridDrawState); aState: TGridDrawState);
Var var
F: TField; F: TField;
S: string;
begin begin
// Draw appropiated attributes // Draw appropiated attributes
inherited DrawCell(aCol, aRow, aRect, aState); inherited DrawCell(aCol, aRow, aRect, aState);
If Not FDataLink.Active then Exit; if not FDataLink.Active then
Exit;
// Draw text When needed // Draw text When needed
If gdFixed in aState Then begin if gdFixed in aState then begin
if (aRow=0)And(ACol>=FixedCols) Then begin if (aRow=0)and(ACol>=FixedCols) then begin
// draw column headers // draw column headers
F:=FDataLink.Fields[aCol-FixedCols]; F:=FDataLink.Fields[aCol-FixedCols];
If F<>nil then Canvas.TextOut(Arect.Left+2,ARect.Top+2, F.FieldName); if F<>nil then
End Else Canvas.TextOut(Arect.Left+2,ARect.Top+2, F.FieldName);
If (aCol=0)And(aRow=Row) Then end else
if (aCol=0)and(aRow=Row) then
// draw row headers (selected/editing/* record) // draw row headers (selected/editing/* record)
DrawArrow(Canvas, aRect, FDataLink.Dataset.State) DrawArrow(Canvas, aRect, FDataLink.Dataset.State)
End Else begin end else begin
// Draw the other cells // Draw the other cells
F:=FDataLink.Fields[Acol-FixedCols]; try
If F<>nil then Canvas.TextOut(aRect.Left+2,ARect.Top+2, F.AsString); F:=FDataLink.Fields[Acol-FixedCols];
End; if F<>nil then
S := F.AsString
else
S := '';
except
S := 'Error!';
end;
Canvas.TextOut(aRect.Left+2,ARect.Top+2, S);
end;
end; end;
procedure TCustomDbGrid.UpdateActive; procedure TCustomDbGrid.UpdateActive;
@ -654,32 +601,32 @@ var
WasVisible: Boolean; WasVisible: Boolean;
} }
begin begin
With FDataLink do begin with FDataLink do begin
If Not GCache.ValidGrid then Exit; if not GCache.ValidGrid then Exit;
If DataSource=nil Then Exit; if DataSource=nil then Exit;
DebugLn('(',Name,') ActiveRecord=', dbgs(ActiveRecord), ' FixedRows=',dbgs(FixedRows), ' Row=', dbgs(Row)); DebugLn('(',Name,') ActiveRecord=', dbgs(ActiveRecord), ' FixedRows=',dbgs(FixedRows), ' Row=', dbgs(Row));
Row:= FixedRows + ActiveRecord; Row:= FixedRows + ActiveRecord;
{ {
LastRow:=Row; LastRow:=Row;
LastEditor:= Editor; LastEditor:= Editor;
WasVisible:= (Lasteditor<>nil)And(LastEditor.Visible); WasVisible:= (Lasteditor<>nil)and(LastEditor.Visible);
FRow:=FixedRows + ActiveRecord; FRow:=FixedRows + ActiveRecord;
If LastRow<>FRow Then if LastRow<>FRow then
ProcessEditor(LastEditor,Col,LastRow,WasVisible); ProcessEditor(LastEditor,Col,LastRow,WasVisible);
} }
End; end;
Invalidate; Invalidate;
end; end;
procedure TCustomDbGrid.VisualChange; procedure TCustomDbGrid.VisualChange;
begin begin
If FDataLink=nil Then Exit; if FDataLink=nil then Exit;
If not FVisualLock Then begin if not FVisualLock then begin
inherited VisualChange; inherited VisualChange;
End; end;
If Not FLayoutChanging Then begin if not FLayoutChanging then begin
LayoutChanged; LayoutChanged;
End; end;
end; end;
constructor TCustomDbGrid.Create(AOwner: TComponent); constructor TCustomDbGrid.Create(AOwner: TComponent);
@ -711,25 +658,25 @@ begin
FDataLink.OnDataSetChanged:=nil; FDataLink.OnDataSetChanged:=nil;
FDataLink.OnRecordChanged:=nil; FDataLink.OnRecordChanged:=nil;
FDataLink.Free; FDataLink.Free;
Inherited Destroy; inherited Destroy;
end; end;
{ TComponentDataLink } { TComponentDataLink }
function TComponentDataLink.GetFields(Index: Integer): TField; function TComponentDataLink.GetFields(Index: Integer): TField;
begin begin
If (index>=0)And(index<DataSet.FieldCount) Then result:=DataSet.Fields[index]; if (index>=0)and(index<DataSet.FieldCount) then result:=DataSet.Fields[index];
end; end;
function TComponentDataLink.GetDataSetName: String; function TComponentDataLink.GetDataSetName: string;
begin begin
Result:=FDataSetName; Result:=FDataSetName;
If DataSet<>nil Then Result:=DataSet.Name; if DataSet<>nil then Result:=DataSet.Name;
end; end;
procedure TComponentDataLink.SetDataSetName(const AValue: String); procedure TComponentDataLink.SetDataSetName(const AValue: string);
begin begin
If FDataSetName<>AValue then FDataSetName:=AValue; if FDataSetName<>AValue then FDataSetName:=AValue;
end; end;
procedure TComponentDataLink.RecordChanged(Field: TField); procedure TComponentDataLink.RecordChanged(Field: TField);
@ -737,7 +684,7 @@ begin
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('TComponentDataLink.RecordChanged'); DebugLn('TComponentDataLink.RecordChanged');
{$endif} {$endif}
If Assigned(OnRecordChanged) Then OnRecordChanged(Field); if Assigned(OnRecordChanged) then OnRecordChanged(Field);
end; end;
procedure TComponentDataLink.DataSetChanged; procedure TComponentDataLink.DataSetChanged;
@ -745,7 +692,7 @@ begin
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('TComponentDataLink.DataSetChanged'); DebugLn('TComponentDataLink.DataSetChanged');
{$Endif} {$Endif}
If Assigned(OnDataSetChanged) Then OnDataSetChanged(DataSet); if Assigned(OnDataSetChanged) then OnDataSetChanged(DataSet);
end; end;
procedure TComponentDataLink.ActiveChanged; procedure TComponentDataLink.ActiveChanged;
@ -780,7 +727,7 @@ end;
procedure TComponentDataLink.LayoutChanged; procedure TComponentDataLink.LayoutChanged;
begin begin
Inherited LayoutChanged; inherited LayoutChanged;
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('TComponentDataLink.LayoutChanged'); DebugLn('TComponentDataLink.LayoutChanged');
{$endif} {$endif}
@ -789,9 +736,9 @@ end;
procedure TComponentDataLink.DataSetScrolled(Distance: Integer); procedure TComponentDataLink.DataSetScrolled(Distance: Integer);
begin begin
{$ifdef dbgdbgrid} {$ifdef dbgdbgrid}
DebugLn('TComponentDataLink.DataSetScrolled(',Distance,')'); DebugLn('TComponentDataLink.DataSetScrolled(',IntToStr(Distance),')');
{$endif} {$endif}
if Assigned(OnDataSetScrolled) Then OnDataSetScrolled(DataSet, Distance); if Assigned(OnDataSetScrolled) then OnDataSetScrolled(DataSet, Distance);
end; end;
procedure TComponentDataLink.FocusControl(Field: TFieldRef); procedure TComponentDataLink.FocusControl(Field: TFieldRef);

View File

@ -32,6 +32,8 @@ Cur version: 0.8.5
The log was moved to end of file, search for: The_Log The log was moved to end of file, search for: The_Log
} }
{$Define UseClipRect}
unit Grids; unit Grids;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
@ -114,7 +116,7 @@ type
TGridZone = (gzNormal, gzFixedCols, gzFixedRows, gzFixedCells); TGridZone = (gzNormal, gzFixedCols, gzFixedRows, gzFixedCells);
TUpdateOption = (uoNone, uoQuick, uoFull); TUpdateOption = (uoNone, uoQuick, uoFull);
TAutoAdvance = (aaDown,aaRight); TAutoAdvance = (aaDown,aaRight,aaLeft);
TGridStatus = (stNormal, stEditorHiding, stEditorShowing, stFocusing); TGridStatus = (stNormal, stEditorHiding, stEditorShowing, stFocusing);
TItemType = (itNormal,itCell,itColumn,itRow,itFixed,itFixedColumn,itFixedRow,itSelected); TItemType = (itNormal,itCell,itColumn,itRow,itFixed,itFixedColumn,itFixedRow,itSelected);
@ -193,6 +195,10 @@ type
TSelectEditorEvent = TSelectEditorEvent =
procedure(Sender: TObject; Col,Row: Integer; procedure(Sender: TObject; Col,Row: Integer;
var Editor: TWinControl) of object; var Editor: TWinControl) of object;
TOnPrepareCanvasEvent =
procedure(sender: TObject; Col,Row: Integer;
aState:TGridDrawState) of object;
TVirtualGrid=class TVirtualGrid=class
private private
@ -271,9 +277,11 @@ type
FGridLineWidth: Integer; FGridLineWidth: Integer;
FDefColWidth, FDefRowHeight: Integer; FDefColWidth, FDefRowHeight: Integer;
FCol,FRow, FFixedCols, FFixedRows: Integer; FCol,FRow, FFixedCols, FFixedRows: Integer;
FOnPrepareCanvas: TOnPrepareCanvasEvent;
FOnSelectEditor: TSelectEditorEvent; FOnSelectEditor: TSelectEditorEvent;
FGridLineColor: TColor; FGridLineColor: TColor;
FFixedcolor, FFocusColor, FSelectedColor: TColor; FFixedcolor, FFocusColor, FSelectedColor: TColor;
FFocusRectVisible: boolean;
FCols,FRows: TList; FCols,FRows: TList;
FsaveOptions: TSaveOptions; FsaveOptions: TSaveOptions;
FScrollBars: TScrollStyle; FScrollBars: TScrollStyle;
@ -301,6 +309,7 @@ type
procedure CheckCount(aNewColCount, aNewRowCount: Integer); procedure CheckCount(aNewColCount, aNewRowCount: Integer);
function CheckTopLeft(aCol,aRow: Integer; CheckCols,CheckRows: boolean): boolean; function CheckTopLeft(aCol,aRow: Integer; CheckCols,CheckRows: boolean): boolean;
procedure SetFlat(const AValue: Boolean); procedure SetFlat(const AValue: Boolean);
procedure SetFocusRectVisible(const AValue: Boolean);
function doColSizing(X,Y: Integer): Boolean; function doColSizing(X,Y: Integer): Boolean;
function doRowSizing(X,Y: Integer): Boolean; function doRowSizing(X,Y: Integer): Boolean;
procedure doColMoving(X,Y: Integer); procedure doColMoving(X,Y: Integer);
@ -386,8 +395,8 @@ type
procedure DrawColRowMoving; procedure DrawColRowMoving;
procedure DrawEdges; procedure DrawEdges;
//procedure DrawFixedCells; virtual; //procedure DrawFixedCells; virtual;
procedure DrawFocused; virtual; //procedure DrawFocused; virtual;
procedure DrawFocusRect(aCol,aRow:Integer; ARect:TRect; aState:TGridDrawstate); virtual; procedure DrawFocusRect(aCol,aRow:Integer; ARect:TRect); virtual;
//procedure DrawInteriorCells; virtual; //procedure DrawInteriorCells; virtual;
procedure DrawRow(aRow: Integer); virtual; procedure DrawRow(aRow: Integer); virtual;
procedure EditordoGetValue; virtual; procedure EditordoGetValue; virtual;
@ -398,6 +407,7 @@ type
function GetEditText(ACol, ARow: Longint): string; dynamic; function GetEditText(ACol, ARow: Longint): string; dynamic;
procedure SetEditText(ACol, ARow: Longint; const Value: string); dynamic; procedure SetEditText(ACol, ARow: Longint; const Value: string); dynamic;
procedure HeaderClick(IsColumn: Boolean; index: Integer); dynamic; procedure HeaderClick(IsColumn: Boolean; index: Integer); dynamic;
procedure HeaderSized(IsColumn: Boolean; index: Integer); dynamic;
procedure InvalidateCell(aCol, aRow: Integer); overload; procedure InvalidateCell(aCol, aRow: Integer); overload;
procedure InvalidateCell(aCol, aRow: Integer; Redraw: Boolean); overload; procedure InvalidateCell(aCol, aRow: Integer; Redraw: Boolean); overload;
procedure InvalidateCol(ACol: Integer); procedure InvalidateCol(ACol: Integer);
@ -455,6 +465,7 @@ type
property FixedColor: TColor read GetFixedColor write SetFixedcolor; property FixedColor: TColor read GetFixedColor write SetFixedcolor;
property Flat: Boolean read FFlat write SetFlat default false; property Flat: Boolean read FFlat write SetFlat default false;
property FocusColor: TColor read FFocusColor write SetFocusColor; property FocusColor: TColor read FFocusColor write SetFocusColor;
property FocusRectVisible: Boolean read FFocusRectVisible write SetFocusRectVisible;
property GCache: TGridDataCache read FGCAChe; property GCache: TGridDataCache read FGCAChe;
property GridHeight: Integer read FGCache.GridHeight; property GridHeight: Integer read FGCache.GridHeight;
property GridLineColor: TColor read FGridLineColor write SetGridLineColor; property GridLineColor: TColor read FGridLineColor write SetGridLineColor;
@ -478,6 +489,7 @@ type
property OnBeforeSelection: TOnSelectEvent read FOnBeforeSelection write FOnBeforeSelection; property OnBeforeSelection: TOnSelectEvent read FOnBeforeSelection write FOnBeforeSelection;
property OnCompareCells: TOnCompareCells read FOnCompareCells write FOnCompareCells; property OnCompareCells: TOnCompareCells read FOnCompareCells write FOnCompareCells;
property OnPrepareCanvas: TOnPrepareCanvasEvent read FOnPrepareCanvas write FOnPrepareCanvas;
property OnDrawCell: TOnDrawCell read FOnDrawCell write FOnDrawCell; property OnDrawCell: TOnDrawCell read FOnDrawCell write FOnDrawCell;
property OnSelection: TOnSelectEvent read fOnSelection write fOnSelection; property OnSelection: TOnSelectEvent read fOnSelection write fOnSelection;
property OnSelectEditor: TSelectEditorEvent read FOnSelectEditor write FOnSelectEditor; property OnSelectEditor: TSelectEditorEvent read FOnSelectEditor write FOnSelectEditor;
@ -521,7 +533,7 @@ type
FOnColRowMoved: TgridOperationEvent; FOnColRowMoved: TgridOperationEvent;
FOnGetEditMask: TGetEditEvent; FOnGetEditMask: TGetEditEvent;
FOnGetEditText: TGetEditEvent; FOnGetEditText: TGetEditEvent;
FOnHeaderClick: THdrEvent; FOnHeaderClick, FOnHeaderSized: THdrEvent;
FOnSelectCell: TOnSelectcellEvent; FOnSelectCell: TOnSelectcellEvent;
FOnSetEditText: TSetEditEvent; FOnSetEditText: TSetEditEvent;
protected protected
@ -532,8 +544,9 @@ type
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override; procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override;
function CreateVirtualGrid: TVirtualGrid; virtual; function CreateVirtualGrid: TVirtualGrid; virtual;
procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override; procedure DrawCell(aCol,aRow: Integer; aRect: TRect; aState:TGridDrawState); override;
procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect; aState: TGridDrawstate); override; procedure DrawFocusRect(aCol,aRow: Integer; ARect: TRect); override;
procedure HeaderClick(IsColumn: Boolean; index: Integer); override; procedure HeaderClick(IsColumn: Boolean; index: Integer); override;
procedure HeaderSized(IsColumn: Boolean; index: Integer); override;
function GetEditMask(aCol, aRow: Longint): string; override; function GetEditMask(aCol, aRow: Longint): string; override;
function GetEditText(aCol, aRow: Longint): string; override; function GetEditText(aCol, aRow: Longint): string; override;
function SelectCell(aCol,aRow: Integer): boolean; override; function SelectCell(aCol,aRow: Integer): boolean; override;
@ -553,6 +566,7 @@ type
property Editor; property Editor;
property EditorMode; property EditorMode;
property FocusColor; property FocusColor;
property FocusRectVisible;
property GridHeight; property GridHeight;
property GridLineColor; property GridLineColor;
property GridLineStyle; property GridLineStyle;
@ -561,6 +575,7 @@ type
property Row; property Row;
property RowHeights; property RowHeights;
property SaveOptions; property SaveOptions;
property SelectedColor;
property Selection; property Selection;
property SkipUnselectable; property SkipUnselectable;
//property TabStops; //property TabStops;
@ -618,12 +633,14 @@ type
property OnGetEditMask: TGetEditEvent read FOnGetEditMask write FOnGetEditMask; property OnGetEditMask: TGetEditEvent read FOnGetEditMask write FOnGetEditMask;
property OnGetEditText: TGetEditEvent read FOnGetEditText write FOnGetEditText; property OnGetEditText: TGetEditEvent read FOnGetEditText write FOnGetEditText;
property OnHeaderClick: THdrEvent read FOnHeaderClick write FOnHeaderClick; property OnHeaderClick: THdrEvent read FOnHeaderClick write FOnHeaderClick;
property OnHeaderSized: THdrEvent read FOnHeaderSized write FOnHeaderSized;
property OnKeyDown; property OnKeyDown;
property OnKeyPress; property OnKeyPress;
property OnKeyUp; property OnKeyUp;
property OnMouseDown; property OnMouseDown;
property OnMouseMove; property OnMouseMove;
property OnMouseUp; property OnMouseUp;
property OnPrepareCanvas;
property OnSelectEditor; property OnSelectEditor;
property OnSelection; property OnSelection;
property OnSelectCell: TOnSelectCellEvent read FOnSelectCell write FOnSelectCell; property OnSelectCell: TOnSelectCellEvent read FOnSelectCell write FOnSelectCell;
@ -1485,14 +1502,16 @@ end;
procedure TCustomGrid.HeaderClick(IsColumn: Boolean; index: Integer); procedure TCustomGrid.HeaderClick(IsColumn: Boolean; index: Integer);
begin begin
end; end;
procedure TCustomGrid.HeaderSized(IsColumn: Boolean; index: Integer);
begin
end;
procedure TCustomGrid.ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); procedure TCustomGrid.ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer);
begin begin
end; end;
procedure TCustomGrid.ColRowExchanged(isColumn: Boolean; index, WithIndex: Integer); procedure TCustomGrid.ColRowExchanged(isColumn: Boolean; index, WithIndex: Integer);
begin begin
end; end;
procedure TCustomGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect; procedure TCustomGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect);
aState: TGridDrawstate);
begin begin
end; end;
procedure TCustomGrid.AutoAdjustColumn(aCol: Integer); procedure TCustomGrid.AutoAdjustColumn(aCol: Integer);
@ -1539,6 +1558,8 @@ begin
Canvas.Brush.Color := clWindow; Canvas.Brush.Color := clWindow;
Canvas.Font.Color := clWindowText; Canvas.Font.Color := clWindowText;
end; end;
if Assigned(OnPrepareCanvas) then
OnPrepareCanvas(Self, aCol, aRow, aState);
end; end;
procedure TCustomGrid.ResetOffset(chkCol, ChkRow: Boolean); procedure TCustomGrid.ResetOffset(chkCol, ChkRow: Boolean);
@ -1579,14 +1600,14 @@ var
R: TRect; R: TRect;
begin begin
if BorderStyle = bsSingle then begin if BorderStyle = bsSingle then begin
R := Rect(0,0,Width,Height); R := Rect(0,0,FGCache.ClientWidth, FGCache.Clientheight);
with R, Canvas do begin with R, Canvas do begin
Pen.Color := cl3DDKShadow; Pen.Color := cl3DDKShadow;
MoveTo(Right-1, 0); MoveTo(0,0);
LineTo(0,Bottom);
LineTo(Right, Bottom);
LineTo(Right, 0);
LineTo(0,0); LineTo(0,0);
LineTo(0,Bottom-1);
LineTo(Right-1, Bottom-1);
LineTo(Right-1, Top-1);
end; end;
end; end;
end; end;
@ -1668,28 +1689,59 @@ begin
For i:=0 to FFixedRows-1 Do DrawRow(i); For i:=0 to FFixedRows-1 Do DrawRow(i);
end; end;
function VerticalIntersect(const aRect,bRect: TRect): boolean;
begin
result := (aRect.Top < bRect.Bottom) and (aRect.Bottom > bRect.Top);
end;
function HorizontalIntersect(const aRect,bRect: TRect): boolean;
begin
result := (aRect.Left < bRect.Right) and (aRect.Right > bRect.Left);
end;
procedure TCustomGrid.DrawRow(aRow: Integer); procedure TCustomGrid.DrawRow(aRow: Integer);
var var
Gds: TGridDrawState; Gds: TGridDrawState;
i: Integer; i: Integer;
Rs: Boolean; Rs: Boolean;
R: TRect; R: TRect;
{$IFDEF UseClipRect}
ClipArea: Trect;
{$ENDIF}
begin begin
// Upper and Lower bounds for this row // Upper and Lower bounds for this row
ColRowToOffSet(False, True, aRow, R.Top, R.Bottom); ColRowToOffSet(False, True, aRow, R.Top, R.Bottom);
{$IFDEF UseClipRect}
// is this row within the ClipRect
ClipArea := Canvas.ClipRect;
if not VerticalIntersect( R, ClipArea) then exit;
{$ENDIF}
// Draw columns in this row // Draw columns in this row
with FGCache.VisibleGrid do with FGCache.VisibleGrid do
if ARow<FFixedRows then begin if ARow<FFixedRows then begin
gds:=[gdFixed]; gds:=[gdFixed];
For i:=Left to Right do begin For i:=Left to Right do begin
ColRowToOffset(true, True, i, R.Left, R.Right); ColRowToOffset(true, True, i, R.Left, R.Right);
{$IFDEF UseClipRect}
// is this column within the ClipRect?
if HorizontalIntersect( R, ClipArea) then
{$ENDIF}
DrawCell(i,aRow, R,gds) DrawCell(i,aRow, R,gds)
end; end;
end else begin end else begin
Rs:=(goRowSelect in Options); Rs:=(goRowSelect in Options);
For i:=Left To Right do begin For i:=Left To Right do begin
ColRowToOffset(True, True, i, R.Left, R.Right);
{$IFDEF UseClipRect}
// is this column within the ClipRect?
if Not HorizontalIntersect( R, ClipArea) then
Continue;
{$ENDIF}
Gds:=[]; Gds:=[];
if (i=Fcol)and(FRow=ARow) then begin if (i=Fcol)and(FRow=ARow) then begin
// Focused Cell // Focused Cell
@ -1699,18 +1751,22 @@ begin
(Rs and not(goRelaxedRowSelect in Options)) then Include(gds, gdSelected); (Rs and not(goRelaxedRowSelect in Options)) then Include(gds, gdSelected);
end else end else
if IsCellSelected(i, ARow) then Include(gds, gdSelected); if IsCellSelected(i, ARow) then Include(gds, gdSelected);
ColRowToOffset(True, True, i, R.Left, R.Right);
DrawCell(i,aRow, R, gds); DrawCell(i,aRow, R, gds);
end; end;
// Draw the focus Rect // Draw the focus Rect
if (ARow=FRow) and if FFocusRectVisible and (ARow=FRow) and
(IsCellVisible(FCol,ARow) or (Rs and (ARow>=Top) and (ARow<=Bottom))) ((Rs and (ARow>=Top) and (ARow<=Bottom)) or IsCellVisible(FCol,ARow))
then begin then begin
if EditorShouldEdit and (FEditor<>nil)and(FEditor.Visible) then begin if EditorShouldEdit and (FEditor<>nil) and FEditor.Visible then begin
//DebugLn('No Draw Focus Rect'); //DebugLn('No Draw Focus Rect');
end else begin end else begin
ColRowToOffset(True, True, FCol, R.Left, R.Right); ColRowToOffset(True, True, FCol, R.Left, R.Right);
DrawFocusRect(FCol,FRow, R, [gdFocused]); {$IFDEF UseClipRect}
// is this column within the ClipRect?
if HorizontalIntersect( R, ClipArea) then
{$ENDIF}
DrawFocusRect(FCol,FRow, R);
end; end;
end; end;
end; // else begin end; // else begin
@ -1719,6 +1775,10 @@ begin
gds:=[gdFixed]; gds:=[gdFixed];
For i:=0 to FFixedCols-1 do begin For i:=0 to FFixedCols-1 do begin
ColRowToOffset(True, True, i, R.Left, R.Right); ColRowToOffset(True, True, i, R.Left, R.Right);
{$IFDEF UseClipRect}
// is this column within the ClipRect?
if HorizontalIntersect( R, ClipArea) then
{$ENDIF}
DrawCell(i,aRow, R,gds); DrawCell(i,aRow, R,gds);
end; end;
end; end;
@ -1744,6 +1804,7 @@ begin
end; end;
end; end;
{
procedure TCustomGrid.DrawFocused; procedure TCustomGrid.DrawFocused;
var var
R: TRect; R: TRect;
@ -1766,6 +1827,7 @@ begin
DrawFocusRect(fcol,fRow, R, gds); DrawFocusRect(fcol,fRow, R, gds);
end; end;
end; end;
}
procedure DebugRect(S:string; R:TRect); procedure DebugRect(S:string; R:TRect);
begin begin
@ -2053,7 +2115,7 @@ var
Ch: Char; Ch: Char;
begin begin
Ch:=Char(message.CharCode); Ch:=Char(message.CharCode);
//DebugLn(ClassName,'.WMchar CharCode= ',message.CharCode); DebugLn(ClassName,'.WMchar CharCode= ', IntToStr(message.CharCode));
if (goEditing in Options) and (Ch in [^H, #32..#255]) then if (goEditing in Options) and (Ch in [^H, #32..#255]) then
EditorShowChar(Ch) EditorShowChar(Ch)
else else
@ -2230,6 +2292,14 @@ begin
Invalidate; Invalidate;
end; end;
procedure TCustomGrid.SetFocusRectVisible(const AValue: Boolean);
begin
if FFocusRectVisible<>AValue then begin
FFocusRectVisible := AValue;
Invalidate;
end;
end;
procedure TCustomGrid.SetBorderStyle(const AValue: TBorderStyle); procedure TCustomGrid.SetBorderStyle(const AValue: TBorderStyle);
begin begin
if FBorderStyle<>AValue Then begin if FBorderStyle<>AValue Then begin
@ -2687,6 +2757,14 @@ begin
end else end else
if Cur.Y=FSplitter.Y then HeaderClick(False, FSplitter.Y); if Cur.Y=FSplitter.Y then HeaderClick(False, FSplitter.Y);
end; end;
gsColSizing:
begin
debugln('Col Sizing ENDED');
end;
gsRowSizing:
begin
debugLn('Row Sizing ENDED');
end;
end; end;
fGridState:=gsNormal; fGridState:=gsNormal;
{$IfDef dbgFocus}DebugLn('MouseUP END RND=',Random);{$Endif} {$IfDef dbgFocus}DebugLn('MouseUP END RND=',Random);{$Endif}
@ -2808,6 +2886,9 @@ begin
aaDown: aaDown:
if Sh then Key:=VK_UP if Sh then Key:=VK_UP
else Key:=VK_DOWN; else Key:=VK_DOWN;
aaLeft:
if sh then Key:=VK_RIGHT
else Key:=VK_LEFT;
end; end;
end else begin end else begin
// TODO // TODO
@ -2960,11 +3041,18 @@ begin
LastEditor:=Editor; LastEditor:=Editor;
WasVis:=(LastEditor<>nil)and(LastEditor.Visible); WasVis:=(LastEditor<>nil)and(LastEditor.Visible);
// default range
if goRowSelect in Options then FRange:=Rect(FFixedCols, DRow, Colcount-1, DRow)
else FRange:=Rect(DCol,DRow,DCol,DRow);
InvalidateAll:=False; InvalidateAll:=False;
// default range
if goRowSelect in Options then FRange:=Rect(FFixedCols, DRow, Colcount-1, DRow)
else begin
// Just after selectActive=false and Selection Area is more than one cell
InvalidateAll := Not SelectActive And (
(FRange.Right-FRange.Left > 0) or
(Frange.Bottom-FRange.Top > 0) );
FRange:=Rect(DCol,DRow,DCol,DRow);
end;
if SelectActive then if SelectActive then
if goRangeSelect in Options then begin if goRangeSelect in Options then begin
if goRowSelect in Options then begin if goRowSelect in Options then begin
@ -3310,12 +3398,14 @@ begin
case FAutoAdvance of case FAutoAdvance of
aaRight: Key:=VK_RIGHT * Integer( FCol<ColCount-1 ); aaRight: Key:=VK_RIGHT * Integer( FCol<ColCount-1 );
aaDown : Key:=VK_DOWN * Integer( FRow<RowCount-1 ); aaDown : Key:=VK_DOWN * Integer( FRow<RowCount-1 );
aaLeft : Key:=VK_LEFT * Integer( FCol>FixedCols );
end; end;
if Key=0 then begin if Key=0 then begin
EditorGetValue; EditorGetValue;
EditorShow; EditorShow;
// Select All ! // Select All !
end else KeyDown(Key, Shift); end else
KeyDown(Key, Shift);
end; end;
end; end;
FEditorKey:=False; FEditorKey:=False;
@ -3337,20 +3427,19 @@ begin
end; end;
procedure TCustomGrid.EditorShowChar(Ch: Char); procedure TCustomGrid.EditorShowChar(Ch: Char);
{
var var
msg: TGridMessage; msg: TGridMessage;
}
begin begin
SelectEditor; SelectEditor;
if FEditor<>nil then begin if FEditor<>nil then begin
EditorShow; EditorShow;
EditorSelectAll; EditorSelectAll;
PostMessage(FEditor.Handle, LM_CHAR, Word(Ch), 0); //DebugLn('Posting editor LM_CHAR, ch=',ch, ' ', InttoStr(Ord(ch)));
//
//PostMessage(FEditor.Handle, LM_CHAR, Word(Ch), 0);
///
// Note. this is a workaround because the call above doesn't work // Note. this is a workaround because the call above doesn't work
/// ///
{
Msg.MsgID:=GM_SETVALUE; Msg.MsgID:=GM_SETVALUE;
Msg.Grid:=Self; Msg.Grid:=Self;
Msg.Col:=FCol; Msg.Col:=FCol;
@ -3358,7 +3447,6 @@ begin
if Ch=^H then Msg.Value:='' if Ch=^H then Msg.Value:=''
else Msg.Value:=ch; else Msg.Value:=ch;
FEditor.Dispatch(Msg); FEditor.Dispatch(Msg);
}
end; end;
end; end;
@ -3610,6 +3698,7 @@ begin
//DebugLn('FGSMHBar= ', FGSMHBar, ' FGSMVBar= ', FGSMVBar); //DebugLn('FGSMHBar= ', FGSMHBar, ' FGSMVBar= ', FGSMVBar);
inherited Create(AOwner); inherited Create(AOwner);
//AutoScroll:=False; //AutoScroll:=False;
FFocusRectVisible := True;
FBorderStyle := bsSingle; //bsNone; FBorderStyle := bsSingle; //bsNone;
FDefaultDrawing := True; FDefaultDrawing := True;
FOptions:= FOptions:=
@ -3937,7 +4026,7 @@ end;
{ {
procedure TStringCellEditor.WndProc(var TheMessage: TLMessage); procedure TStringCellEditor.WndProc(var TheMessage: TLMessage);
begin begin
write(Name,'.WndProc msg= '); DbgOut(Name+'.WndProc msg= ');
case TheMessage.Msg of case TheMessage.Msg of
LM_SHOWWINDOW: DebugLn('LM_SHOWWINDOW'); LM_SHOWWINDOW: DebugLn('LM_SHOWWINDOW');
LM_SETFOCUS: DebugLn('LM_SETFOCUS'); LM_SETFOCUS: DebugLn('LM_SETFOCUS');
@ -4049,36 +4138,35 @@ procedure TDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
begin begin
if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin
PrepareCanvas(aCol, aRow, aState); PrepareCanvas(aCol, aRow, aState);
Canvas.FillRect(aRect); if DefaultDrawing then
Canvas.FillRect(aRect);
OnDrawCell(Self,aCol,aRow,aRect,aState) OnDrawCell(Self,aCol,aRow,aRect,aState)
end else end else
DefaultDrawCell(aCol,aRow,aRect,aState); DefaultDrawCell(aCol,aRow,aRect,aState);
inherited DrawCellGrid(aCol,aRow,aRect,aState); inherited DrawCellGrid(aCol,aRow,aRect,aState);
end; end;
procedure TDrawGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect; procedure TDrawGrid.DrawFocusRect(aCol, aRow: Integer; ARect: TRect);
aState: TGridDrawstate);
begin begin
// Draw focused cell if we have the focus // Draw focused cell if we have the focus
if Self.Focused Or (EditorShouldEdit and ((Feditor=nil)or not Feditor.Focused)) then begin if Self.Focused Or (EditorShouldEdit and ((Feditor=nil) or not Feditor.Focused)) then
if (gdFocused in aState)then begin begin
Canvas.Pen.Color:=FFocusColor; Canvas.Pen.Color:=FFocusColor;
Canvas.Pen.Style:=psDot; Canvas.Pen.Style:=psDot;
if goRowSelect in Options then begin if goRowSelect in Options then begin
Canvas.MoveTo(FGCache.FixedWidth+1, aRect.Top); Canvas.MoveTo(FGCache.FixedWidth+1, aRect.Top);
Canvas.LineTo(FGCache.MaxClientXY.x-2, aRect.Top); Canvas.LineTo(FGCache.MaxClientXY.x-2, aRect.Top);
Canvas.LineTo(FGCache.MaxClientXY.x-2, aRect.Bottom-2); Canvas.LineTo(FGCache.MaxClientXY.x-2, aRect.Bottom-2);
Canvas.LineTo(FGCache.FixedWidth+1, aRect.Bottom-2); Canvas.LineTo(FGCache.FixedWidth+1, aRect.Bottom-2);
Canvas.LineTo(FGCache.FixedWidth+1, aRect.Top+1); Canvas.LineTo(FGCache.FixedWidth+1, aRect.Top+1);
end else begin end else begin
Canvas.MoveTo(aRect.Left, aRect.Top); Canvas.MoveTo(aRect.Left, aRect.Top);
Canvas.LineTo(ARect.Right-2,aRect.Top); Canvas.LineTo(ARect.Right-2,aRect.Top);
Canvas.LineTo(aRect.Right-2,aRect.bottom-2); Canvas.LineTo(aRect.Right-2,aRect.bottom-2);
Canvas.LineTo(aRect.Left, aRect.Bottom-2); Canvas.LineTo(aRect.Left, aRect.Bottom-2);
Canvas.Lineto(aRect.left, aRect.top+1); Canvas.Lineto(aRect.left, aRect.top+1);
end;
Canvas.Pen.Style:=psSolid;
end; end;
Canvas.Pen.Style:=psSolid;
end; end;
end; end;
@ -4109,6 +4197,12 @@ begin
if Assigned(OnHeaderClick) then OnHeaderClick(Self, IsColumn, index); if Assigned(OnHeaderClick) then OnHeaderClick(Self, IsColumn, index);
end; end;
procedure TDrawGrid.HeaderSized(IsColumn: Boolean; index: Integer);
begin
inherited HeaderSized(IsColumn, index);
If Assigned(OnHeaderSized) then OnHeaderSized(Self, IsColumn, index);
end;
function TDrawGrid.GetEditMask(aCol, aRow: Longint): string; function TDrawGrid.GetEditMask(aCol, aRow: Longint): string;
begin begin
result:=''; result:='';

View File

@ -30,7 +30,6 @@ begin
inherited Create(AOwner); inherited Create(AOwner);
fCompStyle := csMemo; fCompStyle := csMemo;
FWordWrap := True; FWordWrap := True;
//FFont := TFont.Create;
FLines := TMemoStrings.Create(Self); FLines := TMemoStrings.Create(Self);
FVertScrollbar := TMemoScrollBar.Create(Self, sbVertical); FVertScrollbar := TMemoScrollBar.Create(Self, sbVertical);
FHorzScrollbar := TMemoScrollBar.Create(Self, sbHorizontal); FHorzScrollbar := TMemoScrollBar.Create(Self, sbHorizontal);
@ -47,7 +46,6 @@ end;
destructor TCustomMemo.Destroy; destructor TCustomMemo.Destroy;
begin begin
FreeThenNil(FLines); FreeThenNil(FLines);
//FreeThenNil(FFont);
FreeThenNil(FVertScrollbar); FreeThenNil(FVertScrollbar);
FreeThenNil(FHorzScrollbar); FreeThenNil(FHorzScrollbar);
inherited destroy; inherited destroy;
@ -117,7 +115,7 @@ procedure TCustomMemo.SetScrollbars(const Value : TScrollStyle);
begin begin
if Value <> FScrollbars then begin if Value <> FScrollbars then begin
FScrollbars:= Value; FScrollbars:= Value;
if HandleAllocated then if HandleAllocated and (not (csLoading in ComponentState)) then
CNSendMessage(LM_SETPROPERTIES, Self, nil); CNSendMessage(LM_SETPROPERTIES, Self, nil);
end; end;
end; end;
@ -134,6 +132,8 @@ end;
procedure TCustomMemo.Loaded; procedure TCustomMemo.Loaded;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomMemo.Loaded; procedure TCustomMemo.Loaded;
var
s: String;
begin begin
inherited Loaded; inherited Loaded;
CNSendMessage(LM_SETPROPERTIES, Self, nil); CNSendMessage(LM_SETPROPERTIES, Self, nil);
@ -160,6 +160,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.25 2004/05/14 12:53:25 mattias
improved grids e.g. OnPrepareCanvas patch from Jesus
Revision 1.24 2004/05/11 12:16:47 mattias Revision 1.24 2004/05/11 12:16:47 mattias
replaced writeln by debugln replaced writeln by debugln

View File

@ -772,23 +772,10 @@ begin
StopKeyEvent('key_press_event') StopKeyEvent('key_press_event')
else begin else begin
EventString^:=chr(Msg.CharCode); EventString^:=chr(Msg.CharCode);
gdk_event_key_set_string(Event,EventString);
end; end;
end; end;
end; end;
{if (Msg.CharCode = VK_TAB)
and (TObject(Data) is TControl)
then begin
TopLevel := gtk_widget_get_toplevel(TargetWidget);
if GtkWidgetIsA(TopLevel, gtk_window_get_type)
and (PGtkWindow(TopLevel)^.focus_widget = TargetWidget)
then begin
StopKeyEvent('key_press_event');
// Perform a forward tab, or when Shift is pressed a backward tab
Result := TControl(TargetData).PerformTab(
(Event^.State and GDK_SHIFT_MASK) = 0);
end;
end;}
end; end;
end; end;
//DebugLn('[HandleGTKKeyUpDown] ',TControl(Data).Name,':',TControl(Data).ClassName,' Result=',Result); //DebugLn('[HandleGTKKeyUpDown] ',TControl(Data).Name,':',TControl(Data).ClassName,' Result=',Result);
@ -3098,6 +3085,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.231 2004/05/14 12:53:25 mattias
improved grids e.g. OnPrepareCanvas patch from Jesus
Revision 1.230 2004/05/11 11:42:27 mattias Revision 1.230 2004/05/11 11:42:27 mattias
replaced writeln by debugln replaced writeln by debugln

View File

@ -7922,6 +7922,56 @@ var
pRowText : PChar; pRowText : PChar;
BitImage : TBitMap; BitImage : TBitMap;
AnAdjustment: PGtkAdjustment; AnAdjustment: PGtkAdjustment;
{$IfDef GTK1}
procedure SetMemoProperties;
begin
ImplWidget:= GetWidgetInfo(wHandle, true)^.CoreWidget;
gtk_text_freeze(PGtkText(ImplWidget));
gtk_text_set_editable (GTK_TEXT(ImplWidget), not (Sender as TCustomMemo).ReadOnly);
if TCustomMemo(Sender).WordWrap then
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkTrue)
else
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkFalse);
gtk_text_set_word_wrap(GTK_TEXT(ImplWidget), GdkTrue);
case (Sender as TCustomMemo).Scrollbars of
ssHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);
ssVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
ssBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
ssAutoHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
ssAutoVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
ssAutoBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
end;
if (TCustomMemo(Sender).MaxLength >= 0) then begin
i:= gtk_text_get_length(GTK_TEXT(ImplWidget));
if i > TCustomMemo(Sender).MaxLength then begin
gtk_editable_delete_text(PGtkOldEditable(ImplWidget),
TCustomMemo(Sender).MaxLength, i);
end;
end;
gtk_text_thaw(PGtkText(ImplWidget));
end;
{$ENDIF}
begin begin
Result := 0; // default if nobody sets it Result := 0; // default if nobody sets it
@ -8164,49 +8214,10 @@ begin
gtk_clist_thaw(GTK_CLIST(Widget)); gtk_clist_thaw(GTK_CLIST(Widget));
end; end;
{$EndIf} {$EndIf}
{$IfDef GTK1} {$IfDef GTK1}
csMemo: csMemo:
begin SetMemoProperties;
ImplWidget:= GetWidgetInfo(wHandle, true)^.CoreWidget;
gtk_text_set_editable (GTK_TEXT(ImplWidget), not (Sender as TCustomMemo).ReadOnly);
if TCustomMemo(Sender).WordWrap then
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkTrue)
else
gtk_text_set_line_wrap(GTK_TEXT(ImplWidget), GdkFalse);
gtk_text_set_word_wrap(GTK_TEXT(ImplWidget), GdkTrue);
case (Sender as TCustomMemo).Scrollbars of
ssHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);
ssVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
ssBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
ssAutoHorizontal: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
ssAutoVertical: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
ssAutoBoth: gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wHandle),
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
end;
if (TCustomMemo(Sender).MaxLength >= 0) then begin
i:= gtk_text_get_length(GTK_TEXT(ImplWidget));
if i > TCustomMemo(Sender).MaxLength then begin
gtk_editable_delete_text(PGtkOldEditable(ImplWidget), TCustomMemo(Sender).MaxLength, i);
end;
end;
end;
{$EndIf} {$EndIf}
csSpinEdit: csSpinEdit:
@ -9405,6 +9416,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.501 2004/05/14 12:53:25 mattias
improved grids e.g. OnPrepareCanvas patch from Jesus
Revision 1.500 2004/05/11 12:16:47 mattias Revision 1.500 2004/05/11 12:16:47 mattias
replaced writeln by debugln replaced writeln by debugln

View File

@ -73,6 +73,23 @@ begin
{$EndIF} {$EndIF}
end; end;
procedure gdk_event_key_set_string(Event: PGDKEventKey; const NewString: PChar
);
var
OldString: PChar;
begin
{$IfDef GTK2}
OldString := Pointer(Event^._String);
{$Else}
OldString := Pointer(Event^.TheString);
{$EndIF}
if (OldString<>nil) then
if (NewString<>nil) then
OldString[0]:=NewString[0]
else
OldString[0]:=#0;
end;
function gdk_event_get_type(Event : Pointer) : guint; function gdk_event_get_type(Event : Pointer) : guint;
begin begin
{$IfDef GTK2} {$IfDef GTK2}
@ -6761,6 +6778,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.279 2004/05/14 12:53:25 mattias
improved grids e.g. OnPrepareCanvas patch from Jesus
Revision 1.278 2004/05/11 12:16:47 mattias Revision 1.278 2004/05/11 12:16:47 mattias
replaced writeln by debugln replaced writeln by debugln

View File

@ -396,6 +396,7 @@ function IsToggleKey(const AVKey: Byte): Boolean;
//function GTKEventState2ShiftState(KeyState: Word): TShiftState; //function GTKEventState2ShiftState(KeyState: Word): TShiftState;
//function KeyToListCode_(KeyCode, VirtKeyCode: Word; Extended: boolean): integer; //function KeyToListCode_(KeyCode, VirtKeyCode: Word; Extended: boolean): integer;
procedure gdk_event_key_get_string(Event: PGDKEventKey; var theString: Pointer); procedure gdk_event_key_get_string(Event: PGDKEventKey; var theString: Pointer);
procedure gdk_event_key_set_string(Event: PGDKEventKey; const NewString: PChar);
function gdk_event_get_type(Event: Pointer): guint; function gdk_event_get_type(Event: Pointer): guint;
procedure RememberKeyEventWasHandledByLCL(Event: PGdkEventKey; procedure RememberKeyEventWasHandledByLCL(Event: PGdkEventKey;
BeforeEvent: boolean); BeforeEvent: boolean);