Revision: 7847
http://skim-app.svn.sourceforge.net/skim-app/?rev=7847&view=rev
Author: hofman
Date: 2012-12-11 18:02:28 +0000 (Tue, 11 Dec 2012)
Log Message:
-----------
Use controller object for text note edit field, so we control where the
delegate method is implemented
Modified Paths:
--------------
trunk/SKPDFView.h
trunk/SKPDFView.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SKTextNoteEditor.h
trunk/SKTextNoteEditor.m
Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h 2012-12-10 20:09:32 UTC (rev 7846)
+++ trunk/SKPDFView.h 2012-12-11 18:02:28 UTC (rev 7847)
@@ -81,9 +81,9 @@
};
typedef NSInteger SKNoteType;
-@class SKReadingBar, SKTransitionController, SKTypeSelectHelper,
SKNavigationWindow;
+@class SKReadingBar, SKTransitionController, SKTypeSelectHelper,
SKNavigationWindow, SKTextNoteEditor;
-@interface SKPDFView : PDFView <NSTextFieldDelegate> {
+@interface SKPDFView : PDFView {
SKToolMode toolMode;
SKNoteType annotationMode;
SKInteractionMode interactionMode;
@@ -103,7 +103,7 @@
PDFAnnotation *activeAnnotation;
PDFAnnotation *highlightAnnotation;
- NSTextField *editField;
+ SKTextNoteEditor *editor;
NSRect selectionRect;
NSUInteger selectionPageIndex;
NSPoint syncPoint;
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2012-12-10 20:09:32 UTC (rev 7846)
+++ trunk/SKPDFView.m 2012-12-11 18:02:28 UTC (rev 7847)
@@ -72,6 +72,7 @@
#import "NSGeometry_SKExtensions.h"
#import "NSGraphics_SKExtensions.h"
#import "NSArray_SKExtensions.h"
+#import "SKTextNoteEditor.h"
#define SKEscapeCharacter 0x001b
@@ -370,7 +371,7 @@
[NSGraphicsContext restoreGraphicsState];
}
- if ([[activeAnnotation page] isEqual:pdfPage] && editField == nil)
+ if ([[activeAnnotation page] isEqual:pdfPage] && [self isEditing] == NO)
[activeAnnotation drawSelectionHighlightWithScaleFactor:[self
scaleFactor]];
if ([[highlightAnnotation page] isEqual:pdfPage]) {
@@ -546,7 +547,7 @@
}
- (BOOL)isEditing {
- return editField != nil;
+ return editor != nil;
}
- (void)setDisplayMode:(PDFDisplayMode)mode {
@@ -1991,23 +1992,9 @@
} else if (hideNotes == NO && [type isEqualToString:SKNFreeTextString]) {
- NSRect editBounds = [activeAnnotation bounds];
- NSFont *font = [(PDFAnnotationFreeText *)activeAnnotation font];
- NSColor *color = [activeAnnotation color];
- NSColor *fontColor = [(PDFAnnotationFreeText *)activeAnnotation
fontColor];
- CGFloat alpha = [color alphaComponent];
- if (alpha < 1.0)
- color = [[NSColor controlBackgroundColor]
blendedColorWithFraction:alpha ofColor:[color colorWithAlphaComponent:1.0]];
- editBounds = [self convertRect:editBounds
toDocumentViewFromPage:[activeAnnotation page]];
- editField = [[NSTextField alloc] initWithFrame:editBounds];
- [editField setBackgroundColor:color];
- [editField setTextColor:fontColor];
- [editField setFont:[[NSFontManager sharedFontManager] convertFont:font
toSize:[font pointSize] * [self scaleFactor]]];
- [editField setAlignment:[(PDFAnnotationFreeText *)activeAnnotation
alignment]];
- [editField setStringValue:[activeAnnotation string]];
- [editField setDelegate:self];
- [[self documentView] addSubview:editField];
- [editField selectText:self];
+ editor = [[SKTextNoteEditor alloc] initWithPDFView:self
annotation:(PDFAnnotationFreeText *)activeAnnotation];
+ [[self documentView] addSubview:[editor textField]];
+ [[editor textField] selectText:nil];
[self setNeedsDisplayForAnnotation:activeAnnotation];
@@ -2026,11 +2013,10 @@
}
- (void)discardEditing {
- if (editField) {
- [editField abortEditing];
- [editField removeFromSuperview];
- [editField release];
- editField = nil;
+ if ([self isEditing]) {
+ [[editor textField] abortEditing];
+ [[editor textField] removeFromSuperview];
+ SKDESTROY(editor);
if ([[activeAnnotation type] isEqualToString:SKNFreeTextString])
[self setNeedsDisplayForAnnotation:activeAnnotation];
@@ -2041,14 +2027,14 @@
}
- (BOOL)commitEditing {
- if (editField) {
- if ([[self window] firstResponder] == [editField currentEditor] &&
[[self window] makeFirstResponder:self] == NO)
+ if ([self isEditing]) {
+ if ([[editor textField] currentEditor] && [[self window]
makeFirstResponder:self] == NO)
return NO;
- if ([[editField stringValue] isEqualToString:[activeAnnotation
string]] == NO)
- [activeAnnotation setString:[editField stringValue]];
- [editField removeFromSuperview];
- [editField release];
- editField = nil;
+ NSString *newValue = [[editor textField] stringValue];
+ if ([newValue isEqualToString:[activeAnnotation string]] == NO)
+ [activeAnnotation setString:newValue];
+ [[editor textField] removeFromSuperview];
+ SKDESTROY(editor);
if ([[activeAnnotation type] isEqualToString:SKNFreeTextString])
[self setNeedsDisplayForAnnotation:activeAnnotation];
@@ -2059,19 +2045,6 @@
return YES;
}
-- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)command {
- BOOL rv = NO;
- if ([control isEqual:editField]) {
- if (command == @selector(insertNewline:) || command ==
@selector(insertTab:) || command == @selector(insertBacktab:)) {
- [self commitEditing];
- [[self window] makeFirstResponder:self];
- rv = YES;
- }
- }
- // PDFView does not implement this method since 10.5, as it uses a
separate controller object
- return rv;
-}
-
- (void)selectNextActiveAnnotation:(id)sender {
PDFDocument *pdfDoc = [self document];
NSInteger numberOfPages = [pdfDoc pageCount];
@@ -2275,7 +2248,7 @@
accessibilityChildren = [children mutableCopy];
}
if ([self isEditing])
- return [accessibilityChildren arrayByAddingObject:editField];
+ return [accessibilityChildren arrayByAddingObject:[editor textField]];
else
return accessibilityChildren;
}
@@ -2283,8 +2256,8 @@
- (id)accessibilityChildAtPoint:(NSPoint)point {
NSPoint localPoint = [self convertPoint:[[self window]
convertScreenToBase:point] fromView:nil];
id child = nil;
- if ([self isEditing] && NSMouseInRect([self convertPoint:localPoint
toView:[self documentView]], [editField frame], [[self documentView]
isFlipped])) {
- child = NSAccessibilityUnignoredDescendant(editField);
+ if ([self isEditing] && NSMouseInRect([self convertPoint:localPoint
toView:[self documentView]], [[editor textField] frame], [[self documentView]
isFlipped])) {
+ child = NSAccessibilityUnignoredDescendant([editor textField]);
} else {
PDFPage *page = [self pageForPoint:localPoint nearest:NO];
if (page) {
@@ -2301,7 +2274,7 @@
- (id)accessibilityFocusedChild {
id child = nil;
if ([self isEditing])
- child = NSAccessibilityUnignoredDescendant(editField);
+ child = NSAccessibilityUnignoredDescendant([editor textField]);
else if (activeAnnotation)
child =
NSAccessibilityUnignoredAncestor([SKAccessibilityProxyFauxUIElement
elementWithObject:activeAnnotation parent:[self documentView]]);
//else
@@ -2364,12 +2337,8 @@
- (void)handleScaleChangedNotification:(NSNotification *)notification {
[self resetPDFToolTipRects];
if ([self isEditing]) {
- NSRect editBounds = [self convertRect:[activeAnnotation bounds]
toDocumentViewFromPage:[activeAnnotation page]];
- [editField setFrame:editBounds];
- if ([activeAnnotation respondsToSelector:@selector(font)]) {
- NSFont *font = [(PDFAnnotationFreeText *)activeAnnotation font];
- [editField setFont:[[NSFontManager sharedFontManager]
convertFont:font toSize:[font pointSize] * [self scaleFactor]]];
- }
+ [editor updateFrame];
+ [editor updateFont];
}
}
@@ -3218,7 +3187,7 @@
// Get mouse in "page space".
pagePoint = [self convertPoint:mouseDownOnPage toPage:page];
- if ([activeAnnotation page] == page && editField == nil &&
[activeAnnotation isResizable] && [activeAnnotation
resizeHandleForPoint:pagePoint scaleFactor:[self scaleFactor]] != 0) {
+ if ([activeAnnotation page] == page && [self isEditing] == NO &&
[activeAnnotation isResizable] && [activeAnnotation
resizeHandleForPoint:pagePoint scaleFactor:[self scaleFactor]] != 0) {
mouseDownInAnnotation = YES;
newActiveAnnotation = activeAnnotation;
} else {
@@ -3233,7 +3202,7 @@
// Hit test annotation.
if ([annotation isSkimNote]) {
- if ([annotation hitTest:pagePoint] && (editField == nil ||
annotation != activeAnnotation)) {
+ if ([annotation hitTest:pagePoint] && ([self isEditing] == NO
|| annotation != activeAnnotation)) {
mouseDownInAnnotation = YES;
newActiveAnnotation = annotation;
break;
@@ -3405,7 +3374,7 @@
while (i-- > 0) {
PDFAnnotation *annotation = [annotations objectAtIndex:i];
- if ([annotation isSkimNote] && [annotation hitTest:pagePoint] &&
(editField == nil || annotation != activeAnnotation)) {
+ if ([annotation isSkimNote] && [annotation hitTest:pagePoint] &&
([self isEditing] == NO || annotation != activeAnnotation)) {
[self removeAnnotation:annotation];
[[self documentUndoManager]
setActionName:NSLocalizedString(@"Remove Note", @"Undo action name")];
break;
@@ -4227,7 +4196,7 @@
}
- (void)relayoutEditField {
- if (editField) {
+ if ([self isEditing]) {
PDFDisplayMode displayMode = [self displayMode];
PDFPage *page = [activeAnnotation page];
PDFPage *currentPage = [self currentPage];
@@ -4247,16 +4216,15 @@
}
}
if (isVisible) {
- NSRect editBounds = [self convertRect:[activeAnnotation bounds]
toDocumentViewFromPage:[activeAnnotation page]];
- [editField setFrame:editBounds];
- if ([editField superview] == nil) {
- [[self documentView] addSubview:editField];
+ [editor updateFrame];
+ if ([[editor textField] superview] == nil) {
+ [[self documentView] addSubview:[editor textField]];
if ([[[self window] firstResponder] isEqual:self])
- [editField selectText:self];
+ [[editor textField] selectText:nil];
}
- } else if ([editField superview]) {
- BOOL wasFirstResponder = [[[self window] firstResponder]
isEqual:[editField currentEditor]];
- [editField removeFromSuperview];
+ } else if ([[editor textField] superview]) {
+ BOOL wasFirstResponder = ([[editor textField] currentEditor] !=
nil);
+ [[editor textField] removeFromSuperview];
if (wasFirstResponder)
[[self window] makeFirstResponder:self];
}
Added: trunk/SKTextNoteEditor.h
===================================================================
--- trunk/SKTextNoteEditor.h (rev 0)
+++ trunk/SKTextNoteEditor.h 2012-12-11 18:02:28 UTC (rev 7847)
@@ -0,0 +1,56 @@
+//
+// SKTextNoteEditor.h
+// Skim
+//
+// Created by Christiaan Hofman on 12/11/12.
+/*
+ This software is Copyright (c) 2012
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Quartz/Quartz.h>
+
+
+@interface SKTextNoteEditor : NSObject <NSTextFieldDelegate> {
+ NSTextField *textField;
+ PDFView *pdfView;
+ PDFAnnotationFreeText *annotation;
+}
+
+@property (nonatomic, readonly) NSTextField *textField;
+
+- (id)initWithPDFView:(PDFView *)aPDFView annotation:(PDFAnnotationFreeText
*)anAnnotation;
+
+- (void)updateFont;
+- (void)updateFrame;
+
+@end
Added: trunk/SKTextNoteEditor.m
===================================================================
--- trunk/SKTextNoteEditor.m (rev 0)
+++ trunk/SKTextNoteEditor.m 2012-12-11 18:02:28 UTC (rev 7847)
@@ -0,0 +1,97 @@
+//
+// SKTextNoteEditor.m
+// Skim
+//
+// Created by Christiaan Hofman on 12/11/12.
+/*
+ This software is Copyright (c) 2012
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SKTextNoteEditor.h"
+#import "PDFView_SKExtensions.h"
+#import <SkimNotes/SkimNotes.h>
+
+
+@implementation SKTextNoteEditor
+
+@synthesize textField;
+
+- (id)initWithPDFView:(PDFView *)aPDFView annotation:(PDFAnnotationFreeText
*)anAnnotation {
+ self = [super init];
+ if (self) {
+ pdfView = aPDFView;
+ annotation = [anAnnotation retain];
+ NSColor *color = [annotation color];
+ NSColor *fontColor = [annotation fontColor];
+ CGFloat alpha = [color alphaComponent];
+ if (alpha < 1.0)
+ color = [[NSColor controlBackgroundColor]
blendedColorWithFraction:alpha ofColor:[color colorWithAlphaComponent:1.0]];
+ textField = [[NSTextField alloc] init];
+ [textField setBackgroundColor:color];
+ [textField setTextColor:fontColor];
+ [textField setAlignment:[annotation alignment]];
+ [textField setStringValue:[annotation string]];
+ [textField setDelegate:self];
+ [self updateFont];
+ [self updateFrame];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ pdfView = nil;
+ SKDESTROY(annotation);
+ SKDESTROY(textField);
+ [super dealloc];
+}
+
+- (void)updateFont {
+ NSFont *font = [annotation font];
+ font = [[NSFontManager sharedFontManager] convertFont:font toSize:[font
pointSize] * [pdfView scaleFactor]];
+ [textField setFont:font];
+}
+
+- (void)updateFrame {
+ NSRect frame = [pdfView convertRect:[annotation bounds]
toDocumentViewFromPage:[annotation page]];
+ [textField setFrame:frame];
+}
+
+- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)command {
+ if (command == @selector(insertNewline:) || command ==
@selector(insertTab:) || command == @selector(insertBacktab:)) {
+ [pdfView commitEditing];
+ [[pdfView window] makeFirstResponder:pdfView];
+ return YES;
+ }
+ return NO;
+}
+
+@end
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2012-12-10 20:09:32 UTC (rev
7846)
+++ trunk/Skim.xcodeproj/project.pbxproj 2012-12-11 18:02:28 UTC (rev
7847)
@@ -129,6 +129,7 @@
CE3A3D2C0B78C0A0006B64D3 /* SKNPDFAnnotationNote_SKExtensions.m
in Sources */ = {isa = PBXBuildFile; fileRef = CE3A3D2B0B78C0A0006B64D3 /*
SKNPDFAnnotationNote_SKExtensions.m */; };
CE3A41580B790C56006B64D3 /* SKDragImageView.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE3A41570B790C56006B64D3 /* SKDragImageView.m
*/; };
CE3A45530B7A04A4006B64D3 /* NSBezierPath_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE3A45520B7A04A4006B64D3 /*
NSBezierPath_SKExtensions.m */; };
+ CE40D6161677A9DC00573882 /* SKTextNoteEditor.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE40D6151677A9DC00573882 /* SKTextNoteEditor.m
*/; };
CE41A6CC0B975E5000ECF819 /* Skim.sdef in Resources */ = {isa =
PBXBuildFile; fileRef = CE41A6CB0B975E5000ECF819 /* Skim.sdef */; };
CE41B2A70C08CFA900E36EB7 /* NSArray_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE41B2A50C08CFA900E36EB7 /*
NSArray_SKExtensions.m */; };
CE41B2CC0C08D17100E36EB7 /* NSValue_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE41B2CA0C08D17100E36EB7 /*
NSValue_SKExtensions.m */; };
@@ -756,6 +757,8 @@
CE3A41570B790C56006B64D3 /* SKDragImageView.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKDragImageView.m; sourceTree = "<group>"; };
CE3A45510B7A04A4006B64D3 /* NSBezierPath_SKExtensions.h */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = NSBezierPath_SKExtensions.h; sourceTree = "<group>"; };
CE3A45520B7A04A4006B64D3 /* NSBezierPath_SKExtensions.m */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.objc; path = NSBezierPath_SKExtensions.m; sourceTree = "<group>";
};
+ CE40D6141677A9DC00573882 /* SKTextNoteEditor.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKTextNoteEditor.h; sourceTree = "<group>"; };
+ CE40D6151677A9DC00573882 /* SKTextNoteEditor.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKTextNoteEditor.m; sourceTree = "<group>"; };
CE41A6CB0B975E5000ECF819 /* Skim.sdef */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = text.sdef; path =
Skim.sdef; sourceTree = "<group>"; };
CE41B2A40C08CFA900E36EB7 /* NSArray_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
NSArray_SKExtensions.h; sourceTree = "<group>"; };
CE41B2A50C08CFA900E36EB7 /* NSArray_SKExtensions.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= NSArray_SKExtensions.m; sourceTree = "<group>"; };
@@ -1617,6 +1620,8 @@
CE1248C413FEDCF200FFAE20 /* SKTemplateManager.m
*/,
CE109798161320CF00C4FA18 /*
SKExportAccessoryController.h */,
CE109799161320CF00C4FA18 /*
SKExportAccessoryController.m */,
+ CE40D6141677A9DC00573882 /* SKTextNoteEditor.h
*/,
+ CE40D6151677A9DC00573882 /* SKTextNoteEditor.m
*/,
);
name = Controllers;
sourceTree = "<group>";
@@ -2581,6 +2586,7 @@
CE10979A161320CF00C4FA18 /*
SKExportAccessoryController.m in Sources */,
CE5347141645DD3000737191 /*
SKAttachmentEmailer.m in Sources */,
CE1B651B16595C5200B74339 /* SKWatchedPath.m in
Sources */,
+ CE40D6161677A9DC00573882 /* SKTextNoteEditor.m
in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit