/* This file is part of "psdrecover", a File Format plugin for Adobe Photoshop Copyright (C) 2011 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Loosely based on Dissolve sample plugin, CS5 SDK #ifdef __x86_64__ #import "PsdExtractChooseLayerController.h" #include "../psdrecover.h" #include "../ui.h" extern int *layermap; @implementation PsdExtractChooseLayerController - (id) init { self = [super init]; // initialize NSApplication, using an entry point that is specific to // bundles this is a no-op for Cocoa apps, but is required by Carbon apps //NSApplicationLoad(); if (![NSBundle loadNibNamed:@"PsdExtractChooseLayer" owner:self]) NSLog(@"failed to load PsdExtractChooseLayer xib"); return self; } - (int) showWindow { extern struct psd_header header; char s[0x100]; int i, j; // set up the dialog contents [promptField setStringValue: [NSString stringWithFormat:@"The file contains %d layer%s.", header.nlayers, header.nlayers > 1 ? "s" : ""]]; [layersPopup removeAllItems]; [layersPopup addItemWithTitle:@"Merged image"]; layermap = malloc(header.nlayers*sizeof(int)); layermap[0] = 0; j = 1; for(i = 0; i < header.nlayers; ++i){ psd_pixels_t w = header.linfo[i].right - header.linfo[i].left, h = header.linfo[i].bottom - header.linfo[i].top; // skip layers with zero width or height if(w && h){ sprintf(s,"Layer %d: \"%s\" (%u x %u)", i+1, header.linfo[i].name, w, h); [layersPopup addItemWithTitle:[NSString stringWithCString:s]]; layermap[j++] = i+1; } } int b = [[NSApplication sharedApplication] runModalForWindow:pickLayerWindow]; [pickLayerWindow orderOut:self]; free(layermap); return b; } - (IBAction)pickLayer:(id)sender { whichlayer = layermap[ [layersPopup indexOfSelectedItem] ]; } - (IBAction)okAction:(id)sender { [[NSApplication sharedApplication] stopModalWithCode:1]; } - (IBAction)cancelAction:(id)sender { [[NSApplication sharedApplication] stopModalWithCode:0]; } @end static PsdExtractChooseLayerController *gController = NULL; Boolean picklayerdialog(FormatRecordPtr pb){ if(!gController) gController = [[PsdExtractChooseLayerController alloc] init]; return [gController showWindow]; } #endif