Revision: 2918
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2918&view=rev
Author:   hofman
Date:     2007-09-13 09:43:33 -0700 (Thu, 13 Sep 2007)

Log Message:
-----------
Simplify textwithiconcell, we don't use all the features. Just use super's 
implementation to draw the text.

Modified Paths:
--------------
    trunk/SKTextWithIconCell.h
    trunk/SKTextWithIconCell.m

Modified: trunk/SKTextWithIconCell.h
===================================================================
--- trunk/SKTextWithIconCell.h  2007-09-13 16:22:35 UTC (rev 2917)
+++ trunk/SKTextWithIconCell.h  2007-09-13 16:43:33 UTC (rev 2918)
@@ -43,13 +43,9 @@
 
 @interface SKTextWithIconCell : NSTextFieldCell {
     NSImage *icon;
-    NSCellImagePosition imagePosition;
 }
 
 - (NSImage *)icon;
 - (void)setIcon:(NSImage *)anIcon;
 
-- (NSCellImagePosition)imagePosition;
-- (void)setImagePosition:(NSCellImagePosition)aPosition;
-
 @end

Modified: trunk/SKTextWithIconCell.m
===================================================================
--- trunk/SKTextWithIconCell.m  2007-09-13 16:22:35 UTC (rev 2917)
+++ trunk/SKTextWithIconCell.m  2007-09-13 16:43:33 UTC (rev 2918)
@@ -38,37 +38,26 @@
 
 #import "SKTextWithIconCell.h"
 
-/* Almost all of this code is copy-and-paste from 
OmniAppKit/OATextWithIconCell, except for the text layout (which seems wrong in 
OATextWithIconCell). */
+// Almost all of this code is copy-and-paste from 
OmniAppKit/OATextWithIconCell, with some simplifications for features we're not 
interested in
 
 NSString *SKTextWithIconCellImageKey = @"image";
 NSString *SKTextWithIconCellStringKey = @"string";
 
+#define BORDER_BETWEEN_EDGE_AND_IMAGE (2.0)
+#define BORDER_BETWEEN_IMAGE_AND_TEXT (2.0)
 
[EMAIL PROTECTED] NSLayoutManager (BDSKExtensions)
-+ (float)defaultViewLineHeightForFont:(NSFont *)theFont;
[EMAIL PROTECTED]
-
-
 @implementation SKTextWithIconCell
 
 // Init and dealloc
 
 - (id)init {
     if (self = [super initTextCell:@""]) {
-        [self setImagePosition:NSImageLeft];
         [self setEditable:YES];
         [self setScrollable:YES];
     }
     return self;
 }
 
-- (id)initWithCoder:(NSCoder *)coder {
-    if (self = [super initWithCoder:coder]) {
-        [self setImagePosition:NSImageLeft];
-    }
-    return self;
-}
-
 - (void)dealloc {
     [icon release];
     [super dealloc];
@@ -82,63 +71,32 @@
     return copy;
 }
 
-#define BORDER_BETWEEN_EDGE_AND_IMAGE (2.0)
-#define BORDER_BETWEEN_IMAGE_AND_TEXT (3.0)
-#define SIZE_OF_TEXT_FIELD_BORDER (1.0)
-
-#define CELL_SIZE_FUDGE_FACTOR 10.0
-
 - (NSSize)cellSize {
     NSSize cellSize = [super cellSize];
-    // TODO: WJS 1/31/04 -- I REALLY don't think this next line is accurate. 
It appears to not be used much, anyways, but still...
-    cellSize.width += [icon size].width + (BORDER_BETWEEN_EDGE_AND_IMAGE * 
2.0) + (BORDER_BETWEEN_IMAGE_AND_TEXT * 2.0) + (SIZE_OF_TEXT_FIELD_BORDER * 
2.0) + CELL_SIZE_FUDGE_FACTOR;
+    cellSize.width += [icon size].width + BORDER_BETWEEN_EDGE_AND_IMAGE + 
BORDER_BETWEEN_IMAGE_AND_TEXT;
     return cellSize;
 }
 
 #define CALCULATE_DRAWING_RECTS_AND_SIZES \
