Revision: 14843
          http://sourceforge.net/p/skim-app/code/14843
Author:   hofman
Date:     2024-12-18 17:43:52 +0000 (Wed, 18 Dec 2024)
Log Message:
-----------
cache row heights in note outline view ivar

Modified Paths:
--------------
    trunk/SKMainWindowController.h
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_UI.m
    trunk/SKNoteOutlineView.h
    trunk/SKNoteOutlineView.m
    trunk/SKNotesDocument.h
    trunk/SKNotesDocument.m

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKMainWindowController.h      2024-12-18 17:43:52 UTC (rev 14843)
@@ -115,7 +115,6 @@
     
     SKNoteTypeSheetController           *noteTypeSheetController;
     NSMutableArray<PDFAnnotation *>     *notes;
-    NSMapTable                          *rowHeights;
     
     NSMutableArray<PDFAnnotation *>     *widgets;
     NSMapTable<PDFAnnotation *, id>     *widgetValues;

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKMainWindowController.m      2024-12-18 17:43:52 UTC (rev 14843)
@@ -240,8 +240,7 @@
         snapshots = [[NSMutableArray alloc] init];
         pageLabels = [[NSArray alloc] init];
         lastViewedPages = [[NSPointerArray alloc] 
initWithOptions:NSPointerFunctionsOpaqueMemory | 
NSPointerFunctionsIntegerPersonality];
-        rowHeights = [[NSMapTable alloc] 
initWithKeyOptions:NSPointerFunctionsStrongMemory | 
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsOpaqueMemory 
| NSPointerFunctionsIntegerPersonality capacity:0];
-
+        
         savedNormalSetup = [[NSMutableDictionary alloc] init];
         mwcFlags.leftSidePaneState = SKSidePaneStateThumbnail;
         mwcFlags.rightSidePaneState = SKSidePaneStateNote;
@@ -1337,8 +1336,8 @@
     [[self windowControllerForNote:note] close];
     
     if ([note hasNoteText])
-        NSMapRemove(rowHeights, (__bridge void *)[note noteText]);
-    NSMapRemove(rowHeights, (__bridge void *)note);
+        [rightSideController.noteOutlineView removeRowHeightForItem:[note 
noteText]];
+    [rightSideController.noteOutlineView removeRowHeightForItem:note];
     
     // Stop observing the removed notes
     [self stopObservingNotes:@[note]];
@@ -1354,7 +1353,7 @@
                 [wc close];
         }
         
-        [rowHeights removeAllObjects];
+        [rightSideController.noteOutlineView resetRowHeights];
         
         [self stopObservingNotes:notes];
 
@@ -2709,9 +2708,9 @@
             
             if (mwcFlags.autoResizeNoteRows) {
                 if ([keyPath isEqualToString:SKNPDFAnnotationStringKey])
-                    NSMapRemove(rowHeights, (__bridge void *)note);
+                    [rightSideController.noteOutlineView 
removeRowHeightForItem:note];
                 else if ([keyPath isEqualToString:SKNPDFAnnotationTextKey])
-                    NSMapRemove(rowHeights, (__bridge void *)[note noteText]);
+                    [rightSideController.noteOutlineView 
removeRowHeightForItem:[note noteText]];
             }
             if ([self notesNeedReloadForKey:keyPath]) {
                 [self performSelectorOnce:@selector(reloadNotesTable) 
afterDelay:0.0];

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKMainWindowController_UI.m   2024-12-18 17:43:52 UTC (rev 14843)
@@ -840,7 +840,7 @@
 }
 
 - (void)resetNoteRowHeights {
-    [rowHeights removeAllObjects];
+    [rightSideController.noteOutlineView resetRowHeights];
     [rightSideController.noteOutlineView noteHeightOfRowsChangedAnimating:YES];
 }
 
