mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-04 13:49:34 +01:00
Separates gtk2spin
git-svn-id: trunk@14872 -
This commit is contained in:
parent
dcb54a9371
commit
30b56850c0
@ -27,15 +27,17 @@ unit GtkWSSpin;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
// Bindings
|
||||||
{$IFDEF gtk2}
|
{$IFDEF gtk2}
|
||||||
glib2, gdk2pixbuf, gdk2, gtk2, Pango,
|
glib2, gdk2pixbuf, gdk2, gtk2, Pango,
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
glib, gdk, gtk,
|
glib, gdk, gtk,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
GtkInt,
|
// RTL, FCL, LCL
|
||||||
LCLProc, Spin, StdCtrls, GtkProc, GtkExtra, GtkDef,
|
Controls, LCLType, LCLProc, Spin, StdCtrls,
|
||||||
GtkWSControls, GtkWSStdCtrls,
|
// Widgetset
|
||||||
WSLCLClasses, WSSpin, Controls, LCLType;
|
GtkProc, GtkExtra, GtkDef, GtkInt, GtkWSControls, GtkWSStdCtrls,
|
||||||
|
WSLCLClasses, WSSpin;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ uses
|
|||||||
// Gtk2WSMaskEdit,
|
// Gtk2WSMaskEdit,
|
||||||
Gtk2WSMenus,
|
Gtk2WSMenus,
|
||||||
// Gtk2WSPairSplitter,
|
// Gtk2WSPairSplitter,
|
||||||
// Gtk2WSSpin,
|
Gtk2WSSpin,
|
||||||
Gtk2WSStdCtrls,
|
Gtk2WSStdCtrls,
|
||||||
// Gtk2WSToolwin,
|
// Gtk2WSToolwin,
|
||||||
Gtk2Themes,
|
Gtk2Themes,
|
||||||
|
|||||||
@ -68,11 +68,44 @@ function GTKWindowStateEventCB(widget: PGtkWidget;
|
|||||||
function gtkMouseWheelCB(widget: PGtkWidget; event: PGdkEventScroll;
|
function gtkMouseWheelCB(widget: PGtkWidget; event: PGdkEventScroll;
|
||||||
data: gPointer): GBoolean; cdecl;
|
data: gPointer): GBoolean; cdecl;
|
||||||
|
|
||||||
|
{ Miscelaneus Widget functions }
|
||||||
|
|
||||||
|
function WidgetGetSelStart(const Widget: PGtkWidget): integer;
|
||||||
|
procedure WidgetSetSelLength(const Widget: PGtkWidget; NewLength: integer);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses gtkproc; // Remove when separation is complete
|
uses gtkproc; // Remove when separation is complete
|
||||||
|
|
||||||
|
{ Callbacks for events }
|
||||||
|
|
||||||
{$include gtk2callback.inc}
|
{$include gtk2callback.inc}
|
||||||
|
|
||||||
|
{ Miscelaneus Widget functions }
|
||||||
|
|
||||||
|
function WidgetGetSelStart(const Widget: PGtkWidget): integer;
|
||||||
|
begin
|
||||||
|
if Widget <> nil then
|
||||||
|
begin
|
||||||
|
if PGtkOldEditable(Widget)^.selection_start_pos
|
||||||
|
< PGtkOldEditable(Widget)^.selection_end_pos
|
||||||
|
then
|
||||||
|
Result:= PGtkOldEditable(Widget)^.selection_start_pos
|
||||||
|
else
|
||||||
|
Result:= PGtkOldEditable(Widget)^.current_pos;// selection_end_pos
|
||||||
|
end else
|
||||||
|
Result:= 0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure WidgetSetSelLength(const Widget: PGtkWidget; NewLength: integer);
|
||||||
|
begin
|
||||||
|
if Widget<>nil then
|
||||||
|
begin
|
||||||
|
gtk_editable_select_region(PGtkOldEditable(Widget),
|
||||||
|
gtk_editable_get_position(PGtkOldEditable(Widget)),
|
||||||
|
gtk_editable_get_position(PGtkOldEditable(Widget)) + NewLength);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
@ -27,17 +27,13 @@ unit Gtk2WSSpin;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
////////////////////////////////////////////////////
|
// Bindings
|
||||||
// I M P O R T A N T
|
glib2, gdk2pixbuf, gdk2, gtk2, Pango,
|
||||||
////////////////////////////////////////////////////
|
// RTL, FCL, LCL
|
||||||
// To get as little as posible circles,
|
Controls, LCLType, LCLProc, Spin, StdCtrls,
|
||||||
// uncomment only when needed for registration
|
// Widgetset
|
||||||
////////////////////////////////////////////////////
|
GtkProc, GtkExtra, GtkDef, Gtk2Int, Gtk2WSControls, Gtk2WSStdCtrls,
|
||||||
// Spin,
|
Gtk2Proc, WSLCLClasses, WSSpin;
|
||||||
////////////////////////////////////////////////////
|
|
||||||
WSSpin, WSLCLClasses, Controls, Spin,
|
|
||||||
Gtk2Int,
|
|
||||||
gtk2;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -46,20 +42,145 @@ type
|
|||||||
TGtk2WSCustomFloatSpinEdit = class(TWSCustomFloatSpinEdit)
|
TGtk2WSCustomFloatSpinEdit = class(TWSCustomFloatSpinEdit)
|
||||||
private
|
private
|
||||||
protected
|
protected
|
||||||
|
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
|
||||||
public
|
public
|
||||||
|
class function GetSelStart(const ACustomEdit: TCustomEdit): integer; override;
|
||||||
|
class function GetSelLength(const ACustomEdit: TCustomEdit): integer; override;
|
||||||
|
class function GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): single; override;
|
||||||
|
|
||||||
|
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
|
||||||
|
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
||||||
|
|
||||||
|
class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
|
||||||
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TGtk2WSFloatSpinEdit }
|
function GetGtkSpinEntry(Spin: PGtkSpinButton): PGtkEntry;
|
||||||
|
function GetSpinGtkEntry(const Spin: TWinControl): PGtkEntry;
|
||||||
TGtk2WSFloatSpinEdit = class(TWSFloatSpinEdit)
|
function GetGtkFloatSpinEditable(Spin: PGtkSpinButton): PGtkOldEditable;
|
||||||
private
|
function GetSpinGtkEditable(const Spin: TWinControl): PGtkOldEditable;
|
||||||
protected
|
|
||||||
public
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function GetGtkSpinEntry(Spin: PGtkSpinButton): PGtkEntry;
|
||||||
|
begin
|
||||||
|
Result:=PGtkEntry(@(Spin^.entry));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetSpinGtkEntry(const Spin: TWinControl): PGtkEntry;
|
||||||
|
begin
|
||||||
|
Result:=GetGtkSpinEntry(PGtkSpinButton(Spin.Handle));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetGtkFloatSpinEditable(Spin: PGtkSpinButton): PGtkOldEditable;
|
||||||
|
begin
|
||||||
|
Result:=PGtkOldEditable(@(Spin^.entry));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetSpinGtkEditable(const Spin: TWinControl): PGtkOldEditable;
|
||||||
|
begin
|
||||||
|
Result:=GetGtkFloatSpinEditable(PGtkSpinButton(Spin.Handle));
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TGtkWSCustomFloatSpinEdit }
|
||||||
|
|
||||||
|
class procedure TGtk2WSCustomFloatSpinEdit.SetCallbacks(
|
||||||
|
const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
|
||||||
|
begin
|
||||||
|
TGtk2WSCustomEdit.SetCallbacks(AWidget, AWidgetInfo);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TGtk2WSCustomFloatSpinEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer;
|
||||||
|
begin
|
||||||
|
Result :=WidgetGetSelStart(PGtkWidget(GetSpinGtkEntry(ACustomEdit)));
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TGtk2WSCustomFloatSpinEdit.GetSelLength(const ACustomEdit: TCustomEdit): integer;
|
||||||
|
begin
|
||||||
|
with GetSpinGtkEditable(ACustomEdit)^ do
|
||||||
|
Result := Abs(integer(selection_end_pos)-integer(selection_start_pos));
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TGtk2WSCustomFloatSpinEdit.GetValue(
|
||||||
|
const ACustomFloatSpinEdit: TCustomFloatSpinEdit): single;
|
||||||
|
begin
|
||||||
|
// developer.gnome.org/doc/API/2.2/gtk/GtkSpinButton.html:
|
||||||
|
// "function gtk_spin_button_get_value_as_float is deprecated, use gtk_spin_button_get_value() instead"
|
||||||
|
Result:=Single(gtk_spin_button_get_value(PGtkSpinButton(ACustomFloatSpinEdit.Handle)));
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TGtk2WSCustomFloatSpinEdit.SetSelStart(const ACustomEdit: TCustomEdit;
|
||||||
|
NewStart: integer);
|
||||||
|
begin
|
||||||
|
gtk_editable_set_position(GetSpinGtkEditable(ACustomEdit), NewStart);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TGtk2WSCustomFloatSpinEdit.SetSelLength(const ACustomEdit: TCustomEdit;
|
||||||
|
NewLength: integer);
|
||||||
|
begin
|
||||||
|
WidgetSetSelLength(PGtkWidget(GetSpinGtkEntry(ACustomEdit)),
|
||||||
|
NewLength);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TGtk2WSCustomFloatSpinEdit.UpdateControl(
|
||||||
|
const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
|
||||||
|
var
|
||||||
|
AnAdjustment: PGtkAdjustment;
|
||||||
|
wHandle: HWND;
|
||||||
|
SpinWidget: PGtkSpinButton;
|
||||||
|
AMin, AMax: Single;
|
||||||
|
begin
|
||||||
|
//DebugLn(['TGtkWSCustomFloatSpinEdit.UpdateControl ',dbgsName(ACustomFloatSpinEdit)]);
|
||||||
|
wHandle := ACustomFloatSpinEdit.Handle;
|
||||||
|
SpinWidget:=GTK_SPIN_BUTTON(Pointer(wHandle));
|
||||||
|
|
||||||
|
if ACustomFloatSpinEdit.MaxValue > ACustomFloatSpinEdit.MinValue then
|
||||||
|
begin
|
||||||
|
AMin := ACustomFloatSpinEdit.MinValue;
|
||||||
|
AMax := ACustomFloatSpinEdit.MaxValue;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
AMin := -3.4E38; // min single
|
||||||
|
AMax := 3.4E38; // max single
|
||||||
|
end;
|
||||||
|
|
||||||
|
AnAdjustment:=gtk_spin_button_get_adjustment(SpinWidget);
|
||||||
|
if (AnAdjustment^.lower <> AMin)
|
||||||
|
or (AnAdjustment^.upper <> AMax) then
|
||||||
|
begin
|
||||||
|
AnAdjustment^.lower := AMin;
|
||||||
|
AnAdjustment^.upper := AMax;
|
||||||
|
gtk_adjustment_changed(AnAdjustment);
|
||||||
|
end;
|
||||||
|
|
||||||
|
gtk_spin_button_set_digits(SpinWidget, ACustomFloatSpinEdit.DecimalPlaces);
|
||||||
|
gtk_spin_button_set_value(SpinWidget,ACustomFloatSpinEdit.Value);
|
||||||
|
AnAdjustment^.step_increment := ACustomFloatSpinEdit.Increment;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TGtk2WSCustomFloatSpinEdit.CreateHandle(
|
||||||
|
const AWinControl: TWinControl; const AParams: TCreateParams
|
||||||
|
): TLCLIntfHandle;
|
||||||
|
var
|
||||||
|
Adjustment: PGtkAdjustment;
|
||||||
|
Widget: PGtkWidget;
|
||||||
|
WidgetInfo: PWidgetInfo;
|
||||||
|
begin
|
||||||
|
Adjustment := PGtkAdjustment(gtk_adjustment_new(1, 1, 100, 1, 1, 1));
|
||||||
|
Widget := gtk_spin_button_new(Adjustment, 1, 0);
|
||||||
|
gtk_widget_show_all(Widget);
|
||||||
|
|
||||||
|
{$IFDEF DebugLCLComponents}
|
||||||
|
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
|
||||||
|
{$ENDIF}
|
||||||
|
Result := TLCLIntfHandle(PtrUInt(Widget));
|
||||||
|
|
||||||
|
WidgetInfo := CreateWidgetInfo(Widget, AWinControl, AParams);
|
||||||
|
Set_RC_Name(AWinControl, Widget);
|
||||||
|
SetCallbacks(Widget, WidgetInfo);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
@ -68,7 +189,7 @@ initialization
|
|||||||
// To improve speed, register only classes
|
// To improve speed, register only classes
|
||||||
// which actually implement something
|
// which actually implement something
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// RegisterWSComponent(TCustomFloatSpinEdit, TGtk2WSCustomFloatSpinEdit);
|
RegisterWSComponent(TCustomFloatSpinEdit, TGtk2WSCustomFloatSpinEdit);
|
||||||
// RegisterWSComponent(TFloatSpinEdit, TGtk2WSFloatSpinEdit);
|
// RegisterWSComponent(TFloatSpinEdit, TGtk2WSFloatSpinEdit);
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
end.
|
end.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user