Commits

Anonymous committed 4402b76

code clean up
added subclass scroll view for scrolling

Comments (0)

Files changed (8)

English.lproj/MyPDFDocWin.xib

 					<string>100092.IBPluginDependency</string>
 					<string>100093.IBPluginDependency</string>
 					<string>100094.IBPluginDependency</string>
+					<string>100131.CustomClassName</string>
 					<string>100131.IBPluginDependency</string>
 					<string>100132.IBPluginDependency</string>
 					<string>100133.IBPluginDependency</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+					<string>TronScrollView</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 					<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">100140</int>
+			<int key="maxID">100144</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
 						<string key="minorKey">TronPDFView.h</string>
 					</object>
 				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">TronScrollView</string>
+					<string key="superclassName">NSScrollView</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBProjectSource</string>
+						<string key="minorKey">TronScrollView.h</string>
+					</object>
+				</object>
+				<object class="IBPartialClassDescription">
+					<string key="className">TronScrollView</string>
+					<string key="superclassName">NSScrollView</string>
+					<object class="IBClassDescriptionSource" key="sourceIdentifier">
+						<string key="majorKey">IBUserSource</string>
+						<string key="minorKey"/>
+					</object>
+				</object>
 			</object>
 			<object class="NSMutableArray" key="referencedPartialClassDescriptionsV3.2+">
 				<bool key="EncodedWithXMLCoder">YES</bool>

MyPDFWinController.h

 #import "MyPDFDoc.h"
 
 #import "TronPDFView.h"
+#import "TronScrollView.h"
 
 @interface MyPDFWinController : NSWindowController {
-    IBOutlet NSScrollView * _pdfScrollView;
+    IBOutlet TronScrollView * _pdfScrollView;
     IBOutlet TronPDFView * _tronPDFView;
     
     // go to page panel
 
 - (void)windowResized:(NSNotification *)notification;
 
+- (void)OnScroll:(CGFloat)deltaX deltaY:(CGFloat)deltaY;
+
+#pragma mark c callbacks 
+void beginRendering(void* data);
+void endRendering(void* data, bool canceled);
+void currPageProc(void* data);
+void cp_1_pixel(const char * src, char * dst, int i, int j, int width, int height);
 
 @end
-
-void beginRendering(void* data);
-
-void endRendering(void* data, bool canceled);
-
-void cp_1_pixel(const char * src, char * dst, int i, int j, int width, int height);
 
 #import "TronPDFView.h"
 
+@implementation TronPDFView
+
+#pragma mark callback functions
 void beginRendering(void* data) {
-    // NSLog(@"%@", "begin rendering");
+    NSLog(@"begin rendering");
     //printf("begin rendering");
 }
 
 void endRendering(void* data, bool canceled) {
-    //printf("end rendering");
+    NSLog(@"end rendering");
+    if (!canceled) {
+        NSLog(@"endRendering: setNeedDisplay:YES");
+        [(TronPDFView*)data setNeedsDisplay:YES];
+    }
+}
+
+void currPageProc(void* data) {
+    
 }
 
 /**
     dst[dst_idx + 3] = src[src_idx + 3];
 }
 
-@implementation TronPDFView
+#pragma mark objc code 
 
 @synthesize tronPDFView = _tronPDFView;
 
 - (void)awakeFromNib {
     [super awakeFromNib];
     _tronPDFView = new pdftron::PDF::PDFView();
-    /*
-    NSRect bound = [self bounds];
-    double width = (double) bound.size.width;
-    double height = (double) bound.size.height;
-    _tronPDFView->OnSize(width, height);
-     */
 }
 
 #pragma mark draw view
 }
 
 - (void)drawRect:(NSRect)dirtyRect {
-    /*
-    [[NSColor redColor] set];
-    NSRectFill([self bounds]);
-     */
-
+    
     if (_tronPDFView->GetDoc()) {
-        /*
-        double width = _tronPDFView->GetCanvasWidth();
-        double height = _tronPDFView->GetCanvasHeight();
-        
-        [self setFrame:NSMakeRect(0, 0, width, height)];
-        [self setBounds:NSMakeRect(0, 0, width, height)];
-        */
-        
-        //_tronPDFView->OnSize((int) svFrame.size.width, (int) svFrame.size.height);
-
-        
         const char* bgra = _tronPDFView->GetBuffer();
         if (bgra) {
             int width = _tronPDFView->GetBufferWidth();
             int height = _tronPDFView->GetBufferHeight();
             char * rgba = (char *) malloc(width * height * 4);
-            /*
-            for (int i = 0; i < width * height; ++i) {
-                rgba[4*i] = bgra[4*i + 2];
-                rgba[4*i + 1] = bgra[4*i + 1];
-                rgba[4*i + 2] = bgra[4*i];
-                rgba[4*i + 3] = bgra[4*i + 3];
-            }*/
             
             for (int i = 0; i < height; ++i) {
                 for (int j = 0; j < width; ++j) {
                                                                colorSpace,
                                                                kCGImageAlphaPremultipliedLast);
             
-            
             CFRelease(colorSpace);
             
             CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
             
-            __strong NSGraphicsContext	*	nsGraphicsContext	= [NSGraphicsContext currentContext];
-            __strong CGContextRef			zCgContextRef		= (CGContextRef) [nsGraphicsContext graphicsPort];
-            
+            __strong NSGraphicsContext * nsGraphicsContext = [NSGraphicsContext currentContext];
+            __strong CGContextRef zCgContextRef = (CGContextRef) [nsGraphicsContext graphicsPort];            
             
             NSRect imageRect;
             imageRect.origin = NSZeroPoint;
             free(rgba);
         }
     }
-
 }
 
 
 - (void)setDocument:(MyPDFDoc*) myDoc {
     if (_tronPDFView) {
         _tronPDFView->SetDoc(*(myDoc.tronPDFDoc));
-        _tronPDFView->SetRenderBeginProc(beginRendering, NULL);
-        _tronPDFView->SetRenderFinishProc(endRendering, NULL);
+        _tronPDFView->SetRenderBeginProc(beginRendering, self);
+        _tronPDFView->SetRenderFinishProc(endRendering, self);
         _tronPDFView->SetPageSpacing(10, 10, 20, 10);
         [self windowResized:nil];
-      /*
-        double w = _tronPDFView->GetCanvasWidth();
-        double h = _tronPDFView->GetCanvasHeight();
-        NSLog(@"setFrame width: %d, height: %d", w, h);
-        [self setFrame:NSMakeRect(0.0, 0.0, w, h)];
-       */
     }
 }
 
 - (void)viewDidMoveToWindow
 {
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]];
+    [[NSNotificationCenter defaultCenter] addObserver:self 
+                                             selector:@selector(windowResized:) 
+                                                 name:NSWindowDidResizeNotification 
+                                               object:[self window]];
 }
 
 - (void)windowResized:(NSNotification *)notification;
 {
-    NSSize win_size = [[self window] frame].size;
-    
-    NSLog(@"window width = %f, window height = %f", win_size.width, win_size.height);
-    
-    NSSize size = [self bounds].size;
-    
-    NSRect svFrame = [[self superview] frame];
-    NSRect svBound = [[self superview] bounds];
-    NSRect rect = [self bounds];
-    NSPoint p = rect.origin;
-    NSSize s = rect.size;
-    NSLog(@"self bound: w: %0.4f, h: %0.4f", s.width, s.height);
-    NSLog(@"self frame: w: %0.4f, h: %0.4f", [self frame].size.width, [self frame].size.height);
-    NSLog(@"super frame: x: w: %0.4f, h: %0.4f", svFrame.size.width, svFrame.size.height);
-    NSLog(@"super bound: x: w: %0.4f, h: %0.4f", svBound.size.width, svBound.size.height);
-    
-    
     if (_tronPDFView)
     {
-        _tronPDFView->OnSize((int) svBound.size.width, (int) svBound.size.height);
+        NSSize size = [[self superview] bounds].size;
+        _tronPDFView->OnSize((int) size.width, (int) size.height);
     
         double w = _tronPDFView->GetCanvasWidth();
         double h = _tronPDFView->GetCanvasHeight();
-        NSLog(@"setFrame width: %d, height: %d", w, h);
-        NSLog(@"setFrame width: %0.4f, height: %0.4f", w, h);
         [self setFrame:NSMakeRect(0.0, 0.0, w, h)];
-        NSLog(@"result frame: w: %d, h: %d", [self frame].size.width, [self frame].size.height);
-        NSLog(@"result frame: w: %0.4f, h: %0.4f", [self frame].size.width, [self frame].size.height);        
     }
 }
 
     NSLog(@"keyUp");
 }
 
