Revision: 23844
          http://sourceforge.net/p/bibdesk/svn/23844
Author:   hofman
Date:     2019-05-30 13:46:28 +0000 (Thu, 30 May 2019)
Log Message:
-----------
draw image popup button using button cell again, because NSPopUpButtonCell is 
seriously messed up

Modified Paths:
--------------
    trunk/bibdesk/BDSKImagePopUpButtonCell.h
    trunk/bibdesk/BDSKImagePopUpButtonCell.m

Modified: trunk/bibdesk/BDSKImagePopUpButtonCell.h
===================================================================
--- trunk/bibdesk/BDSKImagePopUpButtonCell.h    2019-05-30 06:30:42 UTC (rev 
23843)
+++ trunk/bibdesk/BDSKImagePopUpButtonCell.h    2019-05-30 13:46:28 UTC (rev 
23844)
@@ -39,5 +39,7 @@
 
 #import <Cocoa/Cocoa.h>
 
-@interface BDSKImagePopUpButtonCell : NSPopUpButtonCell
+@interface BDSKImagePopUpButtonCell : NSPopUpButtonCell {
+    NSButtonCell *buttonCell;
+}
 @end

Modified: trunk/bibdesk/BDSKImagePopUpButtonCell.m
===================================================================
--- trunk/bibdesk/BDSKImagePopUpButtonCell.m    2019-05-30 06:30:42 UTC (rev 
23843)
+++ trunk/bibdesk/BDSKImagePopUpButtonCell.m    2019-05-30 13:46:28 UTC (rev 
23844)
@@ -44,11 +44,22 @@
 
 @implementation BDSKImagePopUpButtonCell
 
+- (void)makeButtonCell {
+    buttonCell = [[NSButtonCell allocWithZone:[self zone]] initTextCell:@""];
+    [buttonCell setBordered: NO];
+    [buttonCell setHighlightsBy:NSContentsCellMask];
+    [buttonCell setImagePosition:NSImageOnly];
+    [buttonCell setImageScaling:NSImageScaleProportionallyDown];
+    [buttonCell setEnabled:[self isEnabled]];
+    [buttonCell setShowsFirstResponder:[self showsFirstResponder]];
+}
+
 // we should always be unbordered and pulldown
 - (id)initTextCell:(NSString *)stringValue pullsDown:(BOOL)pullsDown{
     self = [super initTextCell:stringValue pullsDown:YES];
     if (self) {
         [self setBordered:NO];
+        [self makeButtonCell];
     }
     return self;
 }
@@ -57,10 +68,42 @@
     self = [super initWithCoder:coder];
     if (self) {
         [self setBordered:NO];
+        [self makeButtonCell];
        }
        return self;
 }
 
+- (id)copyWithZone:(NSZone *)aZone {
+    BDSKImagePopUpButtonCell *copy = [super copyWithZone:aZone];
+    [copy makeButtonCell];
+    return copy;
+}
+
+- (void)dealloc {
+    BDSKDESTROY(buttonCell);
+    [super dealloc];
+}
+
+- (void)setEnabled:(BOOL)flag {
+    [super setEnabled:flag];
+    [buttonCell setEnabled:flag];
+}
+
+- (void)setShowsFirstResponder:(BOOL)flag{
+    [super setShowsFirstResponder:flag];
+    [buttonCell setShowsFirstResponder:flag];
+}
+
+- (void)setBackgroundStyle:(NSBackgroundStyle)style {
+    [super setBackgroundStyle:style];
+    [buttonCell setBackgroundStyle:style];
+}
+
+- (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView 
*)controlView{
+    [buttonCell highlight:flag withFrame:cellFrame inView:controlView];
+    [super highlight:flag withFrame:cellFrame inView:controlView];
+}
+
 #pragma mark Drawing and highlighting
 
 - (NSSize)cellSizeForBounds:(NSRect)aRect {
@@ -76,6 +119,12 @@
     return rect;
 }
 
+- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
+    [buttonCell setImage:[self numberOfItems] ? [[self itemAtIndex:0] image] : 
nil];
+    [buttonCell drawWithFrame:[self imageRectForBounds:cellFrame] 
inView:controlView];
+    [self drawBorderAndBackgroundWithFrame:cellFrame inView:controlView];
+}
+
 - (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView 
*)controlView {
     if ([self arrowPosition] != NSPopUpNoArrow) {
         NSRect arrowRect = NSZeroRect, rect = cellFrame;

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to