Struct objc2_app_kit::NSPasteboard
source · #[repr(C)]pub struct NSPasteboard { /* private fields */ }
Available on crate feature
NSPasteboard
only.Implementations§
source§impl NSPasteboard
impl NSPasteboard
sourcepub unsafe fn generalPasteboard() -> Retained<NSPasteboard>
pub unsafe fn generalPasteboard() -> Retained<NSPasteboard>
Examples found in repository?
examples/nspasteboard.rs (line 53)
52 53 54 55 56 57 58 59 60 61 62 63 64
fn main() {
let pasteboard = unsafe { NSPasteboard::generalPasteboard() };
let impl_1 = get_text_1(&pasteboard);
let impl_2 = get_text_2(&pasteboard);
println!("Pasteboard text from implementation 1 was: {impl_1:?}");
println!("Pasteboard text from implementation 2 was: {impl_2:?}");
assert_eq!(impl_1, impl_2);
let s = NSString::from_str("Hello, world!");
set_text(&pasteboard, &s);
println!("Now the pasteboard text should be: {s:?}");
assert_eq!(Some(s), get_text_1(&pasteboard));
}
pub unsafe fn pasteboardWithName( name: &NSPasteboardName ) -> Retained<NSPasteboard>
pub unsafe fn pasteboardWithUniqueName() -> Retained<NSPasteboard>
pub unsafe fn name(&self) -> Retained<NSPasteboardName>
pub unsafe fn changeCount(&self) -> NSInteger
pub unsafe fn prepareForNewContentsWithOptions( &self, options: NSPasteboardContentsOptions ) -> NSInteger
sourcepub unsafe fn clearContents(&self) -> NSInteger
pub unsafe fn clearContents(&self) -> NSInteger
sourcepub unsafe fn writeObjects(
&self,
objects: &NSArray<ProtocolObject<dyn NSPasteboardWriting>>
) -> bool
pub unsafe fn writeObjects( &self, objects: &NSArray<ProtocolObject<dyn NSPasteboardWriting>> ) -> bool
sourcepub unsafe fn readObjectsForClasses_options(
&self,
class_array: &NSArray<TodoClass>,
options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>
) -> Option<Retained<NSArray>>
pub unsafe fn readObjectsForClasses_options( &self, class_array: &NSArray<TodoClass>, options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>> ) -> Option<Retained<NSArray>>
Examples found in repository?
examples/nspasteboard.rs (line 32)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
pub fn get_text_2(pasteboard: &NSPasteboard) -> Option<Retained<NSString>> {
// The NSPasteboard API is a bit weird, it requires you to pass classes as
// objects, which `objc2_foundation::NSArray` was not really made for - so
// we convert the class to an `AnyObject` type instead.
//
// TODO: Investigate and find a better way to express this in `objc2`.
let string_class = {
let cls: *const AnyClass = NSString::class();
let cls = cls as *mut AnyObject;
unsafe { Retained::retain(cls).unwrap() }
};
let class_array = NSArray::from_vec(vec![string_class]);
let objects = unsafe { pasteboard.readObjectsForClasses_options(&class_array, None) };
let obj: *const AnyObject = objects?.first()?;
// And this part is weird as well, since we now have to convert the object
// into an NSString, which we know it to be since that's what we told
// `readObjectsForClasses:options:`.
let obj = obj as *mut NSString;
Some(unsafe { Retained::retain(obj) }.unwrap())
}
pub unsafe fn pasteboardItems( &self ) -> Option<Retained<NSArray<NSPasteboardItem>>>
Available on crate feature
NSPasteboardItem
only.pub unsafe fn indexOfPasteboardItem( &self, pasteboard_item: &NSPasteboardItem ) -> NSUInteger
Available on crate feature
NSPasteboardItem
only.pub unsafe fn canReadItemWithDataConformingToTypes( &self, types: &NSArray<NSString> ) -> bool
pub unsafe fn canReadObjectForClasses_options( &self, class_array: &NSArray<TodoClass>, options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>> ) -> bool
pub unsafe fn declareTypes_owner( &self, new_types: &NSArray<NSPasteboardType>, new_owner: Option<&AnyObject> ) -> NSInteger
pub unsafe fn addTypes_owner( &self, new_types: &NSArray<NSPasteboardType>, new_owner: Option<&AnyObject> ) -> NSInteger
pub unsafe fn types(&self) -> Option<Retained<NSArray<NSPasteboardType>>>
pub unsafe fn availableTypeFromArray( &self, types: &NSArray<NSPasteboardType> ) -> Option<Retained<NSPasteboardType>>
pub unsafe fn setData_forType( &self, data: Option<&NSData>, data_type: &NSPasteboardType ) -> bool
pub unsafe fn setPropertyList_forType( &self, plist: &AnyObject, data_type: &NSPasteboardType ) -> bool
pub unsafe fn setString_forType( &self, string: &NSString, data_type: &NSPasteboardType ) -> bool
pub unsafe fn dataForType( &self, data_type: &NSPasteboardType ) -> Option<Retained<NSData>>
pub fn propertyListForType( &self, data_type: &NSPasteboardType ) -> Option<Retained<AnyObject>>
sourcepub unsafe fn stringForType(
&self,
data_type: &NSPasteboardType
) -> Option<Retained<NSString>>
pub unsafe fn stringForType( &self, data_type: &NSPasteboardType ) -> Option<Retained<NSString>>
source§impl NSPasteboard
impl NSPasteboard
Methods declared on superclass NSObject
source§impl NSPasteboard
impl NSPasteboard
FilterServices
pub unsafe fn typesFilterableTo( type: &NSPasteboardType ) -> Retained<NSArray<NSPasteboardType>>
pub unsafe fn pasteboardByFilteringFile( filename: &NSString ) -> Retained<NSPasteboard>
pub unsafe fn pasteboardByFilteringData_ofType( data: &NSData, type: &NSPasteboardType ) -> Retained<NSPasteboard>
pub unsafe fn pasteboardByFilteringTypesInPasteboard( pboard: &NSPasteboard ) -> Retained<NSPasteboard>
source§impl NSPasteboard
impl NSPasteboard
NSFileContents
pub unsafe fn writeFileContents(&self, filename: &NSString) -> bool
pub unsafe fn readFileContentsType_toFile( &self, type: Option<&NSPasteboardType>, filename: &NSString ) -> Option<Retained<NSString>>
pub unsafe fn writeFileWrapper(&self, wrapper: &NSFileWrapper) -> bool
pub unsafe fn readFileWrapper(&self) -> Option<Retained<NSFileWrapper>>
Methods from Deref<Target = NSObject>§
sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
sourcepub fn class(&self) -> &'static AnyClass
Available on crate feature NSAccessibilityConstants
only.
pub fn class(&self) -> &'static AnyClass
NSAccessibilityConstants
only.Dynamically find the class of this object.
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.Available on crate feature NSAccessibilityConstants
only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.NSAccessibilityConstants
only.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
sourcepub unsafe fn get_mut_ivar<T>(&mut self, name: &str) -> &mut Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load_mut
instead.Available on crate feature NSAccessibilityConstants
only.
pub unsafe fn get_mut_ivar<T>(&mut self, name: &str) -> &mut Twhere
T: Encode,
Ivar::load_mut
instead.NSAccessibilityConstants
only.Use Ivar::load_mut
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Trait Implementations§
source§impl AsMut<AnyObject> for NSPasteboard
impl AsMut<AnyObject> for NSPasteboard
source§impl AsMut<NSObject> for NSPasteboard
impl AsMut<NSObject> for NSPasteboard
source§impl AsMut<NSPasteboard> for NSPasteboard
impl AsMut<NSPasteboard> for NSPasteboard
source§impl AsRef<AnyObject> for NSPasteboard
impl AsRef<AnyObject> for NSPasteboard
source§impl AsRef<NSObject> for NSPasteboard
impl AsRef<NSObject> for NSPasteboard
source§impl AsRef<NSPasteboard> for NSPasteboard
impl AsRef<NSPasteboard> for NSPasteboard
source§impl Borrow<AnyObject> for NSPasteboard
impl Borrow<AnyObject> for NSPasteboard
source§impl Borrow<NSObject> for NSPasteboard
impl Borrow<NSObject> for NSPasteboard
source§impl BorrowMut<AnyObject> for NSPasteboard
impl BorrowMut<AnyObject> for NSPasteboard
source§fn borrow_mut(&mut self) -> &mut AnyObject
fn borrow_mut(&mut self) -> &mut AnyObject
Mutably borrows from an owned value. Read more
source§impl BorrowMut<NSObject> for NSPasteboard
impl BorrowMut<NSObject> for NSPasteboard
source§fn borrow_mut(&mut self) -> &mut NSObject
fn borrow_mut(&mut self) -> &mut NSObject
Mutably borrows from an owned value. Read more
source§impl ClassType for NSPasteboard
impl ClassType for NSPasteboard
§type Mutability = InteriorMutable
type Mutability = InteriorMutable
Whether the type is mutable or immutable. Read more
source§const NAME: &'static str = "NSPasteboard"
const NAME: &'static str = "NSPasteboard"
The name of the Objective-C class that this type represents. Read more
source§fn class() -> &'static AnyClass
fn class() -> &'static AnyClass
Get a reference to the Objective-C class that this type represents. Read more
source§fn as_super_mut(&mut self) -> &mut Self::Super
fn as_super_mut(&mut self) -> &mut Self::Super
Get a mutable reference to the superclass.
source§impl Debug for NSPasteboard
impl Debug for NSPasteboard
source§impl Deref for NSPasteboard
impl Deref for NSPasteboard
source§impl DerefMut for NSPasteboard
impl DerefMut for NSPasteboard
source§impl Hash for NSPasteboard
impl Hash for NSPasteboard
source§impl NSObjectProtocol for NSPasteboard
impl NSObjectProtocol for NSPasteboard
source§fn isEqual(&self, other: &AnyObject) -> bool
fn isEqual(&self, other: &AnyObject) -> bool
Check whether the object is equal to an arbitrary other object. Read more
source§fn hash(&self) -> usize
fn hash(&self) -> usize
An integer that can be used as a table address in a hash table
structure. Read more
source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Check if the object is an instance of the class, or one of its
subclasses. Read more
source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
Check if the object is an instance of the class type, or one of its
subclasses. Read more
source§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Check if the object is an instance of a specific class, without
checking subclasses. Read more
source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Check whether the object implements or inherits a method with the
given selector. Read more
source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Check whether the object conforms to a given protocol. Read more
source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
A textual representation of the object to use when debugging. Read more
source§impl PartialEq for NSPasteboard
impl PartialEq for NSPasteboard
source§fn eq(&self, other: &NSPasteboard) -> bool
fn eq(&self, other: &NSPasteboard) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl RefEncode for NSPasteboard
impl RefEncode for NSPasteboard
source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
The Objective-C type-encoding for a reference of this type. Read more
impl Eq for NSPasteboard
impl Message for NSPasteboard
impl StructuralPartialEq for NSPasteboard
Auto Trait Implementations§
impl !Freeze for NSPasteboard
impl !RefUnwindSafe for NSPasteboard
impl !Send for NSPasteboard
impl !Sync for NSPasteboard
impl !Unpin for NSPasteboard
impl !UnwindSafe for NSPasteboard
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CounterpartOrSelf for T
impl<T> CounterpartOrSelf for T
§type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
type Immutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Immutable
The immutable counterpart of the type, or
Self
if the type has no
immutable counterpart. Read more§type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
type Mutable = <<T as ClassType>::Mutability as MutabilityCounterpartOrSelf<T>>::Mutable
The mutable counterpart of the type, or
Self
if the type has no
mutable counterpart. Read more