From 2f9cf6bc9b4ab00e1a6b0473ddfb2fbd2ddf6c8d Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Tue, 27 Apr 2010 22:11:17 -0700 Subject: [PATCH] Add action buttons to button bars. --- AppKit/CPButtonBar.j | 37 ++++++++++++++++++++++-- AppKit/Resources/action_button.png | Bin 0 -> 506 bytes AppKit/Themes/Aristo/ThemeDescriptors.j | 8 +++-- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 AppKit/Resources/action_button.png diff --git a/AppKit/CPButtonBar.j b/AppKit/CPButtonBar.j index 1f63473de..01aa1d833 100644 --- a/AppKit/CPButtonBar.j +++ b/AppKit/CPButtonBar.j @@ -14,7 +14,7 @@ + (id)plusButton { var button = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, 35, 25)], - image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:self] pathForResource:@"plus_button.png"] size:CGSizeMake(11, 12)]; + image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPButtonBar class]] pathForResource:@"plus_button.png"] size:CGSizeMake(11, 12)]; [button setBordered:NO]; [button setImage:image]; @@ -26,7 +26,7 @@ + (id)minusButton { var button = [[CPButton alloc] initWithFrame:CGRectMake(0, 0, 35, 25)], - image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:self] pathForResource:@"minus_button.png"] size:CGSizeMake(11, 4)]; + image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPButtonBar class]] pathForResource:@"minus_button.png"] size:CGSizeMake(11, 4)]; [button setBordered:NO]; [button setImage:image]; @@ -35,6 +35,21 @@ return button; } ++ (id)actionPopupButton +{ + var button = [[CPPopUpButton alloc] initWithFrame:CGRectMake(0, 0, 35, 25)], + image = [[CPImage alloc] initWithContentsOfFile:[[CPBundle bundleForClass:[CPButtonBar class]] pathForResource:@"action_button.png"] size:CGSizeMake(22, 14)]; + + [button addItemWithTitle:nil]; + [[button lastItem] setImage:image]; + [button setImagePosition:CPImageOnly]; + [button setValue:CGInsetMake(0, 0, 0, 0) forThemeAttribute:"content-inset"]; + + [button setPullsDown:YES]; + + return button; +} + + (CPString)themeClass { return @"button-bar"; @@ -174,13 +189,23 @@ [buttonsNotHidden removeObject:buttonsNotHidden[count]]; var currentButtonOffset = _resizeControlIsLeftAligned ? CGRectGetMaxX([self bounds]) + 1 : -1, - height = CGRectGetHeight([self bounds]) - 1; + bounds = [self bounds], + height = CGRectGetHeight(bounds) - 1, + frameWidth = CGRectGetWidth(bounds), + resizeRect = _hasResizeControl ? [self rectForEphemeralSubviewNamed:"resize-control-view"] : CGRectMakeZero(), + resizeWidth = CGRectGetWidth(resizeRect), + availableWidth = frameWidth - resizeWidth - 1; for (var i = 0, count = [buttonsNotHidden count]; i < count; i++) { var button = buttonsNotHidden[i], width = CGRectGetWidth([button frame]); + if (availableWidth > width) + availableWidth -=width; + else + break; + if (_resizeControlIsLeftAligned) { [button setFrame:CGRectMake(currentButtonOffset - width, 1, width, height)]; @@ -216,6 +241,12 @@ } } +- (void)setFrameSize:(CGSize)aSize +{ + [super setFrameSize:aSize]; + [self setNeedsLayout]; +} + @end var CPButtonBarHasResizeControlKey = @"CPButtonBarHasResizeControlKey", diff --git a/AppKit/Resources/action_button.png b/AppKit/Resources/action_button.png new file mode 100644 index 0000000000000000000000000000000000000000..2af0dfc48ffaae68415fea7a5d2e6653786424ec GIT binary patch literal 506 zcmV3ZN0000PbVXQnQ*UN; zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBUzoJmAMRCwBA`2YVu12P5zW+>ec#2`jL zl+TT>79U17P!fn67#SH40BKgJp)kzH&d%Noq}P#bFb4<6E|@`3!{G+Au&``K;_o5J z;L_64t!S>qz(C9Y7#SJeCCOkQ_N=X~y$v!zM@Q#lUtiz#w{PDbo;Y#hH4qGE?E-N;l>gt@*!caAA3qL2)x$0R_U&6> zLPEkLAlm|4Iz9$WW`Ci{?H{g`0hGImC9;@+I16j4FflQ?2h$uJ9Q+K~Fj#8g