Revision: 3085
http://skim-app.svn.sourceforge.net/skim-app/?rev=3085&view=rev
Author: hofman
Date: 2007-10-28 11:12:12 -0700 (Sun, 28 Oct 2007)
Log Message:
-----------
Use our own textfield to edit text notes in Leopard.
Modified Paths:
--------------
trunk/SKPDFView.h
trunk/SKPDFView.m
Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h 2007-10-28 15:56:09 UTC (rev 3084)
+++ trunk/SKPDFView.h 2007-10-28 18:12:12 UTC (rev 3085)
@@ -96,6 +96,7 @@
PDFAnnotation *activeAnnotation;
PDFAnnotation *highlightAnnotation;
PDFAnnotationTextWidget *editAnnotation;
+ NSTextField *editField;
PDFSelection *wasSelection;
NSRect wasBounds;
NSPoint wasStartPoint;
@@ -180,6 +181,7 @@
- (void)handleAnnotationWillChangeNotification:(NSNotification *)notification;
- (void)handleAnnotationDidChangeNotification:(NSNotification *)notification;
- (void)handlePageChangedNotification:(NSNotification *)notification;
+- (void)handleScaleChangedNotification:(NSNotification *)notification;
- (void)handleWindowWillCloseNotification:(NSNotification *)notification;
- (void)resetHoverRects;
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2007-10-28 15:56:09 UTC (rev 3084)
+++ trunk/SKPDFView.m 2007-10-28 18:12:12 UTC (rev 3085)
@@ -218,6 +218,9 @@
name:SKAnnotationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handlePageChangedNotification:)
name:PDFViewPageChangedNotification object:self];
+ if (floor(NSAppKitVersionNumber) > 824)
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleScaleChangedNotification:)
+
name:PDFViewScaleChangedNotification object:self];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
forKeys:
[NSArray arrayWithObjects:SKReadingBarColorKey, SKReadingBarInvertKey,
nil]];
}
@@ -535,7 +538,7 @@
}
- (BOOL)isEditing {
- return editAnnotation != nil;
+ return editAnnotation != nil || editField != nil;
}
- (NSRect)currentSelectionRect {
@@ -1903,17 +1906,40 @@
} else if ([type isEqualToString:SKFreeTextString]) {
NSRect editBounds = [activeAnnotation bounds];
- editAnnotation = [[[PDFAnnotationTextWidget alloc]
initWithBounds:editBounds] autorelease];
- [editAnnotation setStringValue:[activeAnnotation contents]];
- if ([activeAnnotation respondsToSelector:@selector(font)])
- [editAnnotation setFont:[(PDFAnnotationFreeText *)activeAnnotation
font]];
- [[activeAnnotation page] addAnnotation:editAnnotation];
- // Start editing
- NSPoint location = [self convertPoint:[self
convertPoint:SKCenterPoint(editBounds) fromPage:[activeAnnotation page]]
toView:nil];
- NSEvent *theEvent = [NSEvent mouseEventWithType:NSLeftMouseDown
location:location modifierFlags:0 timestamp:0 windowNumber:[[self window]
windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1.0];
- [super mouseDown:theEvent];
+ if (floor(NSAppKitVersionNumber) <= 824) {
+
+ editAnnotation = [[[PDFAnnotationTextWidget alloc]
initWithBounds:editBounds] autorelease];
+ [editAnnotation setStringValue:[activeAnnotation contents]];
+ if ([activeAnnotation respondsToSelector:@selector(font)])
+ [editAnnotation setFont:[(PDFAnnotationFreeText
*)activeAnnotation font]];
+ [[activeAnnotation page] addAnnotation:editAnnotation];
+
+ // Start editing
+ NSPoint location = [self convertPoint:[self
convertPoint:SKCenterPoint(editBounds) fromPage:[activeAnnotation page]]
toView:nil];
+ NSEvent *theEvent = [NSEvent mouseEventWithType:NSLeftMouseDown
location:location modifierFlags:0 timestamp:0 windowNumber:[[self window]
windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1.0];
+ [super mouseDown:theEvent];
+
+ } else {
+ NSColor *color = [activeAnnotation color];
+ float alpha = [color alphaComponent];
+ if (alpha < 1.0)
+ color = [[NSColor controlBackgroundColor]
blendedColorWithFraction:alpha ofColor:[color colorWithAlphaComponent:1.0]];
+ editBounds = [self convertRect:[self convertRect:editBounds
fromPage:[activeAnnotation page]] toView:[self documentView]];
+ editField = [[NSTextField alloc] initWithFrame:editBounds];
+ [editField setBezeled:YES];
+ [editField setBackgroundColor:color];
+ if ([activeAnnotation respondsToSelector:@selector(font)]) {
+ NSFont *font = [(PDFAnnotationFreeText *)activeAnnotation
font];
+ [editField setFont:[[NSFontManager sharedFontManager]
convertFont:font toSize:[font pointSize] * [self scaleFactor]]];
+ }
+ [editField setStringValue:[activeAnnotation contents]];
+ [editField setDelegate:self];
+ [[self documentView] addSubview:editField];
+ [editField selectText:self];
+
+ }
}
}
@@ -1927,6 +1953,15 @@
}
[[editAnnotation page] removeAnnotation:editAnnotation];
editAnnotation = nil;
+ } else if (editField) {
+ if ([[self window] firstResponder] == [editField currentEditor] &&
[[self window] makeFirstResponder:self] == NO)
+ [[self window] endEditingFor:nil];
+ if ([[editField stringValue] isEqualToString:[activeAnnotation
contents]] == NO) {
+ [activeAnnotation setContents:[editField stringValue]];
+ }
+ [editField removeFromSuperview];
+ [editField release];
+ editField = nil;
}
}
@@ -2129,8 +2164,36 @@
- (void)handlePageChangedNotification:(NSNotification *)notification {
if ([self toolMode] == SKSelectToolMode && NSIsEmptyRect(selectionRect) ==
NO)
[self setNeedsDisplay:YES];
+ if (editField) {
+ PDFDisplayMode displayMode = [self displayMode];
+ PDFPage *page = [activeAnnotation page];
+ PDFPage *currentPage = [self currentPage];
+ if ([page isEqual:currentPage] == NO && displayMode !=
kPDFDisplaySinglePageContinuous && displayMode != kPDFDisplayTwoUpContinuous) {
+ int currentPageIndex = [currentPage pageIndex];
+ int facingPageIndex = -1;
+ if (displayMode == kPDFDisplayTwoUp) {
+ if ([self displaysAsBook] == (BOOL)(currentPageIndex % 2))
+ facingPageIndex = currentPageIndex + 1;
+ else
+ facingPageIndex = currentPageIndex - 1;
+ }
+ if (facingPageIndex == -1 || facingPageIndex == (int)[[self
document] pageCount] || [page isEqual:[[self document]
pageAtIndex:facingPageIndex]] == NO)
+ [self endAnnotationEdit:self];
+ }
+ }
}
+- (void)handleScaleChangedNotification:(NSNotification *)notification {
+ if (editField) {
+ NSRect editBounds = [self convertRect:[self
convertRect:[activeAnnotation bounds] fromPage:[activeAnnotation page]]
toView:[self documentView]];
+ [editField setFrame:editBounds];
+ if ([activeAnnotation respondsToSelector:@selector(font)]) {
+ NSFont *font = [(PDFAnnotationFreeText *)activeAnnotation font];
+ [editField setFont:[[NSFontManager sharedFontManager]
convertFont:font toSize:[font pointSize] * [self scaleFactor]]];
+ }
+ }
+}
+
#pragma mark FullScreen navigation and autohide
- (void)handleWindowWillCloseNotification:(NSNotification *)notification {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit