From 3021a6afa90e0b601524792614807d7a5176f6a7 Mon Sep 17 00:00:00 2001 From: dynaflash Date: Thu, 2 Aug 2007 12:52:41 +0000 Subject: [PATCH] MacGui: files I forgot to add on last commit git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@780 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/MVMenuButton.h | 22 ++++ macosx/MVMenuButton.m | 164 +++++++++++++++++++++++++++ macosx/icons/actionWidget.png | Bin 0 -> 730 bytes macosx/icons/actionWidgetPressed.png | Bin 0 -> 704 bytes 4 files changed, 186 insertions(+) create mode 100644 macosx/MVMenuButton.h create mode 100644 macosx/MVMenuButton.m create mode 100644 macosx/icons/actionWidget.png create mode 100644 macosx/icons/actionWidgetPressed.png diff --git a/macosx/MVMenuButton.h b/macosx/MVMenuButton.h new file mode 100644 index 000000000..777642d67 --- /dev/null +++ b/macosx/MVMenuButton.h @@ -0,0 +1,22 @@ +#import + +@interface MVMenuButton : NSButton { +@protected + BOOL _drawsArrow; + NSImage *_orgImage; + NSImage *_smallImage; + NSControlSize _size; + NSToolbarItem *_toolbarItem; +} +- (NSControlSize) controlSize; +- (void) setControlSize:(NSControlSize) controlSize; + +- (NSImage *) smallImage; +- (void) setSmallImage:(NSImage *) image; + +- (NSToolbarItem *) toolbarItem; +- (void) setToolbarItem:(NSToolbarItem *) item; + +- (BOOL) drawsArrow; +- (void) setDrawsArrow:(BOOL) arrow; +@end diff --git a/macosx/MVMenuButton.m b/macosx/MVMenuButton.m new file mode 100644 index 000000000..ea6b2efc6 --- /dev/null +++ b/macosx/MVMenuButton.m @@ -0,0 +1,164 @@ +#import "MVMenuButton.h" + +@implementation MVMenuButton +- (void) encodeWithCoder:(NSCoder *) coder { + [super encodeWithCoder:coder]; +} + +- (id) initWithFrame:(NSRect) frame { + if( ( self = [super initWithFrame:frame] ) ) { + [self setBordered:NO]; + [self setButtonType:NSMomentaryChangeButton]; + } + return self; +} + +- (id) initWithCoder:(NSCoder *) coder { + if( ( self = [super initWithCoder:coder] ) ) { + _size = NSRegularControlSize; + _drawsArrow = NO; + _orgImage = [[self image] copy]; + _smallImage = nil; + _toolbarItem = nil; + } + return self; +} + +- (void) dealloc { + [_orgImage release]; + [_smallImage release]; + + _orgImage = nil; + _smallImage = nil; + _toolbarItem = nil; + + [super dealloc]; +} + +- (void) drawRect:(NSRect) rect { + [super drawRect:rect]; + + if( [self drawsArrow] ) { + NSBezierPath *path = [NSBezierPath bezierPath]; + + if( _size == NSRegularControlSize ) { + [path moveToPoint:NSMakePoint( NSWidth( [self frame] ) - 6, NSHeight( [self frame] ) - 3 )]; + [path relativeLineToPoint:NSMakePoint( 6, 0 )]; + [path relativeLineToPoint:NSMakePoint( -3, 3 )]; + } else if( _size == NSSmallControlSize ) { + [path moveToPoint:NSMakePoint( NSWidth( [self frame] ) - 4, NSHeight( [self frame] ) - 3 )]; + [path relativeLineToPoint:NSMakePoint( 4, 0 )]; + [path relativeLineToPoint:NSMakePoint( -2, 3 )]; + } + + [path closePath]; + [[[NSColor blackColor] colorWithAlphaComponent:0.75] set]; + [path fill]; + } +} + +- (void) mouseDown:(NSEvent *) theEvent { + if( ! [self isEnabled] ) return; + if( ! [self menu] ) { + [super mouseDown:theEvent]; + return; + } + + [self highlight:YES]; + + NSPoint point = [self convertPoint:[self bounds].origin toView:nil]; + point.y -= NSHeight( [self frame] ) + 2.; + point.x -= 1.; + + NSEvent *event = [NSEvent mouseEventWithType:[theEvent type] location:point modifierFlags:[theEvent modifierFlags] timestamp:[theEvent timestamp] windowNumber:[[theEvent window] windowNumber] context:[theEvent context] eventNumber:[theEvent eventNumber] clickCount:[theEvent clickCount] pressure:[theEvent pressure]]; + [NSMenu popUpContextMenu:[self menu] withEvent:event forView:self]; + + [self mouseUp:[[NSApplication sharedApplication] currentEvent]]; +} + +- (void) mouseUp:(NSEvent *) theEvent { + [self highlight:NO]; + [super mouseUp:theEvent]; +} + +- (void) mouseDragged:(NSEvent *) theEvent { + return; +} + +- (NSControlSize) controlSize { + return ( _size ? _size : NSRegularControlSize ); +} + +- (void) setControlSize:(NSControlSize) controlSize { + if( ! _orgImage ) _orgImage = [[self image] copy]; + if( controlSize == NSRegularControlSize ) { + [super setImage:_orgImage]; + [_toolbarItem setMinSize:NSMakeSize( 32., 32. )]; + [_toolbarItem setMaxSize:NSMakeSize( 32., 32. )]; + } else if( controlSize == NSSmallControlSize ) { + if( ! _smallImage ) { + NSImageRep *sourceImageRep = [_orgImage bestRepresentationForDevice:nil]; + _smallImage = [[NSImage alloc] initWithSize:NSMakeSize( 24., 24. )]; + [_smallImage lockFocus]; + [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; + [sourceImageRep drawInRect:NSMakeRect( 0., 0., 24., 24. )]; + [_smallImage unlockFocus]; + } + [super setImage:_smallImage]; + [_toolbarItem setMinSize:NSMakeSize( 24., 24. )]; + [_toolbarItem setMaxSize:NSMakeSize( 24., 24. )]; + } + _size = controlSize; +} + +- (void) setImage:(NSImage *) image { + [_orgImage autorelease]; + _orgImage = [[self image] copy]; + + NSImageRep *sourceImageRep = [image bestRepresentationForDevice:nil]; + [_smallImage autorelease]; + _smallImage = [[NSImage alloc] initWithSize:NSMakeSize( 24., 24. )]; + [_smallImage lockFocus]; + [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh]; + [sourceImageRep drawInRect:NSMakeRect( 0., 0., 24., 24. )]; + [_smallImage unlockFocus]; + + if( _size == NSRegularControlSize ) [super setImage:image]; + else if( _size == NSSmallControlSize ) [super setImage:_smallImage]; +} + +- (NSImage *) smallImage { + return _smallImage; +} + +- (void) setSmallImage:(NSImage *) image { + [_smallImage autorelease]; + _smallImage = [image copy]; +} + +- (NSToolbarItem *) toolbarItem { + return _toolbarItem; +} + +- (void) setToolbarItem:(NSToolbarItem *) item { + _toolbarItem = item; +} + +- (BOOL) drawsArrow { + return _drawsArrow; +} + +- (void) setDrawsArrow:(BOOL) arrow { + _drawsArrow = arrow; +} + +- (id) accessibilityAttributeValue:(NSString *) attribute { + if( [attribute isEqualToString:NSAccessibilityTitleAttribute] ) + return [_toolbarItem label]; + if( [attribute isEqualToString:NSAccessibilityHelpAttribute] ) + return [_toolbarItem toolTip]; + if( [attribute isEqualToString:NSAccessibilityToolbarButtonAttribute] ) + return _toolbarItem; + return [super accessibilityAttributeValue:attribute]; +} +@end diff --git a/macosx/icons/actionWidget.png b/macosx/icons/actionWidget.png new file mode 100644 index 0000000000000000000000000000000000000000..d4e18cb36ebad5e08640cf8703bda17611f4e53f GIT binary patch literal 730 zcmV<00ww*4P)^4?ts|6rO((b}{>IF7sD-S5Nq z_q#jJ0A2x_?wDb0Y;5Qt2)aTOLLdeQ2U%KL>IyKI%VBnf^uYcfpi&BeYPCuxli_V9 zL$z9M@x2((^E@2Kp;#b+92^{A zSr$RF3BcCY7MGWo)ayS`O0lr8fN4IhDs8Jx(k9I^g6p~{rReDq zB$LS}!#XOIQes&a@pznziwj1EhnY>M0r+k66>$~5VzD;|fP{6kB`|)p68jVId zIXS^~KhtP5I6Et`va*8K8X*LxX;Lbkl* zwFYDX#c-r)l}bg$aXb{7X_}asOom)8Hxyv2)j}T%>4k<4G~X*IrO-5uFbp|5Izj=T zHZ~X?9qrWy(VGrE&!bkW(P%UX!w}bXd2(ICFr?9FP^;DOJZ~Ui%Arz<^Ye4+^*WB@ zkj-XEp11hqdD14!FO+&*S4GNs^Ex z2_MR3W@cu9pK%`^9&&TjWOsL$$;nB!x3{TQtJLfD)bPc{MOIf=(?H+%dmq9uB#I)W zlq7LX5Cpw?5ClX~glS5WL?;YGeBY;3DiK8yj^p&^6pKYlrP8a}Z#vxC+9HY~j*mYh zgrHjef|L?~)6-L=RM>Wg_4SX8jEwa9mY!pG9EW1D*gO9*(us))uCK2V;*M@NrrEsZ z;NakSSqwByU22SXf|wejdXx`i22$dwYAzvaErc`_;q4Lpsubt^WhO mzrP(eR0000