changeset 26:b8a8e3c5b6c6

Added Subtly::Gtk::Clipboard
author unexist
date Fri, 22 Jan 2010 14:38:33 +0100
parents 1a28b62792cf
children bb259a0825a1 a666afdaa9c9
files subtly/gtk.rb
diffstat 1 files changed, 85 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/subtly/gtk.rb	Fri Jan 22 14:38:19 2010 +0100
+++ b/subtly/gtk.rb	Fri Jan 22 14:38:33 2010 +0100
@@ -581,7 +581,7 @@
       ##
 
       attach_function(:ffi_add,
-        :gtk_box_pack_start, [:pointer, :pointer, :bool, :bool, :int], :void
+        :gtk_box_pack_start, [ :pointer, :pointer, :bool, :bool, :int ], :void
       )      
     end # }}}
 
@@ -873,5 +873,89 @@
         :gtk_entry_new, [ ], :pointer
       )
     end # }}}
+
+    class Clipboard # {{{
+
+      extend FFI::Library
+
+      ffi_lib("libgtk-x11-2.0")
+
+      ## self.text=
+      # Set content of clipboard
+      #
+      # @param [String, #read]  str  A string
+      ##
+
+      def self.text=(str)
+        clip = Subtly::Gtk::Clipboard.ffi_get_cliboard(
+          Subtly::Gdk::Selections[:primary]
+        )
+
+        Subtly::Gtk::Clipboard.ffi_set_text(clip, str, str.size)
+        Subtly::Gtk::Clipboard.ffi_store(clip)
+      end
+
+      ## self.text
+      # Get content of clipboard
+      #
+      # @return [String]  A string
+      ##
+
+      def self.text
+        clip = Subtly::Gtk::Clipboard.ffi_get_cliboard(
+          Subtly::Gdk::Selections[:primary]
+        )
+
+        Subtly::Gtk::Clipboard.ffi_get_text(clip)
+      end
+
+      private
+
+      ## ffi_get_cliboard
+      # Get the clipboard object for given selection
+      #
+      # @param  [Fixnum, #read]  selection  Clipboard identifier
+      #
+      # @return [Pointer]  Clipboard for selection
+      ##
+
+      attach_function(:ffi_get_cliboard,
+        :gtk_clipboard_get, [ :int ], :pointer
+      )
+
+      ## ffi_set_text
+      # Set content of clipboard
+      #
+      # @param [Pointer, #read]  clipboard  A #GtlClipboard
+      # @param [String,  #read]  text       A UTF-8 string
+      # @param [Fixnum,  #read]  len        Length of text
+      ##
+
+      attach_function(:ffi_set_text,
+        :gtk_clipboard_set_text, [ :pointer, :string, :int ], :void
+      )
+
+      ## ffi_get_text
+      # Get content of clipboard
+      #
+      # @param [Pointer, #read]  clipboard  A #GtlClipboard
+      #
+      # @return [String]  A UTF-8 string
+      ##
+
+      attach_function(:ffi_get_text,
+        :gtk_clipboard_wait_for_text, [ :pointer ], :string
+      )
+
+      ## ffi_store
+      # Store the current clipboard
+      #
+      # @param [Pointer, #read]  clipboard  A #GtlClipboard
+      ##
+
+      attach_function(:ffi_store,
+        :gtk_clipboard_store, [ :pointer ], :void
+      )
+    end # }}}
   end
 end