Sha256: 1a5ab8c222d790e8c01de2bdf4ffd44fe84feb90569b2710a34e01bc176ce135

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

class Wx::Clipboard
  class << self
    # This is provided internally by the SWIG interface file, but all
    # public access should be via Clipboard.open; see below
    private :get_global_clipboard

    # Class method to provide access to the clipboard within a ruby
    # block. Tests that the clipboard could be accessed, and ensures
    # that it is closed when the block is finished.
    def open
      clip = nil
      # Trying to access the segfault outside main_loop will segfault on
      # some platforms (eg, GTK)
      unless Wx::const_defined?(:THE_APP)
        raise RuntimeError, 
              "The clipboard can only be accessed when the App is running"
      end

      clip = get_global_clipboard
      unless clip.open
        Kernel.raise "Could not open clipboard"
      end
      yield clip
     ensure
       clip.close if clip
    end
  end

  # Need to do some internal record-keeping to protect data objects on
  # the clipboard from garbage collection
  @@__clip_data = []

  # These methods affect the clipboard contents; each time, update the
  # record with the changed data contents
  wx_add_data = instance_method(:add_data)
  define_method(:add_data) do | the_data |
    @@__clip_data << the_data
    wx_add_data.bind(self).call(the_data)
  end

  wx_clear = instance_method(:clear)
  define_method(:clear) do 
    wx_clear.bind(self).call
    @@__clip_data.clear
  end

  wx_set_data = instance_method(:set_data)
  define_method(:set_data) do | the_data |
    @@__clip_data = [ the_data ]
    wx_set_data.bind(self).call(the_data)
  end

  # Aliases, more clearly expressive?
  alias :place :set_data
  alias :fetch :get_data
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wxruby3-0.9.0.pre.rc.3-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.rc.2-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.rc.1-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.14-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.13-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.11-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.10-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.9-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.8-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.2-x64-mingw-ucrt-3.2-3.2.2 lib/wx/core/clipboard.rb
wxruby3-0.9.0.pre.beta.1-x64-mingw-ucrt-3.2 lib/wx/core/clipboard.rb