view dstep/appkit/NSButtonCell.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Sep 24, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.appkit.NSButtonCell;

import dstep.appkit.NSActionCell;
import dstep.appkit.NSAttributedString;
import dstep.appkit.NSColor;
import dstep.appkit.NSEvent;
import dstep.appkit.NSFont;
import dstep.appkit.NSImage;
import dstep.appkit.NSSound;
import dstep.appkit.NSView;
import dstep.applicationservices.coregraphics.CGBase;
import dstep.foundation.NSAttributedString;
import dstep.foundation.NSGeometry;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSString;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

alias NSUInteger NSButtonType;
alias NSUInteger NSBezelStyle;
alias NSUInteger NSGradientType;

enum
{
	NSMomentaryLightButton = 0,
	NSPushOnPushOffButton = 1,
	NSToggleButton = 2,
	NSSwitchButton = 3,
	NSRadioButton = 4,
	NSMomentaryChangeButton = 5,
	NSOnOffButton = 6,
	NSMomentaryPushInButton = 7,
	NSMomentaryPushButton = 0,
	NSMomentaryLight = 7
}

enum
{
	NSRoundedBezelStyle = 1,
	NSRegularSquareBezelStyle = 2,
	NSThickSquareBezelStyle = 3,
	NSThickerSquareBezelStyle = 4,
	NSDisclosureBezelStyle = 5,
	NSShadowlessSquareBezelStyle = 6,
	NSCircularBezelStyle = 7,
	NSTexturedSquareBezelStyle = 8,
	NSHelpButtonBezelStyle = 9,
	NSSmallSquareBezelStyle = 10,
	NSTexturedRoundedBezelStyle = 11,
	NSRoundRectBezelStyle = 12,
	NSRecessedBezelStyle = 13,
	NSRoundedDisclosureBezelStyle = 14,
	NSSmallIconButtonBezelStyle = 2
}

enum
{
	NSGradientNone = 0,
	NSGradientConcaveWeak = 1,
	NSGradientConcaveStrong = 2,
	NSGradientConvexWeak = 3,
	NSGradientConvexStrong = 4
}

struct _BCFlags
{
	uint alternateMnemonicLocation;
	uint useButtonImageSource;
	uint gradientType;
	uint doesNotDimImage;
	uint inset;
	uint transparent;
	uint lastState;
	uint hasKeyEquivalentInsteadOfImage;
	uint imageSizeDiff;
	uint imageAndText;
	uint bottomOrLeft;
	uint horizontal;
	uint imageOverlaps;
	uint bordered;
	uint drawing;
	uint lightByGray;
	uint lightByBackground;
	uint lightByContents;
	uint changeGray;
	uint changeBackground;
	uint changeContents;
	uint pushIn;
}


struct _BCFlags2
{
	uint bezelStyle;
	uint showsBorderOnlyWhileMouseInside;
	uint mouseInside;
	uint bezelStyle2;
	uint imageScaling;
	uint keyEquivalentModifierMask;
}

const TNSButtonCellExtensions = `

	uint gradientType ()
	{
		return invokeObjcSelf!(uint, "gradientType");
	}

	void setGradientType (uint type)
	{
		return invokeObjcSelf!(void, "setGradientType:", uint)(type);
	}

	void setImageDimsWhenDisabled (bool flag)
	{
		return invokeObjcSelf!(void, "setImageDimsWhenDisabled:", bool)(flag);
	}

	bool imageDimsWhenDisabled ()
	{
		return invokeObjcSelf!(bool, "imageDimsWhenDisabled");
	}

	void setShowsBorderOnlyWhileMouseInside (bool show)
	{
		return invokeObjcSelf!(void, "setShowsBorderOnlyWhileMouseInside:", bool)(show);
	}

	bool showsBorderOnlyWhileMouseInside ()
	{
		return invokeObjcSelf!(bool, "showsBorderOnlyWhileMouseInside");
	}

	void mouseEntered (NSEvent event)
	{
		return invokeObjcSelf!(void, "mouseEntered:", NSEvent)(event);
	}

	void mouseExited (NSEvent event)
	{
		return invokeObjcSelf!(void, "mouseExited:", NSEvent)(event);
	}

	NSColor backgroundColor ()
	{
		return invokeObjcSelf!(NSColor, "backgroundColor");
	}

	void setBackgroundColor (NSColor color)
	{
		return invokeObjcSelf!(void, "setBackgroundColor:", NSColor)(color);
	}

	//mixin ObjcBindMethod!(gradientType, "gradientType");
	//mixin ObjcBindMethod!(setGradientType, "setGradientType:");
	//mixin ObjcBindMethod!(setImageDimsWhenDisabled, "setImageDimsWhenDisabled:");
	//mixin ObjcBindMethod!(imageDimsWhenDisabled, "imageDimsWhenDisabled");
	//mixin ObjcBindMethod!(setShowsBorderOnlyWhileMouseInside, "setShowsBorderOnlyWhileMouseInside:");
	//mixin ObjcBindMethod!(showsBorderOnlyWhileMouseInside, "showsBorderOnlyWhileMouseInside");
	//mixin ObjcBindMethod!(mouseEntered, "mouseEntered:");
	//mixin ObjcBindMethod!(mouseExited, "mouseExited:");
	//mixin ObjcBindMethod!(backgroundColor, "backgroundColor");
	//mixin ObjcBindMethod!(setBackgroundColor, "setBackgroundColor:");

`;

