- TGtk2WSCustomEdit.SetSelStart, TGtk2WSCustomEdit.SetSelLength
- replace some 'if not HandleAllocated then' with 'if not WSCheckHandleAllocated then'

git-svn-id: trunk@12599 -
This commit is contained in:
paul 2007-10-26 16:17:18 +00:00
parent 78c0168346
commit 5a22410984
3 changed files with 63 additions and 14 deletions

View File

@ -1001,16 +1001,20 @@ end;
class procedure TGtkWSCustomEdit.SetSelStart(const ACustomEdit: TCustomEdit;
NewStart: integer);
var
Widget: PGtkWidget;
MaxPos: Integer;
Widget: PGtkWidget;
MaxPos: Integer;
begin
Widget:=GetWidgetInfo(Pointer(ACustomEdit.Handle), true)^.CoreWidget;
if WidgetGetSelStart(Widget)=NewStart then exit;
// sometimes the gtk freezes the memo, changes something and emits the change
// event. Then the LCL gets notified and wants to react: force thaw (unfreeze)
if GTK_IS_TEXT(Widget) then
begin
gtk_text_thaw(PGtkText(Widget));
MaxPos := gtk_text_get_length(PGtkText(Widget));
MaxPos := gtk_text_get_length(PGtkText(Widget));
end
else
MaxPos := 0;
gtk_editable_set_position(PGtkOldEditable(Widget), Min(NewStart, MaxPos));
WidgetSetSelLength(Widget,0); // Setting the selection start should cancel any selection
end;

View File

