Felipe Monteiro de Carvalho wrote:
On 5/3/06, dR <[EMAIL PROTECTED]> wrote:
Hello, I have some questions about Lazarus.
What is the status of drag-and-drop functionality? Is
anyone working on it, and do you need help?
I think noone is working on it and it needs to be implemented. Any
help would be greatly appreciated =)
Are you willing to implement it? If so, would you do it on Windows or
Gtk first? We can help you implementing it.
Searching the mailling list archives on Gmane I found some topics
about drag&drop from january.
I am using Drag and drop for files, and it is working fine under gtk -
Attached is code fragment I am currently using. I posted something
similar to the mailing lists a while back. I am not sure how to include
it in the LCL - The code as is generates the WM_DROPFILES message more
or less like MSWindows
Colin
interface
function DroppedFiles(Event: QDropEventH):TStringList;
procedure DragAcceptFiles(Handle: THandle; Enabled: Boolean);
function DroppedFiles(var Message: TMessage):TStringList;
implementation
{$IFDEF FPC}
var
Targets: array [0..2] of TGtkTargetEntry = ((target:'text/plain'; flags:0; info:0), (target:'text/uri-list'; flags:0; info:1), (target:'STRING'; flags:0; info:1));
function DropCallBack(widget: PGtkWidget; dc: PGdkDragContext; x, y: gint; selection: PGtkSelectionData; info, t: guint; data: gPointer): GBoolean; cdecl;
var
list: PGList;
Message: TMessage;
begin
if (data <> nil) and (selection <> nil) and (selection^.length >= 0) then begin
list := dc^.targets;
while list <> nil do begin
if (selection^.data <> nil) and (StrPos(PChar(selection^.data), 'file://') = PChar(selection^.data)) then begin
Message.Msg := WM_DROPFILES;
Message.lParam := LongInt(selection^.data);
TWinControl(data).Dispatch(Message);
Exit;
end;
list := list^.next;
end;
end;
end;
function DroppedFiles(var Message: TMessage):TStringList;
var
i: Integer;
begin
Result := TStringList.Create;
try
Result.Text := PChar(Message.lParam);
for i := 0 to Result.Count-1 do
if Pos('file://', Result[i]) = 1 then
Result[i] := Copy(Result[i], 8, Length(Result[i]));
except
Result.Free;
Raise;
end;
end;
procedure DragAcceptFiles(Handle: THandle; Enabled: Boolean);
begin
if Enabled then begin
gtk_drag_dest_set(PGtkWidget(Handle), GTK_DEST_DEFAULT_ALL, @Targets[0], Length(Targets), GDK_ACTION_COPY);
gtk_signal_connect(PGtkObject(Handle), 'drag_data_received', TGTKSignalFunc(@DropCallBack), gPointer(FindOwnerControl(Handle)));
end else
gtk_drag_dest_unset(PGtkWidget(Handle));
end;
{$IFDEF MSWINDOWS}
function DroppedFiles(var Message: TMessage):TStringList;
var
n, nFiles: Integer;
Buffer: array [0..600] of Char;
begin
Result := TStringList.Create;
try
try
nFiles := DragQueryFile(Message.wParam, UINT(MinusOne), nil, 0);
for n := 0 to nFiles-1 do begin
DragQueryFile(Message.wParam, n, @Buffer[0], 270);
Result.Add(StrPas(Buffer));
end;
finally
DragFinish(Message.wParam);
Message.Result := 0;
end;
except
Result.Free;
Raise;
end;
end;
{$ENDIF}