+- (void)OnScroll:(CGFloat)deltaX deltaY:(CGFloat)deltaY {
+    if (_tronPDFView && _tronPDFView->GetDoc()) {
+        double hPos = _tronPDFView->GetHScrollPos();
+        double vPos = _tronPDFView->GetVScrollPos();
+        //_tronPDFView->OnScroll(hPos + deltaX, vPos + deltaY);
+    }
+}
+
 @end
+//
+//  TronScrollView.h
+//
+//  Created by Quincy on 10-08-07.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface TronScrollView : NSScrollView {
+
+}
+
+@end

TronScrollView.mm

+//
+//  TronScrollView.m
+//
+//  Created by Quincy on 10-08-07.
+//  Copyright 2010 __MyCompanyName__. All rights reserved.
+//
+
+#import "TronScrollView.h"
+#import "TronPDFView.h"
+
+@implementation TronScrollView
+
+-(void)scrollWheel:(NSEvent *)theEvent {
+    NSLog(@"scrollWheel");
+    [super scrollWheel:theEvent];
+    TronPDFView * pdfView = [self documentView];
+    
+    CGFloat deltaX = [theEvent deltaX];
+    CGFloat deltaY = [theEvent deltaY];
+    CGFloat deltaZ = [theEvent deltaZ];
+    
+    NSLog(@"deltaX: %0.4f, deltaY: %0.4f");
+    
+    [pdfView OnScroll:deltaX deltaY:deltaY];
+}
+
+@end

cocoapdf.xcodeproj/project.pbxproj

 		247B636611F6C30C000D0151 /* setup.sh in Resources */ = {isa = PBXBuildFile; fileRef = 247B5CC411F6C309000D0151 /* setup.sh */; };
 		247B636711F6C30C000D0151 /* whatsnew.html in Resources */ = {isa = PBXBuildFile; fileRef = 247B5CC511F6C309000D0151 /* whatsnew.html */; };
 		249250AB11CB3EA30076F523 /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 249250AA11CB3EA30076F523 /* Quartz.framework */; };
+		24A9C8C4120D6CAC00A86D24 /* TronScrollView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 24A9C8C3120D6CAC00A86D24 /* TronScrollView.mm */; };
 		5B02B6C011E517E80022BB1A /* MainMenuController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B02B6BF11E517E80022BB1A /* MainMenuController.mm */; };
 		5B02B6E511E5215A0022BB1A /* MyPDFWinController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5B02B6E411E5215A0022BB1A /* MyPDFWinController.mm */; };
 		8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; };
 		247B5CC411F6C309000D0151 /* setup.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = setup.sh; sourceTree = "<group>"; };
 		247B5CC511F6C309000D0151 /* whatsnew.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = whatsnew.html; sourceTree = "<group>"; };
 		249250AA11CB3EA30076F523 /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
+		24A9C8C2120D6CAC00A86D24 /* TronScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TronScrollView.h; sourceTree = "<group>"; };
+		24A9C8C3120D6CAC00A86D24 /* TronScrollView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TronScrollView.mm; sourceTree = "<group>"; };
 		2564AD2C0F5327BB00F57823 /* cocoapdf_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoapdf_Prefix.pch; sourceTree = "<group>"; };
 		2A37F4ACFDCFA73011CA2CEA /* MyPDFDoc.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MyPDFDoc.mm; sourceTree = "<group>"; };
 		2A37F4AEFDCFA73011CA2CEA /* MyPDFDoc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MyPDFDoc.h; sourceTree = "<group>"; };
 		2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
 			isa = PBXGroup;
 			children = (
+				24A9C8C2120D6CAC00A86D24 /* TronScrollView.h */,
+				24A9C8C3120D6CAC00A86D24 /* TronScrollView.mm */,
 				5B02B6BE11E517E80022BB1A /* MainMenuController.h */,
 				5B02B6BF11E517E80022BB1A /* MainMenuController.mm */,
 				2A37F4AEFDCFA73011CA2CEA /* MyPDFDoc.h */,
 				5B02B6C011E517E80022BB1A /* MainMenuController.mm in Sources */,
 				5B02B6E511E5215A0022BB1A /* MyPDFWinController.mm in Sources */,
 				2475874111FD068E00F243C8 /* TronPDFView.mm in Sources */,