@ -159,7 +159,6 @@ begin
AWidget:=PGtkWidget(AWinControl.Handle);
AWidget:=GetWidgetInfo(AWidget, True)^.CoreWidget;
Gtk2WidgetSet.SetWidgetColor(AWidget, AWinControl.font.color, AWinControl.color,[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED,GTK_STYLE_BASE]);
end;
class procedure TGtk2WSCustomMemo.SetFont(const AWinControl: TWinControl;
@ -167,7 +166,8 @@ class procedure TGtk2WSCustomMemo.SetFont(const AWinControl: TWinControl;
var
AWidget: PGTKWidget;
begin
if not AWinControl.HandleAllocated then exit;
if not WSCheckHandleAllocated(AWinControl, 'SetFont') then
Exit;
if AFont.IsDefault then exit;
AWidget:= PGtkWidget(AWinControl.Handle);
@ -186,8 +186,9 @@ class procedure TGtk2WSCustomMemo.SetSelStart(const ACustomEdit: TCustomEdit;
var
MemoStrings: TGtk2MemoStrings;
begin
if not ACustomEdit.HandleAllocated then exit;
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelStart') then
Exit;
MemoStrings := TCustomMemo(ACustomEdit).Lines as TGtk2MemoStrings;
MemoStrings.QueueCursorMove(NewStart);
end;
@ -200,7 +201,9 @@ var
StartIter: TGtkTextIter;
SelStart: Integer;
begin
if not ACustomEdit.HandleAllocated then exit;
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelLength') then
Exit;
TextView := PGtkTextView(GetWidgetInfo(Pointer(ACustomEdit.Handle), False)^.CoreWidget);
TextBuffer := gtk_text_view_get_buffer(TextView);
SelStart := GetSelStart(ACustomEdit);
@ -220,7 +223,8 @@ class procedure TGtk2WSCustomMemo.SetWantTabs(const ACustomMemo: TCustomMemo;
var
TextView: PGtkTextView;
begin
if not ACustomMemo.HandleAllocated then exit;
if not WSCheckHandleAllocated(ACustomMemo, 'SetWantTabs') then
Exit;
TextView := PGtkTextView(GetWidgetInfo(Pointer(ACustomMemo.Handle), False)^.CoreWidget);
gtk_text_view_set_accepts_tab(TextView, NewWantTabs);
@ -249,8 +253,9 @@ var
StartPos, EndPos: Integer;
begin
Result := 0;
if not ACustomEdit.HandleAllocated then exit;
if not WSCheckHandleAllocated(ACustomEdit, 'GetSelStart') then
Exit;
TextView := PGtkTextView(GetWidgetInfo(Pointer(ACustomEdit.Handle), False)^.CoreWidget);
TextBuffer := gtk_text_view_get_buffer(TextView);
TextMark := gtk_text_buffer_get_insert(TextBuffer);
@ -275,7 +280,8 @@ var
StartIter, EndIter: TGtkTextIter;
begin
Result := 0;
if not ACustomEdit.HandleAllocated then exit;
if not WSCheckHandleAllocated(ACustomEdit, 'GetSelLength') then
Exit;
TextView := PGtkTextView(GetWidgetInfo(Pointer(ACustomEdit.Handle), False)^.CoreWidget);
TextBuffer := gtk_text_view_get_buffer(TextView);

View File

@ -37,7 +37,7 @@ uses
StdCtrls, LMessages,
////////////////////////////////////////////////////
glib2, gdk2, gtk2, Pango,
WSControls, WSStdCtrls, WSLCLClasses, GtkWSStdCtrls, Gtk2Int, LCLType, GtkDef,
WSControls, WSProc, WSStdCtrls, WSLCLClasses, GtkWSStdCtrls, Gtk2Int, LCLType, GtkDef,
LCLProc, Gtk2CellRenderer, GTKWinApiWindow, gtkglobals, gtkproc, InterfaceBase;
type
@ -184,6 +184,8 @@ type
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
class procedure SetEchoMode(const ACustomEdit: TCustomEdit; NewMode: TEchoMode); override;
class procedure SetPasswordChar(const ACustomEdit: TCustomEdit; NewChar: char); override;
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
end;
{ TGtk2WSCustomMemo }
@ -741,6 +743,9 @@ class function TGtk2WSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit
var
Entry: PGtkEntry;
begin
Result := 0;
if not WSCheckHandleAllocated(ACustomEdit, 'GetSelStart') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
Result := Min(Entry^.current_pos, Entry^.selection_bound);
end;
@ -750,8 +755,11 @@ class function TGtk2WSCustomEdit.GetSelLength(const ACustomEdit: TCustomEdit
var
Entry: PGtkEntry;
begin
Result := 0;
if not WSCheckHandleAllocated(ACustomEdit, 'GetSelLength') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
Result := ABS(Entry^.current_pos - Entry^.selection_bound);
Result := ABS(Entry^.current_pos - Entry^.selection_bound);
end;
class procedure TGtk2WSCustomEdit.SetEchoMode(const ACustomEdit: TCustomEdit;
@ -759,6 +767,8 @@ class procedure TGtk2WSCustomEdit.SetEchoMode(const ACustomEdit: TCustomEdit;
var
Entry: PGtkEntry;
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetEchoMode') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
if NewMode in [emNone,emPassword] then begin
gtk_entry_set_visibility(Entry,false);
@ -774,6 +784,8 @@ var
PWChar: Integer;
Entry: PGtkEntry;
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetPasswordChar') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
if ACustomEdit.EchoMode=emNone then
PWChar:=0
@ -785,6 +797,33 @@ begin
gtk_entry_set_invisible_char(Entry,PWChar);
end;
class procedure TGtk2WSCustomEdit.SetSelStart(const ACustomEdit: TCustomEdit;
NewStart: integer);
var
NewPos: Integer;
Entry: PGtkEntry;
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelStart') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
if GetSelStart(ACustomEdit) = NewStart then exit;
NewPos := Min(NewStart, Entry^.text_max_length);
gtk_entry_set_position(Entry, NewPos);
end;
class procedure TGtk2WSCustomEdit.SetSelLength(
const ACustomEdit: TCustomEdit; NewLength: integer);
var
Entry: PGtkEntry;
begin
if not WSCheckHandleAllocated(ACustomEdit, 'SetSelLength') then
Exit;
Entry := PGtkEntry(ACustomEdit.Handle);
gtk_entry_select_region(Entry,
Entry^.current_pos,
Entry^.current_pos + NewLength);
end;
class procedure TGtk2WSCustomComboBox.ReCreateCombo(
const ACustomComboBox: TCustomComboBox; const AWithEntry: Boolean;
const AWidgetInfo: PWidgetInfo);