Gtk2: implemented GetCaretPos() & SetCaretPos() for TCustomEdit.Patch by Torsten Bonde Christiansen. fixes #17187

git-svn-id: trunk@27218 -
This commit is contained in:
zeljko 2010-08-28 11:45:03 +00:00
parent 1a26b3406d
commit 59cfec4d13
2 changed files with 60 additions and 10 deletions

View File

@ -189,9 +189,11 @@ type
published
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; override;
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class procedure SetCaretPos(const ACustomEdit: TCustomEdit; const NewPos: TPoint); override;
class procedure SetCharCase(const ACustomEdit: TCustomEdit; NewCase: TEditCharCase); override;
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
class procedure SetMaxLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
@ -1074,6 +1076,19 @@ begin
end;
end;
class function TGtk2WSCustomEdit.GetCaretPos(const ACustomEdit: TCustomEdit
): TPoint;
var
Widget: PGtkWidget;
begin
Result := Point(0,0);
if not WSCheckHandleAllocated(ACustomEdit, 'GetCaretPos') then
Exit;
Widget := PGtkWidget(ACustomEdit.Handle);
Result.X := gtk_editable_get_position(PGtkEditable(Widget));
end;
class function TGtk2WSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit
): integer;
var
@ -1098,6 +1113,37 @@ begin
Result := ABS(Entry^.current_pos - Entry^.selection_bound);
end;
function gtk2WSDelayedSelStart(Data: Pointer): gboolean; cdecl;
var
Entry: PGtkEntry;
begin
Result := False;
Entry := PGtkEntry(PWidgetInfo(Data)^.CoreWidget);
gtk_editable_set_position(PGtkEditable(Entry), PWidgetInfo(Data)^.CursorPos);
g_idle_remove_by_data(Data);
end;
class procedure TGtk2WSCustomEdit.SetCaretPos(const ACustomEdit: TCustomEdit;
const NewPos: TPoint);
var
Entry: PGtkEntry;
WidgetInfo: PWidgetInfo;
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetCaretPos') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
if GetCaretPos(ACustomEdit).X = NewPos.X then exit;
if LockOnChange(PgtkObject(Entry),0) > 0 then
begin
WidgetInfo := GetWidgetInfo(Entry);
WidgetInfo^.CursorPos := NewPos.X;
// postpone
g_idle_add(@gtk2WSDelayedSelStart, WidgetInfo);
end else
gtk_editable_set_position(PGtkEditable(Entry), NewPos.X);
end;
class procedure TGtk2WSCustomEdit.SetEchoMode(const ACustomEdit: TCustomEdit;
NewMode: TEchoMode);
var
@ -1143,16 +1189,6 @@ begin
gtk_editable_set_editable(PGtkEditable(Widget), not NewReadOnly);
end;
function gtk2WSDelayedSelStart(Data: Pointer): gboolean; cdecl;
var
Entry: PGtkEntry;
begin
Result := False;
Entry := PGtkEntry(PWidgetInfo(Data)^.CoreWidget);
gtk_editable_set_position(PGtkEditable(Entry), PWidgetInfo(Data)^.CursorPos);
g_idle_remove_by_data(Data);
end;
class procedure TGtk2WSCustomEdit.SetSelStart(const ACustomEdit: TCustomEdit;
NewStart: integer);
var

View File

@ -77,6 +77,7 @@ type
class procedure UpdateWindowFlags(const AWidget: TQtMainWindow;
ABorderStyle: TFormBorderStyle; ABorderIcons: TBorderIcons; AFormStyle: TFormStyle);
published
class function CanFocus(const AWinControl: TWinControl): Boolean; override;
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure CloseModal(const ACustomForm: TCustomForm); override;
@ -563,6 +564,19 @@ begin
AWidget.EndUpdate;
end;
class function TQtWSCustomForm.CanFocus(const AWinControl: TWinControl
): Boolean;
var
Widget: TQtWidget;
begin
if AWinControl.HandleAllocated then
begin
Widget := TQtWidget(AWinControl.Handle);
Result := Widget.getVisible and Widget.getEnabled;
end else
Result := False;
end;
{ TQtWSHintWindow }
class function TQtWSHintWindow.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;