@@ -866,7 +866,7 @@
 
 - (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item {
     if ([ov isEqual:rightSideController.noteOutlineView]) {
-        CGFloat rowHeight = (NSInteger)NSMapGet(rowHeights, (__bridge void 
*)item);
+        CGFloat rowHeight = [rightSideController.noteOutlineView 
rowHeightForItem:item];
         if (rowHeight <= 0.0) {
             if (mwcFlags.autoResizeNoteRows) {
                 NSTableColumn *tableColumn = [ov outlineTableColumn];
@@ -881,7 +881,7 @@
                 if (width > 0.0)
                     rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, 
width, CGFLOAT_MAX)].height;
                 rowHeight = round(fmax(rowHeight, [ov rowHeight]) + 
EXTRA_ROW_HEIGHT);
-                NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)rowHeight);
+                [rightSideController.noteOutlineView setRowHeight:rowHeight 
forItem:item];
             } else {
                 rowHeight = [(PDFAnnotation *)item type] ? [ov rowHeight] + 
EXTRA_ROW_HEIGHT : ([[(SKNoteText *)item note] isNote] ? 
DEFAULT_TEXT_ROW_HEIGHT : DEFAULT_MARKUP_ROW_HEIGHT);
             }
@@ -891,10 +891,6 @@
     return [ov rowHeight];
 }
 
-- (void)outlineView:(NSOutlineView *)ov setHeight:(CGFloat)newHeight 
ofRowByItem:(id)item {
-    NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)round(newHeight));
-}
-
 - (NSArray *)noteItems:(NSArray *)items {
     NSMutableArray *noteItems = [NSMutableArray array];
     
@@ -1174,7 +1170,7 @@
             height = [cell cellSizeForBounds:rect].height;
         else
             height = 0.0;
-        NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)round(fmax(height, rowHeight) + EXTRA_ROW_HEIGHT));
+        [rightSideController.noteOutlineView setRowHeight:round(fmax(height, 
rowHeight) + EXTRA_ROW_HEIGHT) forItem:item];
         if (rowIndexes) {
             row = [ov rowForItem:item];
             if (row != -1)
@@ -1192,7 +1188,7 @@
         SKNoteOutlineView *ov = rightSideController.noteOutlineView;
         NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
         for (id item in items) {
-            NSMapRemove(rowHeights, (__bridge void *)item);
+            [rightSideController.noteOutlineView removeRowHeightForItem:item];
             NSInteger row = [ov rowForItem:item];
             if (row != -1)
                 [indexes addIndex:row];
@@ -2084,7 +2080,7 @@
 
 - (void)handleNoteViewFrameDidChangeNotification:(NSNotification 
*)notification {
     if (mwcFlags.autoResizeNoteRows && [splitView isAnimating] == NO) {
-        [rowHeights removeAllObjects];
+        [rightSideController.noteOutlineView resetRowHeights];
         [rightSideController.noteOutlineView 
noteHeightOfRowsChangedAnimating:NO];
     }
 }

Modified: trunk/SKNoteOutlineView.h
===================================================================
--- trunk/SKNoteOutlineView.h   2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKNoteOutlineView.h   2024-12-18 17:43:52 UTC (rev 14843)
@@ -44,12 +44,13 @@
 @protocol SKNoteOutlineViewDelegate <SKOutlineViewDelegate>
 @optional
 
-- (void)outlineView:(NSOutlineView *)anOutlineView 
setHeight:(CGFloat)newHeight ofRowByItem:(id)item;
 - (void)outlineView:(NSOutlineView *)anOutlineView 
didChangeHiddenOfTableColumn:(NSTableColumn *)aTableColumn;
 
 @end
 
-@interface SKNoteOutlineView : SKOutlineView
+@interface SKNoteOutlineView : SKOutlineView {
+    NSMapTable *rowHeights;
+}
 
 - (void)toggleTableColumn:(nullable id)sender;
 
@@ -58,6 +59,11 @@
 @property (nonatomic, readonly) CGFloat fullWidthCellWidth;
 @property (nonatomic, readonly) CGFloat outlineIndentation;
 
+- (CGFloat)rowHeightForItem:(id)item;
+- (void)setRowHeight:(CGFloat)rowHeight forItem:(id)item;
+- (void)removeRowHeightForItem:(id)item;
+- (void)resetRowHeights;
+
 @end
 
 NS_ASSUME_NONNULL_END

Modified: trunk/SKNoteOutlineView.m
===================================================================
--- trunk/SKNoteOutlineView.m   2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKNoteOutlineView.m   2024-12-18 17:43:52 UTC (rev 14843)
@@ -97,12 +97,30 @@
         }
         
         [[self headerView] setMenu:menu];
+        
+        rowHeights = [[NSMapTable alloc] 
initWithKeyOptions:NSPointerFunctionsStrongMemory | 
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsOpaqueMemory 
| NSPointerFunctionsIntegerPersonality capacity:0];
     }
     return self;
 }
 
