Sha256: bd096c20e4934f8e6e9cd7064ce296f18d247ed6ee2ee025ea2052517c3895f9

Contents?: true

Size: 1.9 KB

Versions: 7

Compression:

Stored size: 1.9 KB

Contents

# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# 
# Some parts are
# Copyright 2004-2007, wxRuby development team
# released under the MIT-like wxRuby2 license

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

7 entries across 7 versions & 1 rubygems

Version Path
wxruby3-0.9.7-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.5-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.4-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.3-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.2-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.1-x64-mingw-ucrt lib/wx/core/clipboard.rb
wxruby3-0.9.0-x64-mingw-ucrt lib/wx/core/clipboard.rb