Revision: 14991 http://sourceforge.net/p/skim-app/code/14991 Author: hofman Date: 2025-03-20 10:16:57 +0000 (Thu, 20 Mar 2025) Log Message: ----------- Support small control size for color swatch, can be used by customized compact toolbar styles. Don't support large control size, as NSSegmentedCell really messes this up.
Modified Paths: -------------- trunk/SKColorSwatch.m Modified: trunk/SKColorSwatch.m =================================================================== --- trunk/SKColorSwatch.m 2025-03-19 17:18:01 UTC (rev 14990) +++ trunk/SKColorSwatch.m 2025-03-20 10:16:57 UTC (rev 14991) @@ -54,6 +54,7 @@ #define TARGET_KEY @"target" #define AUTORESIZES_KEY @"autoResizes" #define SELECTS_KEY @"selects" +#define BEZELHEIGHT_KEY @"bezelHeight" #define COLOR_KEY @"color" @@ -62,7 +63,8 @@ #define BEZEL_INSET_BOTTOM 2.0 #define COLOR_INSET 2.0 -#define BACKGROUND_WIDTH_OFFSET 6.0 +#define BACKGROUND_WIDTH_OFFSET 6.0 +#define SMALL_BACKGROUND_WIDTH_OFFSET 2.0 @interface SKColorSwatchBackgroundView : NSControl @property (nonatomic) CGFloat width; @@ -121,8 +123,6 @@ selectedIndex = -1; draggedIndex = -1; - bezelHeight = 22.0; - [self registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSPasteboardNameDrag]]]; } @@ -134,7 +134,8 @@ target = nil; autoResizes = YES; selects = NO; - + bezelHeight = 22.0; + [self commonInit]; SKColorSwatchBackgroundView *view = [[SKColorSwatchBackgroundView alloc] initWithFrame:[self bounds]]; @@ -159,7 +160,8 @@ target = [decoder decodeObjectForKey:TARGET_KEY]; autoResizes = [decoder decodeBoolForKey:AUTORESIZES_KEY]; selects = [decoder decodeBoolForKey:SELECTS_KEY]; - + bezelHeight = [decoder decodeDoubleForKey:BEZELHEIGHT_KEY]; + [self commonInit]; itemViews = [[NSMutableArray alloc] init]; @@ -170,6 +172,9 @@ else if ([view isKindOfClass:[SKColorSwatchItemView class]]) [itemViews addObject:(SKColorSwatchItemView *)view]; } + + // this is only used for the toolbar customization palette + [backgroundView setControlSize:NSControlSizeRegular]; } return self; } @@ -181,6 +186,7 @@ [coder encodeConditionalObject:target forKey:TARGET_KEY]; [coder encodeBool:autoResizes forKey:AUTORESIZES_KEY]; [coder encodeBool:selects forKey:SELECTS_KEY]; + [coder encodeDouble:bezelHeight forKey:BEZELHEIGHT_KEY]; } - (void)dealloc { @@ -295,6 +301,20 @@ } } +- (void)setControlSize:(NSControlSize)controlSize { + [super setControlSize:controlSize]; + [backgroundView setControlSize:controlSize > NSControlSizeMini ? NSControlSizeRegular : controlSize]; + if ([self window]) { + CGFloat height = [[backgroundView cell] cellSize].height - BEZEL_INSET_TOP - BEZEL_INSET_BOTTOM; + if (fabs(height - bezelHeight) > 0.0) { + bezelHeight = height; + [self updateSubviewLayout]; + if (autoResizes) + [self sizeToFit]; + } + } +} + #pragma mark Notification handling - (void)deactivate:(NSNotification *)note { @@ -861,6 +881,10 @@ return [super defaultAnimationForKey:key]; } +- (CGFloat)widthOffset { + return [self controlSize] == NSControlSizeSmall || [self controlSize] == NSControlSizeMini ? SMALL_BACKGROUND_WIDTH_OFFSET : BACKGROUND_WIDTH_OFFSET; +} + - (instancetype)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; if (self) { 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