const TNSButtonCellBezelStyles = `

	void setBezelStyle (uint bezelStyle)
	{
		return invokeObjcSelf!(void, "setBezelStyle:", uint)(bezelStyle);
	}

	uint bezelStyle ()
	{
		return invokeObjcSelf!(uint, "bezelStyle");
	}

	//mixin ObjcBindMethod!(setBezelStyle, "setBezelStyle:");
	//mixin ObjcBindMethod!(bezelStyle, "bezelStyle");

`;

const TNSButtonCellSoundExtensions = `

	void setSound (NSSound aSound)
	{
		return invokeObjcSelf!(void, "setSound:", NSSound)(aSound);
	}

	NSSound sound ()
	{
		return invokeObjcSelf!(NSSound, "sound");
	}

	//mixin ObjcBindMethod!(setSound, "setSound:");
	//mixin ObjcBindMethod!(sound, "sound");

`;

const TNSButtonCellAttributedStringMethods = `

	NSAttributedString attributedTitle ()
	{
		return invokeObjcSelf!(NSAttributedString, "attributedTitle");
	}

	void setAttributedTitle (NSAttributedString obj)
	{
		return invokeObjcSelf!(void, "setAttributedTitle:", NSAttributedString)(obj);
	}

	NSAttributedString attributedAlternateTitle ()
	{
		return invokeObjcSelf!(NSAttributedString, "attributedAlternateTitle");
	}

	void setAttributedAlternateTitle (NSAttributedString obj)
	{
		return invokeObjcSelf!(void, "setAttributedAlternateTitle:", NSAttributedString)(obj);
	}

	//mixin ObjcBindMethod!(attributedTitle, "attributedTitle");
	//mixin ObjcBindMethod!(setAttributedTitle, "setAttributedTitle:");
	//mixin ObjcBindMethod!(attributedAlternateTitle, "attributedAlternateTitle");
	//mixin ObjcBindMethod!(setAttributedAlternateTitle, "setAttributedAlternateTitle:");

`;

class NSButtonCell : NSActionCell
{
	mixin (ObjcWrap);

	NSString title ()
	{
		return invokeObjcSelf!(NSString, "title");
	}

	void setTitle (NSString aString)
	{
		return invokeObjcSelf!(void, "setTitle:", NSString)(aString);
	}

	NSString alternateTitle ()
	{
		return invokeObjcSelf!(NSString, "alternateTitle");
	}

	void setAlternateTitle (NSString aString)
	{
		return invokeObjcSelf!(void, "setAlternateTitle:", NSString)(aString);
	}

	NSImage alternateImage ()
	{
		return invokeObjcSelf!(NSImage, "alternateImage");
	}

	void setAlternateImage (NSImage image)
	{
		return invokeObjcSelf!(void, "setAlternateImage:", NSImage)(image);
	}

	uint imagePosition ()
	{
		return invokeObjcSelf!(uint, "imagePosition");
	}

	void setImagePosition (uint aPosition)
	{
		return invokeObjcSelf!(void, "setImagePosition:", uint)(aPosition);
	}

	uint imageScaling ()
	{
		return invokeObjcSelf!(uint, "imageScaling");
	}

	void setImageScaling (uint scaling)
	{
		return invokeObjcSelf!(void, "setImageScaling:", uint)(scaling);
	}

	NSInteger highlightsBy ()
	{
		return invokeObjcSelf!(NSInteger, "highlightsBy");
	}

	void setHighlightsBy (NSInteger aType)
	{
		return invokeObjcSelf!(void, "setHighlightsBy:", NSInteger)(aType);
	}

	NSInteger showsStateBy ()
	{
		return invokeObjcSelf!(NSInteger, "showsStateBy");
	}

	void setShowsStateBy (NSInteger aType)
	{
		return invokeObjcSelf!(void, "setShowsStateBy:", NSInteger)(aType);
	}

	void setButtonType (uint aType)
	{
		return invokeObjcSelf!(void, "setButtonType:", uint)(aType);
	}

	bool isOpaque ()
	{
		return invokeObjcSelf!(bool, "isOpaque");
	}

	void setFont (NSFont fontObj)
	{
		return invokeObjcSelf!(void, "setFont:", NSFont)(fontObj);
	}

	bool isTransparent ()
	{
		return invokeObjcSelf!(bool, "isTransparent");
	}

	void setTransparent (bool flag)
	{
		return invokeObjcSelf!(void, "setTransparent:", bool)(flag);
	}

	void setPeriodicDelay (float delay, float interval)
	{
		return invokeObjcSelf!(void, "setPeriodicDelay:interval:", float, float)(delay, interval);
	}

