1/*****************************************************************************\
2     Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3                This file is licensed under the Snes9x License.
4   For further information, consult the LICENSE file in the root directory.
5\*****************************************************************************/
6
7/***********************************************************************************
8  SNES9X for Mac OS (c) Copyright John Stiles
9
10  Snes9x for Mac OS X
11
12  (c) Copyright 2001 - 2011  zones
13  (c) Copyright 2002 - 2005  107
14  (c) Copyright 2002         PB1400c
15  (c) Copyright 2004         Alexander and Sander
16  (c) Copyright 2004 - 2005  Steven Seeger
17  (c) Copyright 2005         Ryan Vogt
18 ***********************************************************************************/
19
20
21#import <Cocoa/Cocoa.h>
22
23#import "mac-cocoatools.h"
24
25
26void CocoaPlayFreezeDefrostSound (void)
27{
28	NSAutoreleasePool	*pool;
29	NSBundle			*bundle;
30	NSString			*path;
31	NSSound				*sound;
32	BOOL				r;
33
34	pool = [[NSAutoreleasePool alloc] init];
35
36	bundle = [NSBundle mainBundle];
37	path = [bundle pathForSoundResource: @"freeze_defrost"];
38	if (path)
39	{
40		sound = [[NSSound alloc] initWithContentsOfFile: path byReference: YES];
41		if (sound)
42		{
43			r = [sound play];
44			[sound release];
45		}
46	}
47
48	[pool release];
49}
50
51void CocoaAddStatTextToView (NSView *view, NSString *label, float x, float y, float w, float h, NSTextField **out)
52{
53	NSTextField	*control;
54
55	control = [[[NSTextField alloc] init] autorelease];
56
57	[[control cell] setControlSize: NSSmallControlSize];
58	[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
59	[control setStringValue: NSLocalizedString(label, @"")];
60	[control setBezeled: NO];
61	[control setDrawsBackground: NO];
62	[control setEditable: NO];
63	[control setSelectable: NO];
64
65	[view addSubview: control];
66	[control setFrame: NSMakeRect(x, y, w, h)];
67
68	if (out != NULL)
69		*out = control;
70}
71
72void CocoaAddEditTextToView (NSView *view, NSString *label, float x, float y, float w, float h, NSTextField **out)
73{
74	NSTextField	*control;
75
76	control = [[[NSTextField alloc] init] autorelease];
77
78	[[control cell] setControlSize: NSSmallControlSize];
79	[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
80	[control setStringValue: NSLocalizedString(label, @"")];
81	[control setBezeled: YES];
82	[control setDrawsBackground: YES];
83	[control setEditable: YES];
84	[control setSelectable: YES];
85
86	[view addSubview: control];
87	[control setFrame: NSMakeRect(x, y, w, h)];
88
89	if (out != NULL)
90		*out = control;
91}
92
93void CocoaAddMPushBtnToView (NSView *view, NSString *label, float x, float y, float w, float h, NSButton **out)
94{
95	NSButton	*control;
96
97	control = [[[NSButton alloc] init] autorelease];
98
99	[[control cell] setControlSize: NSSmallControlSize];
100	[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
101	[control setTitle: NSLocalizedString(label, @"")];
102	[control setBezelStyle: NSRoundedBezelStyle];
103	[control setButtonType: NSMomentaryPushInButton];
104
105	[view addSubview: control];
106	[control setFrame: NSMakeRect(x, y, w, h)];
107
108	if (out != NULL)
109		*out = control;
110}
111
112void CocoaAddCheckBoxToView (NSView *view, NSString *label, float x, float y, float w, float h, NSButton **out)
113{
114	NSButton	*control;
115
116	control = [[[NSButton alloc] init] autorelease];
117
118	[[control cell] setControlSize: NSSmallControlSize];
119	[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
120	[control setTitle: NSLocalizedString(label, @"")];
121	[control setButtonType: NSSwitchButton];
122
123	[view addSubview: control];
124	[control setFrame: NSMakeRect(x, y, w, h)];
125
126	if (out != NULL)
127		*out = control;
128}
129
130void CocoaAddPopUpBtnToView (NSView *view, NSArray *array, float x, float y, float w, float h, NSPopUpButton **out)
131{
132	NSPopUpButton	*control;
133	NSMenu			*menu;
134	int				n;
135
136	menu = [[[NSMenu alloc] init] autorelease];
137
138	n = [array count];
139	for (int i = 0; i < n; i++)
140	{
141		NSString	*item = [array objectAtIndex: i];
142		if ([item isEqualToString: @"---"])
143			[menu addItem: [NSMenuItem separatorItem]];
144		else
145			[menu addItemWithTitle: item action: NULL keyEquivalent: @""];
146	}
147
148	control = [[[NSPopUpButton alloc] init] autorelease];
149
150	[[control cell] setControlSize: NSSmallControlSize];
151	[control setFont: [NSFont systemFontOfSize: [NSFont systemFontSizeForControlSize: NSSmallControlSize]]];
152	[control setPullsDown: NO];
153	[control setMenu: menu];
154
155	[view addSubview: control];
156	[control setFrame: NSMakeRect(x, y, w, h)];
157
158	if (out != NULL)
159		*out = control;
160}
161