mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-15 06:09:30 +02:00
Gtk3: implemented dragimageList.
This commit is contained in:
parent
1e2aa7dbdd
commit
a9736f3470
@ -89,6 +89,11 @@ type
|
||||
// tmp
|
||||
cssProvider:PGtkCssProvider;
|
||||
|
||||
FDragImageList: PGtkWidget;
|
||||
FDragImageListIcon: PGtkImage;
|
||||
FDragHotSpot: TPoint;
|
||||
FDragImageLock: Boolean;
|
||||
|
||||
public
|
||||
function CreateDCForWidget(AWidget: PGtkWidget; AWindow: PGdkWindow; cr: Pcairo_t): HDC;
|
||||
procedure AddWindow(AWindow: PGtkWindow);
|
||||
@ -105,6 +110,12 @@ type
|
||||
procedure FreeStockItems;
|
||||
function CreateDefaultFont: HFONT;
|
||||
|
||||
{dragImageList support}
|
||||
function DragImageList_BeginDrag(APixBuf: PGdkPixbuf; AHotSpot: TPoint): Boolean;
|
||||
procedure DragImageList_EndDrag;
|
||||
function DragImageList_DragMove(X, Y: Integer): Boolean;
|
||||
function DragImageList_SetVisible(NewVisible: Boolean): Boolean;
|
||||
|
||||
public
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
|
@ -265,6 +265,11 @@ var
|
||||
begin
|
||||
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
|
||||
inherited Create;
|
||||
FDragImageList := nil;
|
||||
FDragImageListIcon := nil;
|
||||
FDragHotSpot := Point(0, 0);
|
||||
FDragImageLock := False;
|
||||
|
||||
FActivityCounter := 0;
|
||||
FCSSTheme := TStringList.Create;
|
||||
FSystemMetricsList := TIntegerList.Create;
|
||||
@ -970,3 +975,68 @@ begin
|
||||
Result := HFONT(AFont);
|
||||
end;
|
||||
|
||||
function TGtk3WidgetSet.DragImageList_BeginDrag(APixBuf: PGdkPixbuf;
|
||||
AHotSpot: TPoint): Boolean;
|
||||
var
|
||||
w, h: gint;
|
||||
begin
|
||||
if FDragImageList = nil then
|
||||
begin
|
||||
FDragImageList := gtk_window_new(GTK_WINDOW_POPUP);
|
||||
W := APixBuf^.get_width;
|
||||
H := APixBuf^.get_height;
|
||||
gtk_window_set_default_size(PGtkWindow(FDragImageList), w, h);
|
||||
gtk_widget_realize(FDragImageList);
|
||||
gdk_window_set_decorations(FDragImageList^.window, []);
|
||||
gdk_window_set_functions(FDragImageList^.window, [GDK_FUNC_RESIZE,GDK_FUNC_CLOSE]);
|
||||
|
||||
FDragImageListIcon := gtk_image_new_from_pixbuf(APixBuf);
|
||||
PGtkWindow(FDragImageList)^.add(FDragImageListIcon);
|
||||
FDragImageListIcon^.show;
|
||||
gtk_widget_show(FDragImageListIcon);
|
||||
// make window transparent outside mask
|
||||
//gdk_window_shape_combine_region();
|
||||
//gdk_window_shape_combine_mask(FDragImageList^.window, APixBuf, 0, 0);
|
||||
FDragHotSpot := AHotSpot;
|
||||
end;
|
||||
Result := FDragImageList <> nil;
|
||||
end;
|
||||
|
||||
procedure TGtk3WidgetSet.DragImageList_EndDrag;
|
||||
begin
|
||||
if FDragImageList <> nil then
|
||||
begin
|
||||
if FDragImageListIcon <> nil then
|
||||
gtk_widget_destroy(FDragImageListIcon);
|
||||
gtk_widget_destroy(FDragImageList);
|
||||
FDragImageList := nil;
|
||||
FDragImageListIcon := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TGtk3WidgetSet.DragImageList_DragMove(X, Y: Integer): Boolean;
|
||||
begin
|
||||
Result := FDragImageList <> nil;
|
||||
if Result then
|
||||
begin
|
||||
if Gtk3IsGdkWindow(FDragImageList^.Window) then
|
||||
begin
|
||||
if FDragImageList^.Window^.is_visible then
|
||||
gdk_window_raise(FDragImageList^.Window);
|
||||
PGtkWindow(FDragImageList)^.move(X - FDragHotSpot.X, Y - FDragHotSpot.Y);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TGtk3WidgetSet.DragImageList_SetVisible(NewVisible: Boolean): Boolean;
|
||||
begin
|
||||
Result := FDragImageList <> nil;
|
||||
if Result then
|
||||
begin
|
||||
if NewVisible then
|
||||
FDragImageList^.show_all
|
||||
else
|
||||
FDragImageList^.hide;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -125,7 +125,7 @@ type
|
||||
|
||||
|
||||
implementation
|
||||
uses SysUtils, gtk3objects, gtk3procs;
|
||||
uses SysUtils, gtk3objects, gtk3procs, gtk3int;
|
||||
|
||||
{ TGtk3WSWinControl }
|
||||
|
||||
@ -586,30 +586,48 @@ end;
|
||||
|
||||
class function TGtk3WSDragImageListResolution.BeginDrag(const ADragImageList: TDragImageListResolution;
|
||||
Window: HWND; AIndex, X, Y: Integer): Boolean;
|
||||
var
|
||||
ABitmap: TBitmap;
|
||||
APixBuf: PGdkPixbuf;
|
||||
begin
|
||||
Result := False;
|
||||
ABitmap := TBitmap.Create;
|
||||
ADragImageList.GetBitmap(AIndex, ABitmap);
|
||||
if (ABitmap.Handle = 0) or (ABitmap.Width = 0) or (ABitmap.Height = 0) then
|
||||
begin
|
||||
ABitmap.Free;
|
||||
exit;
|
||||
end;
|
||||
APixBuf := TGtk3Image(ABitmap.Handle).Handle;
|
||||
APixBuf^.ref;
|
||||
Result := Gtk3Widgetset.DragImageList_BeginDrag(APixBuf, ADragImageList.DragHotspot);
|
||||
if Result then
|
||||
Gtk3Widgetset.DragImageList_DragMove(X, Y);
|
||||
APixBuf^.unref;
|
||||
ABitmap.Free;
|
||||
end;
|
||||
|
||||
class function TGtk3WSDragImageListResolution.DragMove(const ADragImageList: TDragImageListResolution;
|
||||
X, Y: Integer): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
Result := Gtk3Widgetset.DragImageList_DragMove(X, Y);
|
||||
end;
|
||||
|
||||
class procedure TGtk3WSDragImageListResolution.EndDrag(const ADragImageList: TDragImageListResolution);
|
||||
begin
|
||||
Gtk3Widgetset.DragImageList_EndDrag;
|
||||
end;
|
||||
|
||||
class function TGtk3WSDragImageListResolution.HideDragImage(const ADragImageList: TDragImageListResolution;
|
||||
ALockedWindow: HWND; DoUnLock: Boolean): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
Result := Gtk3Widgetset.DragImageList_SetVisible(False);
|
||||
end;
|
||||
|
||||
class function TGtk3WSDragImageListResolution.ShowDragImage(const ADragImageList: TDragImageListResolution;
|
||||
ALockedWindow: HWND; X, Y: Integer; DoLock: Boolean): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
Result := Gtk3Widgetset.DragImageList_DragMove(X, Y) and Gtk3Widgetset.DragImageList_SetVisible(True);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -154,8 +154,8 @@ end;
|
||||
// controls
|
||||
function RegisterDragImageListResolution: Boolean; alias : 'WSRegisterDragImageListResolution';
|
||||
begin
|
||||
// RegisterWSComponent(TDragImageListResolution, TGtk3WSDragImageListResolution);
|
||||
Result := False;
|
||||
RegisterWSComponent(TDragImageListResolution, TGtk3WSDragImageListResolution);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterLazAccessibleObject: Boolean; alias : 'WSRegisterLazAccessibleObject';
|
||||
|
Loading…
Reference in New Issue
Block a user