Revision: 12745
          http://sourceforge.net/p/skim-app/code/12745
Author:   hofman
Date:     2022-01-25 10:06:11 +0000 (Tue, 25 Jan 2022)
Log Message:
-----------
Convenience property for indentation of outline column cell. This can also 
depend on whether the outline column is the first column. Apple made this a 
real mess.

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

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2022-01-24 16:03:57 UTC (rev 12744)
+++ trunk/SKMainWindowController_UI.m   2022-01-25 10:06:11 UTC (rev 12745)
@@ -119,10 +119,6 @@
 #define DEFAULT_TEXT_ROW_HEIGHT 85.0
 #define DEFAULT_MARKUP_ROW_HEIGHT 50.0
 
-static CGFloat outlineIndentation = 0.0;
-
-#define OUTLINE_INDENTATION (outlineIndentation > 0.0 ? outlineIndentation : 
RUNNING_AFTER(10_15) ? 9.0 : 16.0)
-
 @interface SKMainWindowController (SKPrivateMain)
 
 - (void)cleanup;
@@ -864,14 +860,8 @@
 }
 
 - (void)outlineView:(NSOutlineView *)ov 
didChangeHiddenOfTableColumn:(NSTableColumn *)tableColumn {
-    if (mwcFlags.autoResizeNoteRows && [ov 
isEqual:rightSideController.noteOutlineView]) {
-        if (outlineIndentation <= 0.0 && [ov numberOfRows] > 0) {
-            NSTableColumn *tc = [ov outlineTableColumn];
-            if ([tc isHidden] == NO)
-                outlineIndentation = [tc width] - NSWidth([ov 
frameOfCellAtColumn:[[ov tableColumns] indexOfObject:tc] row:0]);
-        }
+    if (mwcFlags.autoResizeNoteRows && [ov 
isEqual:rightSideController.noteOutlineView])
         [self performSelectorOnce:@selector(resetNoteRowHeights) 
afterDelay:0.0];
-    }
 }
 
 - (void)outlineViewColumnDidMove:(NSNotification *)notification {
@@ -909,10 +899,10 @@
                 if ([(PDFAnnotation *)item type] == nil) {
                     width = [(SKNoteOutlineView *)ov visibleColumnsWidth];
                     if ([(SKNoteOutlineView *)ov outlineColumnIsFirst])
-                        width -= OUTLINE_INDENTATION;
+                        width -= [(SKNoteOutlineView *)ov outlineIndentation];
                     width = fmax(10.0, width);
                 } else if ([tableColumn isHidden] == NO) {
-                    width = [tableColumn width] - OUTLINE_INDENTATION;
+                    width = [tableColumn width] - [(SKNoteOutlineView *)ov 
outlineIndentation];
                 }
                 if (width > 0.0)
                     rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, 
width, CGFLOAT_MAX)].height;
@@ -1222,14 +1212,6 @@
 }
 
 - (void)toggleAutoResizeNoteRows:(id)sender {
-    if (outlineIndentation <= 0.0 && mwcFlags.autoResizeNoteRows == 0) {
-        // calculate the difference between the cell width and the column 
width for the putline column
-        // which depends on the style and the OS version
-        NSOutlineView *ov = rightSideController.noteOutlineView;
-        NSTableColumn *tc = [ov outlineTableColumn];
-        if ([tc isHidden] == NO && [ov numberOfRows] > 0)
-            outlineIndentation = [tc width] - NSWidth([ov 
frameOfCellAtColumn:[[ov tableColumns] indexOfObject:tc] row:0]);
-    }
     mwcFlags.autoResizeNoteRows = (0 == mwcFlags.autoResizeNoteRows);
     if (mwcFlags.autoResizeNoteRows)
         [self resetNoteRowHeights];

Modified: trunk/SKNoteOutlineView.h
===================================================================
--- trunk/SKNoteOutlineView.h   2022-01-24 16:03:57 UTC (rev 12744)
+++ trunk/SKNoteOutlineView.h   2022-01-25 10:06:11 UTC (rev 12745)
@@ -50,6 +50,7 @@
 
 @property (nonatomic, readonly) BOOL outlineColumnIsFirst;
 @property (nonatomic, readonly) CGFloat visibleColumnsWidth;
+@property (nonatomic, readonly) CGFloat outlineIndentation;
 
 @end
 

Modified: trunk/SKNoteOutlineView.m
===================================================================
--- trunk/SKNoteOutlineView.m   2022-01-24 16:03:57 UTC (rev 12744)
+++ trunk/SKNoteOutlineView.m   2022-01-25 10:06:11 UTC (rev 12745)
@@ -61,7 +61,7 @@
 
 @implementation SKNoteOutlineView
 
-@dynamic outlineColumnIsFirst, visibleColumnsWidth;
+@dynamic outlineColumnIsFirst, visibleColumnsWidth, outlineIndentation;
 
 static inline NSString *titleForTableColumnIdentifier(NSString *identifier) {
     if ([identifier isEqualToString:NOTE_COLUMNID])
@@ -192,6 +192,20 @@
     return width;
 }
 
+- (CGFloat)outlineIndentation {
+    if ([self respondsToSelector:@selector(style)] == NO)
+        return 16.0;
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+    else if ([self style] == NSTableViewStylePlain)
+#pragma clang diagnostic pop
+        return 18.0;
+    else if ([self outlineColumnIsFirst])
+        return 9.0;
+    else
+        return 15.0 - floor(0.5 * [self intercellSpacing].width);
+}
+
 #pragma mark Delegate
 
 - (id <SKNoteOutlineViewDelegate>)delegate { return (id 
<SKNoteOutlineViewDelegate>)[super delegate]; }

Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m     2022-01-24 16:03:57 UTC (rev 12744)
+++ trunk/SKNotesDocument.m     2022-01-25 10:06:11 UTC (rev 12745)
@@ -98,10 +98,6 @@
 #define EXTRA_ROW_HEIGHT 2.0
 #define DEFAULT_TEXT_ROW_HEIGHT 85.0
 
-static CGFloat outlineIndentation = 0.0;
-
-#define OUTLINE_INDENTATION (outlineIndentation > 0.0 ? outlineIndentation : 
RUNNING_AFTER(10_15) ? 9.0 : 16.0)
-
 @implementation SKNotesDocument
 
 @synthesize outlineView, statusBar, arrayController, searchField, notes, 
