2010-07-18 08:00:12 +00:00
|
|
|
/*
|
|
|
|
** iwadpicker_cocoa.mm
|
|
|
|
**
|
|
|
|
** Implements Mac OS X native IWAD Picker.
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2010 Braden Obrzut
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d_main.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_IWAD,
|
|
|
|
COLUMN_GAME,
|
|
|
|
|
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const tableHeaders[NUM_COLUMNS] = { "IWAD", "Game" };
|
|
|
|
|
|
|
|
// Class to convert the IWAD data into a form that Cocoa can use.
|
2010-11-11 00:22:36 +00:00
|
|
|
@interface IWADTableData : NSObject// <NSTableViewDataSource>
|
2010-07-18 08:00:12 +00:00
|
|
|
{
|
|
|
|
NSMutableArray *data;
|
|
|
|
}
|
|
|
|
|
2010-07-18 09:23:33 +00:00
|
|
|
- (void)dealloc;
|
2010-07-18 08:00:12 +00:00
|
|
|
- (IWADTableData *)init:(WadStuff *) wads:(int) numwads;
|
|
|
|
|
|
|
|
- (int)numberOfRowsInTableView:(NSTableView *)aTableView;
|
|
|
|
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation IWADTableData
|
|
|
|
|
2010-07-18 09:23:33 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[data release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2010-07-18 08:00:12 +00:00
|
|
|
- (IWADTableData *)init:(WadStuff *) wads:(int) numwads
|
|
|
|
{
|
|
|
|
data = [[NSMutableArray alloc] initWithCapacity:numwads];
|
|
|
|
|
|
|
|
for(int i = 0;i < numwads;i++)
|
|
|
|
{
|
|
|
|
NSMutableDictionary *record = [[NSMutableDictionary alloc] initWithCapacity:NUM_COLUMNS];
|
|
|
|
const char* filename = strrchr(wads[i].Path, '/');
|
|
|
|
if(filename == NULL)
|
|
|
|
filename = wads[i].Path;
|
|
|
|
else
|
|
|
|
filename++;
|
2010-11-10 23:39:34 +00:00
|
|
|
[record setObject:[NSString stringWithUTF8String:filename] forKey:[NSString stringWithUTF8String:tableHeaders[COLUMN_IWAD]]];
|
|
|
|
[record setObject:[NSString stringWithUTF8String:wads[i].Name] forKey:[NSString stringWithUTF8String:tableHeaders[COLUMN_GAME]]];
|
2010-07-18 08:00:12 +00:00
|
|
|
[data addObject:record];
|
2010-07-18 09:23:33 +00:00
|
|
|
[record release];
|
2010-07-18 08:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
|
|
|
|
{
|
|
|
|
return [data count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
|
|
|
|
{
|
|
|
|
NSParameterAssert(rowIndex >= 0 && (unsigned int) rowIndex < [data count]);
|
|
|
|
NSMutableDictionary *record = [data objectAtIndex:rowIndex];
|
|
|
|
return [record objectForKey:[aTableColumn identifier]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// So we can listen for button actions and such we need to have an Obj-C class.
|
2010-07-18 09:23:33 +00:00
|
|
|
@interface IWADPicker : NSObject
|
2010-07-18 08:00:12 +00:00
|
|
|
{
|
|
|
|
NSApplication *app;
|
|
|
|
NSWindow *window;
|
|
|
|
NSButton *okButton;
|
|
|
|
NSButton *cancelButton;
|
|
|
|
bool cancelled;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)buttonPressed:(id) sender;
|
2010-08-13 00:08:51 +00:00
|
|
|
- (void)doubleClicked:(id) sender;
|
2010-07-18 08:00:12 +00:00
|
|
|
- (void)makeLabel:(NSTextField *)label:(const char*) str;
|
|
|
|
- (int)pickIWad:(WadStuff *)wads:(int) numwads:(bool) showwin:(int) defaultiwad;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation IWADPicker
|
|
|
|
|
|
|
|
- (void)buttonPressed:(id) sender;
|
|
|
|
{
|
|
|
|
if(sender == cancelButton)
|
|
|
|
cancelled = true;
|
|
|
|
|
|
|
|
[window orderOut:self];
|
|
|
|
[app stopModal];
|
|
|
|
}
|
|
|
|
|
2010-08-13 00:08:51 +00:00
|
|
|
- (void)doubleClicked:(id) sender;
|
|
|
|
{
|
|
|
|
if ([sender clickedRow] >= 0)
|
|
|
|
{
|
|
|
|
[window orderOut:self];
|
|
|
|
[app stopModal];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-18 08:00:12 +00:00
|
|
|
// Apparently labels in Cocoa are uneditable text fields, so lets make this a
|
|
|
|
// little more automated.
|
|
|
|
- (void)makeLabel:(NSTextField *)label:(const char*) str
|
|
|
|
{
|
2010-11-10 23:39:34 +00:00
|
|
|
[label setStringValue:[NSString stringWithUTF8String:str]];
|
2010-07-18 08:00:12 +00:00
|
|
|
[label setBezeled:NO];
|
|
|
|
[label setDrawsBackground:NO];
|
|
|
|
[label setEditable:NO];
|
|
|
|
[label setSelectable:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)pickIWad:(WadStuff *)wads:(int) numwads:(bool) showwin:(int) defaultiwad
|
|
|
|
{
|
|
|
|
cancelled = false;
|
|
|
|
|
|
|
|
app = [NSApplication sharedApplication];
|
2013-06-28 08:02:55 +00:00
|
|
|
id windowTitle = [NSString stringWithFormat:@"%s %s", GAMESIG, GetVersionString()];
|
2010-07-18 08:00:12 +00:00
|
|
|
|
2010-08-13 00:08:51 +00:00
|
|
|
NSRect frame = NSMakeRect(0, 0, 440, 450);
|
2010-07-18 08:00:12 +00:00
|
|
|
window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
|
|
|
|
[window setTitle:windowTitle];
|
|
|
|
|
2010-08-13 00:08:51 +00:00
|
|
|
NSTextField *description = [[NSTextField alloc] initWithFrame:NSMakeRect(22, 379, 412, 50)];
|
2013-06-28 08:02:55 +00:00
|
|
|
[self makeLabel:description:"GZDoom found more than one IWAD\nSelect from the list below to determine which one to use:"];
|
2010-07-18 08:00:12 +00:00
|
|
|
[[window contentView] addSubview:description];
|
2010-07-18 09:23:33 +00:00
|
|
|
[description release];
|
2010-07-18 08:00:12 +00:00
|
|
|
|
|
|
|
// Commented out version would account for an additional parameters box.
|
2010-08-13 00:08:51 +00:00
|
|
|
//NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 103, 412, 288)];
|
|
|
|
NSScrollView *iwadScroller = [[NSScrollView alloc] initWithFrame:NSMakeRect(20, 50, 412, 341)];
|
2010-07-18 08:00:12 +00:00
|
|
|
NSTableView *iwadTable = [[NSTableView alloc] initWithFrame:[iwadScroller bounds]];
|
|
|
|
IWADTableData *tableData = [[IWADTableData alloc] init:wads:numwads];
|
|
|
|
for(int i = 0;i < NUM_COLUMNS;i++)
|
|
|
|
{
|
2010-11-10 23:39:34 +00:00
|
|
|
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:[NSString stringWithUTF8String:tableHeaders[i]]];
|
2010-07-18 08:00:12 +00:00
|
|
|
[[column headerCell] setStringValue:[column identifier]];
|
|
|
|
if(i == 0)
|
|
|
|
[column setMaxWidth:110];
|
|
|
|
[column setEditable:NO];
|
|
|
|
[column setResizingMask:NSTableColumnAutoresizingMask];
|
|
|
|
[iwadTable addTableColumn:column];
|
2010-07-18 09:23:33 +00:00
|
|
|
[column release];
|
2010-07-18 08:00:12 +00:00
|
|
|
}
|
|
|
|
[iwadScroller setDocumentView:iwadTable];
|
|
|
|
[iwadScroller setHasVerticalScroller:YES];
|
|
|
|
[iwadTable setDataSource:tableData];
|
|
|
|
[iwadTable sizeToFit];
|
2010-08-13 00:08:51 +00:00
|
|
|
[iwadTable setDoubleAction:@selector(doubleClicked:)];
|
|
|
|
[iwadTable setTarget:self];
|
2010-07-18 09:23:33 +00:00
|
|
|
NSIndexSet *selection = [[NSIndexSet alloc] initWithIndex:defaultiwad];
|
|
|
|
[iwadTable selectRowIndexes:selection byExtendingSelection:NO];
|
|
|
|
[selection release];
|
2010-07-18 08:00:12 +00:00
|
|
|
[iwadTable scrollRowToVisible:defaultiwad];
|
|
|
|
[[window contentView] addSubview:iwadScroller];
|
2010-07-18 09:23:33 +00:00
|
|
|
[iwadTable release];
|
|
|
|
[iwadScroller release];
|
2010-07-18 08:00:12 +00:00
|
|
|
|
|
|
|
/*NSTextField *additionalParametersLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(17, 78, 144, 17)];
|
|
|
|
[self makeLabel:additionalParametersLabel:"Additional Parameters"];
|
|
|
|
[[window contentView] addSubview:additionalParametersLabel];
|
|
|
|
NSTextField *additionalParameters = [[NSTextField alloc] initWithFrame:NSMakeRect(20, 48, 360, 22)];
|
|
|
|
[[window contentView] addSubview:additionalParameters];*/
|
|
|
|
|
|
|
|
// Doesn't look like the SDL version implements this so lets not show it.
|
|
|
|
/*NSButton *dontAsk = [[NSButton alloc] initWithFrame:NSMakeRect(18, 18, 178, 18)];
|
|
|
|
[dontAsk setTitle:[NSString stringWithCString:"Don't ask me this again"]];
|
|
|
|
[dontAsk setButtonType:NSSwitchButton];
|
|
|
|
[dontAsk setState:(showwin ? NSOffState : NSOnState)];
|
|
|
|
[[window contentView] addSubview:dontAsk];*/
|
|
|
|
|
2010-08-13 00:08:51 +00:00
|
|
|
okButton = [[NSButton alloc] initWithFrame:NSMakeRect(236, 12, 96, 32)];
|
2010-11-10 23:39:34 +00:00
|
|
|
[okButton setTitle:[NSString stringWithUTF8String:"OK"]];
|
2010-07-18 08:00:12 +00:00
|
|
|
[okButton setBezelStyle:NSRoundedBezelStyle];
|
|
|
|
[okButton setAction:@selector(buttonPressed:)];
|
|
|
|
[okButton setTarget:self];
|
2010-08-13 00:08:51 +00:00
|
|
|
[okButton setKeyEquivalent:@"\r"];
|
2010-07-18 08:00:12 +00:00
|
|
|
[[window contentView] addSubview:okButton];
|
|
|
|
|
2010-08-13 00:08:51 +00:00
|
|
|
cancelButton = [[NSButton alloc] initWithFrame:NSMakeRect(332, 12, 96, 32)];
|
2010-11-10 23:39:34 +00:00
|
|
|
[cancelButton setTitle:[NSString stringWithUTF8String:"Cancel"]];
|
2010-07-18 08:00:12 +00:00
|
|
|
[cancelButton setBezelStyle:NSRoundedBezelStyle];
|
|
|
|
[cancelButton setAction:@selector(buttonPressed:)];
|
|
|
|
[cancelButton setTarget:self];
|
2010-08-13 00:08:51 +00:00
|
|
|
[cancelButton setKeyEquivalent:@"\033"];
|
2010-07-18 08:00:12 +00:00
|
|
|
[[window contentView] addSubview:cancelButton];
|
|
|
|
|
|
|
|
[window center];
|
|
|
|
[app runModalForWindow:window];
|
|
|
|
|
2010-07-18 09:23:33 +00:00
|
|
|
[window release];
|
|
|
|
[okButton release];
|
|
|
|
[cancelButton release];
|
|
|
|
|
2010-07-18 08:00:12 +00:00
|
|
|
return cancelled ? -1 : [iwadTable selectedRow];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Simple wrapper so we can call this from outside.
|
|
|
|
int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad)
|
|
|
|
{
|
2010-07-18 09:23:33 +00:00
|
|
|
IWADPicker *picker = [IWADPicker alloc];
|
|
|
|
int ret = [picker pickIWad:wads:numwads:showwin:defaultiwad];
|
|
|
|
[picker release];
|
|
|
|
return ret;
|
2010-07-18 08:00:12 +00:00
|
|
|
}
|