Skip to content

add basic GtkClipboard support #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/gdk.jl
Original file line number Diff line number Diff line change
@@ -68,6 +68,21 @@ baremodule GdkKeySyms
const Hyper_R = 0xffee
end

baremodule GdkAtoms
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are you getting all these from? Gtk itself appears to only defines "GDK_NONE"

PyGTK defines a few extras (https://developer.gnome.org/pygtk/stable/class-gdkatom.html), but only because it has computed the value at runtime (https://developer.gnome.org/gdk3/stable/gdk3-Properties-and-Atoms.html#gdk-atom-intern)

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type GdkAtom is a Ptr{Void}. It'll be clearest to define typealias GdkAtom Ptr{Void}, and use that to create these and for below.


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))

2 changes: 1 addition & 1 deletion src/gtktypes.jl
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions src/long_exports.jl
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ export GObject,
GtkTextMark,
GtkTextTag,
GtkTextView,
GtkClipboard,
GtkToolButton,
GtkToolItem,
GtkToolbar,
2 changes: 2 additions & 0 deletions src/long_leaf_exports.jl
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@ export
@GtkTextMark,
@GtkTextTag,
@GtkTextView,
@GtkClipboard,
@GtkToolButton,
@GtkToolItem,
@GtkToolbar,
@@ -134,6 +135,7 @@ export
GtkTextMarkLeaf,
GtkTextTagLeaf,
GtkTextViewLeaf,
GtkClipboardLeaf,
GtkToolButtonLeaf,
GtkToolItemLeaf,
GtkToolbarLeaf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make the corresponding updates to short_leaf_exports.jl and short_exports.jl

20 changes: 16 additions & 4 deletions src/text.jl
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/gui.jl
Original file line number Diff line number Diff line change
@@ -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)