+- (CGFloat)rowHeightForItem:(id)item {
+    return (NSInteger)NSMapGet(rowHeights, (__bridge void *)item);
+}
+
+- (void)setRowHeight:(CGFloat)rowHeight forItem:(id)item {
+    NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)rowHeight);
+}
+
+- (void)removeRowHeightForItem:(id)item {
+    NSMapRemove(rowHeights, (__bridge void *)item);
+}
+
+- (void)resetRowHeights {
+    [rowHeights removeAllObjects];
+}
+
 - (void)mouseDown:(NSEvent *)theEvent {
-    if ([theEvent clickCount] == 1 && [[self delegate] 
respondsToSelector:@selector(outlineView:heightOfRowByItem:)] && [[self 
delegate] respondsToSelector:@selector(outlineView:setHeight:ofRowByItem:)]) {
+    if ([theEvent clickCount] == 1 && [[self delegate] 
respondsToSelector:@selector(outlineView:heightOfRowByItem:)]) {
         NSPoint mouseLoc = [theEvent locationInView:self];
         NSInteger row = [self rowAtPoint:mouseLoc];
         id item = row != -1 ? [self itemAtRow:row] : nil;
@@ -110,7 +128,7 @@
         if (item) {
             NSRect rect = SKSliceRect([self rectOfRow:row], 
RESIZE_EDGE_HEIGHT, [self isFlipped] ? NSMaxYEdge : NSMinYEdge);
             if (NSMouseInRect(mouseLoc, rect, [self isFlipped]) && [NSApp 
willDragMouse]) {
-                CGFloat startHeight = [[self delegate] outlineView:self 
heightOfRowByItem:item];
+                CGFloat startHeight = [self rowHeightForItem:item] ?: 
NSHeight([self rectOfRow:row]) - [self intercellSpacing].height;
                 
                 [[NSCursor resizeUpDownCursor] push];
                 
@@ -118,7 +136,7 @@
                     theEvent = [[self window] nextEventMatchingMask: 
NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged];
                     if ([theEvent type] == NSEventTypeLeftMouseDragged) {
                         CGFloat currentHeight = fmax([self rowHeight], 
round(startHeight + [theEvent locationInView:self].y - mouseLoc.y));
-                        [[self delegate] outlineView:self 
setHeight:currentHeight ofRowByItem:item];
+                        [self setRowHeight:currentHeight forItem:item];
                         [self noteHeightOfRowChanged:row animating:NO];
                     }
                 }

Modified: trunk/SKNotesDocument.h
===================================================================
--- trunk/SKNotesDocument.h     2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKNotesDocument.h     2024-12-18 17:43:52 UTC (rev 14843)
@@ -56,7 +56,6 @@
     NSArray<NSDictionary<NSString *, id> *> *unsupportedNotes;
     PDFDocument *pdfDocument;
     NSURL *sourceFileURL;
-    NSMapTable *rowHeights;
     SKNoteTypeSheetController *noteTypeSheetController;
     NSRect windowRect;
     struct _ndFlags {

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2024-12-18 16:45:52 UTC (rev 14842)
+++ trunk/SKNotesDocument.m     2024-12-18 17:43:52 UTC (rev 14843)
@@ -119,7 +119,6 @@
     if (self) {
         notes = [[NSArray alloc] init];
         pdfDocument = nil;
-        rowHeights = [[NSMapTable alloc] 
initWithKeyOptions:NSPointerFunctionsStrongMemory | 
NSPointerFunctionsObjectPersonality valueOptions:NSPointerFunctionsOpaqueMemory 
| NSPointerFunctionsIntegerPersonality capacity:0];
         windowRect = NSZeroRect;
         memset(&ndFlags, 0, sizeof(ndFlags));
         ndFlags.caseInsensitiveSearch = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKCaseInsensitiveNoteSearchKey];
@@ -201,7 +200,7 @@
 
 - (void)windowDidResize:(NSNotification *)notification {
     if (ndFlags.autoResizeRows) {
-        [rowHeights removeAllObjects];
+        [outlineView resetRowHeights];
         [outlineView noteHeightOfRowsChangedAnimating:NO];
     }
 }
@@ -367,7 +366,7 @@
         }
         [self didChangeValueForKey:PAGES_KEY];
         
-        [rowHeights removeAllObjects];
+        [outlineView resetRowHeights];
         
         [self willChangeValueForKey:NOTES_KEY];
         notes = [newNotes copy];
@@ -566,7 +565,7 @@
             height = [cell cellSizeForBounds:fullRect].height;
         else
             height = 0.0;
-        NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)round(fmax(height, rowHeight) + EXTRA_ROW_HEIGHT));
+        [outlineView setRowHeight:round(fmax(height, rowHeight) + 
EXTRA_ROW_HEIGHT) forItem:item];
         if (rowIndexes) {
             row = [outlineView rowForItem:item];
             if (row != -1)
@@ -577,7 +576,7 @@
 }
 
 - (void)resetRowHeights {
-    [rowHeights removeAllObjects];
+    [outlineView resetRowHeights];
     [outlineView noteHeightOfRowsChangedAnimating:YES];
 }
 
@@ -588,7 +587,7 @@
     } else {
         NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
         for (id item in items) {
-            NSMapRemove(rowHeights, (__bridge void *)item);
+            [outlineView removeRowHeightForItem:item];
             NSInteger row = [outlineView rowForItem:item];
             if (row != -1)
                 [indexes addIndex:row];
@@ -792,7 +791,7 @@
 }
 
 - (CGFloat)outlineView:(NSOutlineView *)ov heightOfRowByItem:(id)item {
-    CGFloat rowHeight = (NSInteger)NSMapGet(rowHeights, (__bridge void *)item);
+    CGFloat rowHeight = [outlineView rowHeightForItem:item];
     if (rowHeight <= 0.0) {
         if (ndFlags.autoResizeRows) {
             NSTableColumn *tableColumn = [ov outlineTableColumn];
@@ -806,7 +805,7 @@
             if (width > 0.0)
                 rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, 
width, CGFLOAT_MAX)].height;
             rowHeight = round(fmax(rowHeight, [ov rowHeight]) + 
EXTRA_ROW_HEIGHT);
-            NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)rowHeight);
+            [outlineView setRowHeight:rowHeight forItem:item];
         } else {
             rowHeight = [(PDFAnnotation *)item type] ? [ov rowHeight] + 
EXTRA_ROW_HEIGHT : DEFAULT_TEXT_ROW_HEIGHT;
         }
@@ -814,10 +813,6 @@
     return rowHeight;
 }
 
-- (void)outlineView:(NSOutlineView *)ov setHeight:(CGFloat)newHeight 
ofRowByItem:(id)item {
-    NSMapInsert(rowHeights, (__bridge void *)item, (void 
*)(NSInteger)round(newHeight));
-}
-
 - (NSArray *)outlineViewTypeSelectHelperSelectionStrings:(NSOutlineView *)ov {
     NSInteger i, count = [outlineView numberOfRows];
     NSMutableArray *texts = [NSMutableArray arrayWithCapacity:count];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to