pdfDocument, sourceFileURL;
@@ -598,11 +594,6 @@
 }
 
 - (void)toggleAutoResizeNoteRows:(id)sender {
-    if (outlineIndentation <= 0.0 && ndFlags.autoResizeRows == 0 && 
[outlineView numberOfRows] > 0) {
-        NSTableColumn *tc = [outlineView outlineTableColumn];
-        if ([tc isHidden] == NO)
-            outlineIndentation = [tc width] - NSWidth([outlineView 
frameOfCellAtColumn:[[outlineView tableColumns] indexOfObject:tc] row:0]);
-    }
     ndFlags.autoResizeRows = (0 == ndFlags.autoResizeRows);
     if (ndFlags.autoResizeRows)
         [self  resetRowHeights];
@@ -793,14 +784,8 @@
 }
 
 - (void)outlineView:(NSOutlineView *)ov 
didChangeHiddenOfTableColumn:(NSTableColumn *)tableColumn {
-    if (ndFlags.autoResizeRows) {
-        if (outlineIndentation <= 0.0 && [outlineView numberOfRows] > 0) {
-            NSTableColumn *tc = [outlineView outlineTableColumn];
-            if ([tc isHidden] == NO)
-                outlineIndentation = [tc width] - NSWidth([ov 
frameOfCellAtColumn:[[ov tableColumns] indexOfObject:tc] row:0]);
-        }
+    if (ndFlags.autoResizeRows)
         [self performSelectorOnce:@selector(resetRowHeights) afterDelay:0.0];
-    }
 }
 
 - (void)outlineView:(NSOutlineView *)ov copyItems:(NSArray *)items  {
@@ -852,10 +837,10 @@
             if ([(PDFAnnotation *)item type] == nil) {
                 width = [outlineView visibleColumnsWidth];
                 if ([outlineView outlineColumnIsFirst])
-                    width -= OUTLINE_INDENTATION;
+                    width -= [outlineView outlineIndentation];
                 width = fmax(10.0, width);
             } else if ([tableColumn isHidden] == NO) {
-                width = [tableColumn width] - OUTLINE_INDENTATION;
+                width = [tableColumn width] - [outlineView outlineIndentation];
             }
             if (width > 0.0)
                 rowHeight = [cell cellSizeForBounds:NSMakeRect(0.0, 0.0, 
width, CGFLOAT_MAX)].height;

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to