1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
607 (*env)->PopLocalFrame(env, NULL);
608
609 return result;
610 }
611
612 // --- Services menu support for lightweights ---
613
614 // finds the focused accessible element, and if it is a text element, obtains the text from it
615 - (NSString *)accessibleSelectedText
616 {
617 id focused = [self accessibilityFocusedUIElement];
618 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;
619 return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];
620 }
621
622 // same as above, but converts to RTFD
623 - (NSData *)accessibleSelectedTextAsRTFD
624 {
625 NSString *selectedText = [self accessibleSelectedText];
626 NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
627 NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length]) documentAttributes:nil];
628 [styledText release];
629 return rtfdData;
630 }
631
632 // finds the focused accessible element, and if it is a text element, sets the text in it
633 - (BOOL)replaceAccessibleTextSelection:(NSString *)text
634 {
635 id focused = [self accessibilityFocusedUIElement];
636 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;
637 [(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];
638 return YES;
639 }
640
641 // called for each service in the Services menu - only handle text for now
642 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
643 {
644 if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
645
646 if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
647 NSString *selectedText = [self accessibleSelectedText];
664 {
665 [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
666 return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
667 }
668
669 return NO;
670 }
671
672 // write text back to Java from the service
673 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
674 {
675 if ([[pboard types] containsObject:NSStringPboardType])
676 {
677 NSString *text = [pboard stringForType:NSStringPboardType];
678 return [self replaceAccessibleTextSelection:text];
679 }
680
681 if ([[pboard types] containsObject:NSRTFDPboardType])
682 {
683 NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
684 NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:nil];
685 NSString *text = [styledText string];
686 [styledText release];
687
688 return [self replaceAccessibleTextSelection:text];
689 }
690
691 return NO;
692 }
693
694
695 -(void) setDragSource:(CDragSource *)source {
696 self._dragSource = source;
697 }
698
699
700 - (void) setDropTarget:(CDropTarget *)target {
701 self._dropTarget = target;
702 [ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];
703 }
704
|
1 /*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
607 (*env)->PopLocalFrame(env, NULL);
608
609 return result;
610 }
611
612 // --- Services menu support for lightweights ---
613
614 // finds the focused accessible element, and if it is a text element, obtains the text from it
615 - (NSString *)accessibleSelectedText
616 {
617 id focused = [self accessibilityFocusedUIElement];
618 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return nil;
619 return [(JavaTextAccessibility *)focused accessibilitySelectedTextAttribute];
620 }
621
622 // same as above, but converts to RTFD
623 - (NSData *)accessibleSelectedTextAsRTFD
624 {
625 NSString *selectedText = [self accessibleSelectedText];
626 NSAttributedString *styledText = [[NSAttributedString alloc] initWithString:selectedText];
627 NSData *rtfdData = [styledText RTFDFromRange:NSMakeRange(0, [styledText length])
628 documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}];
629 [styledText release];
630 return rtfdData;
631 }
632
633 // finds the focused accessible element, and if it is a text element, sets the text in it
634 - (BOOL)replaceAccessibleTextSelection:(NSString *)text
635 {
636 id focused = [self accessibilityFocusedUIElement];
637 if (![focused isKindOfClass:[JavaTextAccessibility class]]) return NO;
638 [(JavaTextAccessibility *)focused accessibilitySetSelectedTextAttribute:text];
639 return YES;
640 }
641
642 // called for each service in the Services menu - only handle text for now
643 - (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType
644 {
645 if ([[self window] firstResponder] != self) return nil; // let AWT components handle themselves
646
647 if ([sendType isEqual:NSStringPboardType] || [returnType isEqual:NSStringPboardType]) {
648 NSString *selectedText = [self accessibleSelectedText];
665 {
666 [pboard declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] owner:nil];
667 return [pboard setData:[self accessibleSelectedTextAsRTFD] forType:NSRTFDPboardType];
668 }
669
670 return NO;
671 }
672
673 // write text back to Java from the service
674 - (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
675 {
676 if ([[pboard types] containsObject:NSStringPboardType])
677 {
678 NSString *text = [pboard stringForType:NSStringPboardType];
679 return [self replaceAccessibleTextSelection:text];
680 }
681
682 if ([[pboard types] containsObject:NSRTFDPboardType])
683 {
684 NSData *rtfdData = [pboard dataForType:NSRTFDPboardType];
685 NSAttributedString *styledText = [[NSAttributedString alloc] initWithRTFD:rtfdData documentAttributes:NULL];
686 NSString *text = [styledText string];
687 [styledText release];
688
689 return [self replaceAccessibleTextSelection:text];
690 }
691
692 return NO;
693 }
694
695
696 -(void) setDragSource:(CDragSource *)source {
697 self._dragSource = source;
698 }
699
700
701 - (void) setDropTarget:(CDropTarget *)target {
702 self._dropTarget = target;
703 [ThreadUtilities performOnMainThread:@selector(controlModelControlValid) on:self._dropTarget withObject:nil waitUntilDone:YES];
704 }
705
|