	void getPeriodicDelay (float* delay, float* interval)
	{
		return invokeObjcSelf!(void, "getPeriodicDelay:interval:", float*, float*)(delay, interval);
	}

	NSString keyEquivalent ()
	{
		return invokeObjcSelf!(NSString, "keyEquivalent");
	}

	void setKeyEquivalent (NSString aKeyEquivalent)
	{
		return invokeObjcSelf!(void, "setKeyEquivalent:", NSString)(aKeyEquivalent);
	}

	NSUInteger keyEquivalentModifierMask ()
	{
		return invokeObjcSelf!(NSUInteger, "keyEquivalentModifierMask");
	}

	void setKeyEquivalentModifierMask (NSUInteger mask)
	{
		return invokeObjcSelf!(void, "setKeyEquivalentModifierMask:", NSUInteger)(mask);
	}

	NSFont keyEquivalentFont ()
	{
		return invokeObjcSelf!(NSFont, "keyEquivalentFont");
	}

	void setKeyEquivalentFont (NSFont fontObj)
	{
		return invokeObjcSelf!(void, "setKeyEquivalentFont:", NSFont)(fontObj);
	}

	void setKeyEquivalentFont (NSString fontName, CGFloat fontSize)
	{
		return invokeObjcSelf!(void, "setKeyEquivalentFont:size:", NSString, CGFloat)(fontName, fontSize);
	}

	void performClick (Object sender)
	{
		return invokeObjcSelf!(void, "performClick:", Object)(sender);
	}

	void drawImage (NSImage image, NSRect frame, NSView controlView)
	{
		return invokeObjcSelf!(void, "drawImage:withFrame:inView:", NSImage, NSRect, NSView)(image, frame, controlView);
	}

	NSRect drawTitle (NSAttributedString title, NSRect frame, NSView controlView)
	{
		return invokeObjcSelf!(NSRect, "drawTitle:withFrame:inView:", NSAttributedString, NSRect, NSView)(title, frame, controlView);
	}

	void drawBezelWithFrame (NSRect frame, NSView controlView)
	{
		return invokeObjcSelf!(void, "drawBezelWithFrame:inView:", NSRect, NSView)(frame, controlView);
	}
	
	// NSButtonCellExtensions
	uint gradientType ()
	{
		return invokeObjcSelf!(uint, "gradientType");
	}

	void setGradientType (uint type)
	{
		return invokeObjcSelf!(void, "setGradientType:", uint)(type);
	}

	void setImageDimsWhenDisabled (bool flag)
	{
		return invokeObjcSelf!(void, "setImageDimsWhenDisabled:", bool)(flag);
	}

	bool imageDimsWhenDisabled ()
	{
		return invokeObjcSelf!(bool, "imageDimsWhenDisabled");
	}

	void setShowsBorderOnlyWhileMouseInside (bool show)
	{
		return invokeObjcSelf!(void, "setShowsBorderOnlyWhileMouseInside:", bool)(show);
	}

	bool showsBorderOnlyWhileMouseInside ()
	{
		return invokeObjcSelf!(bool, "showsBorderOnlyWhileMouseInside");
	}

	void mouseEntered (NSEvent event)
	{
		return invokeObjcSelf!(void, "mouseEntered:", NSEvent)(event);
	}

	void mouseExited (NSEvent event)
	{
		return invokeObjcSelf!(void, "mouseExited:", NSEvent)(event);
	}

	NSColor backgroundColor ()
	{
		return invokeObjcSelf!(NSColor, "backgroundColor");
	}

	void setBackgroundColor (NSColor color)
	{
		return invokeObjcSelf!(void, "setBackgroundColor:", NSColor)(color);
	}
	
	// NSButtonCellBezelStyles
	void setBezelStyle (uint bezelStyle)
	{
		return invokeObjcSelf!(void, "setBezelStyle:", uint)(bezelStyle);
	}

	uint bezelStyle ()
	{
		return invokeObjcSelf!(uint, "bezelStyle");
	}
	
	// NSButtonCellSoundExtensions
	void setSound (NSSound aSound)
	{
		return invokeObjcSelf!(void, "setSound:", NSSound)(aSound);
	}

	NSSound sound ()
	{
		return invokeObjcSelf!(NSSound, "sound");
	}
	
	// NSButtonCellAttributedStringMethods
	NSAttributedString attributedTitle ()
	{
		return invokeObjcSelf!(NSAttributedString, "attributedTitle");
	}

	void setAttributedTitle (NSAttributedString obj)
	{
		return invokeObjcSelf!(void, "setAttributedTitle:", NSAttributedString)(obj);
	}

	NSAttributedString attributedAlternateTitle ()
	{
		return invokeObjcSelf!(NSAttributedString, "attributedAlternateTitle");
	}

	void setAttributedAlternateTitle (NSAttributedString obj)
	{
		return invokeObjcSelf!(void, "setAttributedAlternateTitle:", NSAttributedString)(obj);
	}
}