-NSRectEdge rectEdge;  \
 NSSize imageSize; \
-\
-if (imagePosition == NSImageLeft) { \
-    rectEdge = NSMinXEdge; \
-        imageSize = NSMakeSize(NSHeight(aRect) - 1, NSHeight(aRect) - 1); \
-} else { \
-    rectEdge =  NSMaxXEdge; \
-        if (icon == nil) \
-            imageSize = NSZeroSize; \
-                else \
-                    imageSize = [icon size]; \
-} \
-\
+imageSize = NSMakeSize(NSHeight(aRect) - 1, NSHeight(aRect) - 1); \
 NSRect cellFrame = aRect, ignored; \
+\
 if (imageSize.width > 0) \
-NSDivideRect(cellFrame, &ignored, &cellFrame, BORDER_BETWEEN_EDGE_AND_IMAGE, 
rectEdge); \
+NSDivideRect(cellFrame, &ignored, &cellFrame, BORDER_BETWEEN_EDGE_AND_IMAGE, 
NSMinXEdge); \
 \
 NSRect imageRect, textRect; \
-NSDivideRect(cellFrame, &imageRect, &textRect, imageSize.width, rectEdge); \
+NSDivideRect(cellFrame, &imageRect, &textRect, imageSize.width, NSMinXEdge); \
 \
 if (imageSize.width > 0) \
-NSDivideRect(textRect, &ignored, &textRect, BORDER_BETWEEN_IMAGE_AND_TEXT, 
rectEdge); \
-\
-/* this is the main difference from OATextWithIconCell, which ends up with a 
really weird text baseline for tall cells */\
-float vOffset = 0.5f * (NSHeight(aRect) - [NSLayoutManager 
defaultViewLineHeightForFont:[self font]]); \
-\
-if (![controlView isFlipped]) \
-textRect.origin.y -= vOffset; \
-else \
-textRect.origin.y += vOffset; \
+NSDivideRect(textRect, &ignored, &textRect, BORDER_BETWEEN_IMAGE_AND_TEXT, 
NSMinXEdge);
 
 - (void)drawInteriorWithFrame:(NSRect)aRect inView:(NSView *)controlView {
     CALCULATE_DRAWING_RECTS_AND_SIZES;
     
-    NSDivideRect(textRect, &ignored, &textRect, SIZE_OF_TEXT_FIELD_BORDER, 
NSMinXEdge);
-    textRect = NSInsetRect(textRect, 1.0f, 0.0);
-    
     // Draw the text
-    NSAttributedString *label = [self attributedStringValue];
+    [super drawInteriorWithFrame:textRect inView:controlView];
     
-    [label drawInRect:textRect];
-    
     // Draw the image
     imageRect.origin.x += 0.5 * (NSWidth(imageRect) - imageSize.width);
     imageRect.origin.y += 0.5 * (NSHeight(imageRect) - imageSize.height);
@@ -180,26 +138,4 @@
     }
 }
 
-- (NSCellImagePosition)imagePosition {
-    return imagePosition;
-}
-
-- (void)setImagePosition:(NSCellImagePosition)aPosition {
-    imagePosition = aPosition;
-}
-
 @end
-
-
[EMAIL PROTECTED] NSLayoutManager (BDSKExtensions)
-
-+ (float)defaultViewLineHeightForFont:(NSFont *)theFont {
-    static NSLayoutManager *layoutManager = nil;
-    if (layoutManager == nil) {
-        layoutManager = [[NSLayoutManager alloc] init];
-        [layoutManager 
setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility];
-    }
-    return [layoutManager defaultLineHeightForFont:theFont];
-}
-
[EMAIL PROTECTED]


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to