[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Drag-and-Drop with guile-gnome?
From: |
steve tell |
Subject: |
Re: Drag-and-Drop with guile-gnome? |
Date: |
Sat, 26 May 2007 23:15:06 -0400 (EDT) |
On Fri, 25 May 2007, Andy Wingo wrote:
Hey Steve,
On Fri, 2007-05-25 at 00:32 -0400, steve tell wrote:
Is it possible to do Drag-and-Drop with guile-gnome-2.15.9x?
Does anyone have any examples?
It turns out yesterday's release shouldn't be used because I borked
something with Cairo -- will put out a fix later today.
But!
My photoblogger app still works I think,
http://wingolog.org/software/photoblogger/. There is some dnd code
there, but it doesn't always work. You might have to do some hacking :)
Thanks!
After installing guile-lib-0.1.3, your photoblogger runs well enough to
serve as an example of the "drop" part, but it doesn't provide sources
that can be dragged to its own or another app's drop-site.
With that as a guide, I'm crafting a simpler example, testdnd.scm.
gtk-drag-dest-set works, and interoperates with the
gtk+-2.4.14/tests/testdnd.c I had lying around.
But I think gtk-drag-source-set is missing a needed entry in
guile-gnome-platform-*/gtk/gnome/overrides/gtk.defs
The def in defs/gnome/defs/gtk.defs:
(define-function gtk_drag_source_set
(c-name "gtk_drag_source_set")
(return-type "none")
(parameters
'("GtkWidget*" "widget")
'("GdkModifierType" "start_button_mask")
'("const-GtkTargetEntry*" "targets")
'("gint" "n_targets")
'("GdkDragAction" "actions")
)
)
has arguments of the pattern of an array pointer followed by an integer
specifying the length of the array. Am I correct in assuming that all
functions like that need to have an override def specifying the
scheme-friendly way of passing such a list argument? There seem to be
others like that too.
Rather than further hacking 2.15.90, I guess I'll try to upgrade g-wrap
and then guile-gnome-platform.
Steve
#!/usr/bin/guile -s
!#
; testdnd - demonstrate fundamental drag-and-drop.
; Modeled after gtk+-2.4.14/tests/testdnd.c
(debug-enable 'debug 'backtrace)
(read-enable 'positions)
(use-modules (gnome-0)
(gnome gtk)
)
(define (label-drag-data-received w drag-context x y selection-data info t)
(let* ((data (gtk-selection-data-get-as-string selection-data)))
(format #t "received in label: ~s\n" data)
(gtk-drag-finish drag-context #t #t)))
(define (source-drag-data-get w drag-context x y selection-data info t)
(format #f "source-drag-data-get ~s ~s\n" drag-context info)
(gtk-selection-data-set-as-string selection-data "drop data")
)
(define (source-drag-data-delete w drag-context)
(format #f "delete the drag-data!\n")
)
(define (app)
(let* ((window (make <gtk-window> #:type 'toplevel))
(table (make <gtk-table>
#:n-columns 2 #:n-rows 2 #:homogeneous #f
#:border-width 5 #:row-spacing 5 #:row-spacing 10))
(droplabel (make <gtk-label> #:label "Drop here"))
(poplabel (make <gtk-label> #:label "Someday: Popup"))
(dragbutton (make <gtk-button> #:label "Drag This"))
)
(gtk-window-set-default-size window 300 200)
(gtk-container-add window table)
(attach table droplabel
0 1 0 1 '(fill expand) '(fill expand) 0 0)
(gtk-drag-dest-set droplabel 'all '("text/plain") 'copy)
(connect droplabel 'drag-data-received label-drag-data-received)
(attach table poplabel
1 2 1 2 '(fill expand) '(fill expand) 0 0)
(attach table dragbutton
0 1 1 2 '(fill expand) '(fill expand) 0 0)
; doesn't work, at least with guile-gnome-platform 2.15.90
; (gtk-drag-source-set dragbutton #f '("text/plain") 'copy)
; (gtk-drag-source-set-icon dragbutton ) ;TODO figure out the guileish args
(connect dragbutton 'drag-data-get source-drag-data-get)
(connect dragbutton 'drag-data-delete source-drag-data-delete)
; TODO: trashcan pixmap and open/closed handling
(gtk-widget-show-all window)
(gtk-main)))
(app)