diff --git a/src/gdk.jl b/src/gdk.jl index c71c9ae1..cac0d1cb 100644 --- a/src/gdk.jl +++ b/src/gdk.jl @@ -68,6 +68,21 @@ baremodule GdkKeySyms const Hyper_R = 0xffee end +baremodule GdkAtoms + const NONE = 0x0000 + const SELECTION_PRIMARY = 0x0001 + const SELECTION_SECONDARY = 0x0002 + const SELECTION_TYPE_ATOM = 0x0004 + const SELECTION_TYPE_BITMAP = 0x0005 + const SELECTION_TYPE_COLORMAP = 0x0007 + const SELECTION_TYPE_DRAWABLE = 0x0011 + const SELECTION_TYPE_INTEGER = 0x0013 + const SELECTION_TYPE_PIXMAP = 0x0014 + const SELECTION_TYPE_STRING = 0x001f + const SELECTION_TYPE_WINDOW = 0x0021 + const SELECTION_CLIPBOARD = 0x0045 +end + abstract GdkEvent <: GBoxed make_gvalue(GdkEvent, Ptr{GdkEvent}, :boxed, (:gdk_event,:libgdk)) function convert(::Type{GdkEvent}, evt::Ptr{GdkEvent}) @@ -178,4 +193,3 @@ end keyval(name::String) = ccall((:gdk_keyval_from_name,libgdk),Cuint,(Ptr{Uint8},),bytestring(name)) - diff --git a/src/gtktypes.jl b/src/gtktypes.jl index f5d9dba9..2afa5c23 100644 --- a/src/gtktypes.jl +++ b/src/gtktypes.jl @@ -89,6 +89,7 @@ end @gtktype GtkTextView @gtktype GtkTextMark @gtktype GtkTextTag +@gtktype GtkClipboard @gtktype GtkToolbar @gtktype GtkToolItem @gtktype GtkToolButton @@ -153,4 +154,3 @@ else :( GtkStyleContextLeaf($(args...)) ) end end - diff --git a/src/long_exports.jl b/src/long_exports.jl index 3a79576c..26dea486 100644 --- a/src/long_exports.jl +++ b/src/long_exports.jl @@ -58,6 +58,7 @@ export GObject, GtkTextMark, GtkTextTag, GtkTextView, + GtkClipboard, GtkToolButton, GtkToolItem, GtkToolbar, diff --git a/src/long_leaf_exports.jl b/src/long_leaf_exports.jl index df0d07cd..d1d13e32 100644 --- a/src/long_leaf_exports.jl +++ b/src/long_leaf_exports.jl @@ -59,6 +59,7 @@ export @GtkTextMark, @GtkTextTag, @GtkTextView, + @GtkClipboard, @GtkToolButton, @GtkToolItem, @GtkToolbar, @@ -134,6 +135,7 @@ export GtkTextMarkLeaf, GtkTextTagLeaf, GtkTextViewLeaf, + GtkClipboardLeaf, GtkToolButtonLeaf, GtkToolItemLeaf, GtkToolbarLeaf, diff --git a/src/text.jl b/src/text.jl index 613ab4f5..38d572a6 100644 --- a/src/text.jl +++ b/src/text.jl @@ -83,10 +83,22 @@ immutable GtkTextRange <: Range GtkTextRange(a,b) = new(mutable(copy(a)),mutable(copy(b))) end -#type GtkClipboard -#TODO -#end - +##### GtkClipboard ##### + +GtkClipboardLeaf(selection::Uint16) = GtkClipboardLeaf(ccall((:gtk_clipboard_get,libgtk), Ptr{GObject}, + (Uint16,), selection)) +GtkClipboardLeaf() = GtkClipboardLeaf(Gtk.GdkAtoms.SELECTION_CLIPBOARD) +clipboard_set_text(clip::GtkClipboard,text::String) = ccall((:gtk_clipboard_set_text,libgtk), Void, + (Ptr{GObject}, Ptr{Uint8},Cint), clip, text, sizeof(text)) +clipboard_store(clip::Gtk.GtkClipboard) = ccall((:gtk_clipboard_store ,libgtk), Void, + (Ptr{GObject},), clip) + +#note: this needs main_loops to run +function clipboard_wait_for_text(clip::Gtk.GtkClipboard) + ptr = ccall((:gtk_clipboard_wait_for_text,libgtk), Ptr{Uint8}, + (Ptr{GObject},), clip) + return ptr == C_NULL ? "" : bytestring(ptr) +end ##### GtkTextIter ##### #TODO: search diff --git a/test/gui.jl b/test/gui.jl index 8c87c0d3..f8aa6d06 100644 --- a/test/gui.jl +++ b/test/gui.jl @@ -561,3 +561,12 @@ str = takebuf_string(io) @assert str == "scrolling\n" destroy(w) + +using Gtk.@GtkClipboard +# Clipboard +w = @Window("Window", 400, 300) |> showall +clip = @GtkClipboard() +Gtk.clipboard_set_text(clip,"testing clipboard") +Gtk.clipboard_store(clip) +@assert Gtk.clipboard_wait_for_text(clip) == "testing clipboard" +destroy(w)