+				24A9C8C4120D6CAC00A86D24 /* TronScrollView.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

cocoapdf.xcodeproj/quincy.mode1v3

 			<key>Content</key>
 			<dict>
 				<key>PBXProjectModuleGUID</key>
-				<string>24E4BEA112079F7600CA10EA</string>
+				<string>247157EF120E1B4E00711708</string>
 				<key>PBXProjectModuleLabel</key>
 				<string>TronPDFView.mm</string>
 				<key>PBXSplitModuleInNavigatorKey</key>
 					<key>Split0</key>
 					<dict>
 						<key>PBXProjectModuleGUID</key>
-						<string>24E4BEA91207A02F00CA10EA</string>
+						<string>247157FD120E1CCB00711708</string>
 						<key>PBXProjectModuleLabel</key>
 						<string>TronPDFView.mm</string>
 						<key>_historyCapacity</key>
 						<integer>0</integer>
 						<key>bookmark</key>
-						<string>24A9C8BA120D688D00A86D24</string>
+						<string>24715811120E1DBD00711708</string>
 						<key>history</key>
 						<array>
-							<string>247266D51207A845001BF4F9</string>
-							<string>24A9C708120D0D4600A86D24</string>
-							<string>24A9C709120D0D4600A86D24</string>
-							<string>24A9C78B120D343400A86D24</string>
-							<string>24A9C803120D529100A86D24</string>
-							<string>24A9C805120D529100A86D24</string>
-							<string>24A9C85D120D595200A86D24</string>
-							<string>24A9C868120D5B1A00A86D24</string>
-							<string>24A9C8AF120D65F100A86D24</string>
-							<string>24A9C8B0120D65F100A86D24</string>
+							<string>247157FE120E1CCB00711708</string>
+							<string>247157FF120E1CCB00711708</string>
+							<string>24715801120E1CCB00711708</string>
 						</array>
 					</dict>
 					<key>SplitCount</key>
 			<key>Geometry</key>
 			<dict>
 				<key>Frame</key>
-				<string>{{0, 20}, {808, 502}}</string>
+				<string>{{0, 20}, {1003, 601}}</string>
 				<key>PBXModuleWindowStatusBarHidden2</key>
 				<false/>
 				<key>RubberWindowFrame</key>
-				<string>253 196 808 543 0 0 1280 778 </string>
+				<string>227 121 1003 642 0 0 1280 778 </string>
 			</dict>
 		</dict>
 	</array>
 							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
 							<array>
 								<array>
-									<integer>10</integer>
+									<integer>12</integer>
 									<integer>2</integer>
 									<integer>0</integer>
 								</array>
 										<key>_historyCapacity</key>
 										<integer>0</integer>
 										<key>bookmark</key>
-										<string>24A9C8B9120D688D00A86D24</string>
+										<string>24715810120E1DBD00711708</string>
 										<key>history</key>
 										<array>
 											<string>241D2A8211FBCBED0067260B</string>
 											<string>246738851206E1F400157160</string>
 											<string>24E4BEA71207A02F00CA10EA</string>
 											<string>24E4BECC1207A25400CA10EA</string>
-											<string>24A9C75D120D2D0A00A86D24</string>
+											<string>247157F8120E1CCB00711708</string>
+											<string>247157F9120E1CCB00711708</string>
 										</array>
 									</dict>
 									<key>SplitCount</key>
 							<key>GeometryConfiguration</key>
 							<dict>
 								<key>Frame</key>
-								<string>{{0, 0}, {414, 165}}</string>
+								<string>{{0, 0}, {414, 152}}</string>
 								<key>RubberWindowFrame</key>
 								<string>190 177 788 504 0 0 1280 778 </string>
 							</dict>
 							<key>Module</key>
 							<string>PBXNavigatorGroup</string>
 							<key>Proportion</key>
-							<string>165pt</string>
+							<string>152pt</string>
 						</dict>
 						<dict>
 							<key>ContentConfiguration</key>
 							<key>GeometryConfiguration</key>
 							<dict>
 								<key>Frame</key>
-								<string>{{0, 170}, {414, 293}}</string>
+								<string>{{0, 157}, {414, 306}}</string>
 								<key>RubberWindowFrame</key>
 								<string>190 177 788 504 0 0 1280 778 </string>
 							</dict>
 							<key>Module</key>
 							<string>XCDetailModule</string>
 							<key>Proportion</key>
-							<string>293pt</string>
+							<string>306pt</string>
 						</dict>
 					</array>
 					<key>Proportion</key>
 			</array>
 			<key>TableOfContents</key>
 			<array>
-				<string>24A9C6FF120D0B5F00A86D24</string>
+				<string>247157FB120E1CCB00711708</string>
 				<string>1CE0B1FE06471DED0097A5F4</string>
-				<string>24A9C700120D0B5F00A86D24</string>
+				<string>247157FC120E1CCB00711708</string>
 				<string>1CE0B20306471E060097A5F4</string>
 				<string>1CE0B20506471E060097A5F4</string>
 			</array>
 	<key>PerspectivesBarVisible</key>
 	<false/>
 	<key>PinnedNavigatorIdentifier</key>
-	<string>24E4BEA112079F7600CA10EA</string>
+	<string>247157EF120E1B4E00711708</string>
 	<key>ShelfIsVisible</key>
 	<false/>
 	<key>SourceDescription</key>
 	<integer>5</integer>
 	<key>WindowOrderList</key>
 	<array>
-		<string>24A9C8BB120D688D00A86D24</string>
-		<string>24A9C71A120D0E1200A86D24</string>
-		<string>24A9C71B120D0E1200A86D24</string>
+		<string>24715813120E1DBD00711708</string>
+		<string>24715814120E1DBD00711708</string>
+		<string>24715815120E1DBD00711708</string>
+		<string>1C78EAAD065D492600B07095</string>
+		<string>1CD10A99069EF8BA00B06720</string>
 		<string>/Users/quincy/Repositories/CocoaPDF/cocoapdf.xcodeproj</string>
 		<string>2492503F11CB2A5D0076F523</string>
-		<string>24E4BEA112079F7600CA10EA</string>
-		<string>1CD10A99069EF8BA00B06720</string>
-		<string>1C78EAAD065D492600B07095</string>
+		<string>247157EF120E1B4E00711708</string>
 	</array>
 	<key>WindowString</key>
 	<string>190 177 788 504 0 0 1280 778 </string>
 			<key>TableOfContents</key>
 			<array>
 				<string>2492503F11CB2A5D0076F523</string>
-				<string>24A9C702120D0B5F00A86D24</string>
+				<string>24715803120E1CCB00711708</string>
 				<string>1CD0528F0623707200166675</string>
 				<string>XCMainBuildResultsModuleGUID</string>
 			</array>
 			<key>TableOfContents</key>
 			<array>
 				<string>1CD10A99069EF8BA00B06720</string>
-				<string>24A9C712120D0E1200A86D24</string>
+				<string>24715804120E1CCB00711708</string>
 				<string>1C162984064C10D400B95A72</string>
-				<string>24A9C713120D0E1200A86D24</string>
-				<string>24A9C714120D0E1200A86D24</string>
-				<string>24A9C715120D0E1200A86D24</string>
-				<string>24A9C716120D0E1200A86D24</string>
-				<string>24A9C717120D0E1200A86D24</string>
+				<string>24715805120E1CCB00711708</string>
+				<string>24715806120E1CCB00711708</string>
+				<string>24715807120E1CCB00711708</string>
+				<string>24715808120E1CCB00711708</string>
+				<string>24715809120E1CCB00711708</string>
 			</array>
 			<key>ToolbarConfiguration</key>
 			<string>xcode.toolbar.config.debugV3</string>
 					<key>Dock</key>
 					<array>
 						<dict>
-							<key>BecomeActive</key>
-							<true/>
 							<key>ContentConfiguration</key>
 							<dict>
 								<key>PBXProjectModuleGUID</key>
 			<key>TableOfContents</key>
 			<array>
 				<string>1C78EAAD065D492600B07095</string>
-				<string>24A9C718120D0E1200A86D24</string>
+				<string>24715812120E1DBD00711708</string>
 				<string>1C78EAAC065D492600B07095</string>
 			</array>
 			<key>ToolbarConfiguration</key>
 			<key>WindowToolGUID</key>
 			<string>1C78EAAD065D492600B07095</string>
 			<key>WindowToolIsVisible</key>
-			<true/>
+			<false/>
 		</dict>
 		<dict>
 			<key>Identifier</key>