1/* GormDocumentController.m 2 * 3 * This class is a subclass of the NSDocumentController 4 * 5 * Copyright (C) 2006 Free Software Foundation, Inc. 6 * 7 * Author: Gregory John Casamento <greg_casamento@yahoo.com> 8 * Date: 2006 9 * 10 * This file is part of GNUstep. 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 3 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. 25 */ 26 27#include "GormPrivate.h" 28#include <GormCore/GormDocument.h> 29#include <GormCore/GormDocumentController.h> 30 31@implementation GormDocumentController 32 33- (id) currentDocument 34{ 35 NSArray *documents = [self documents]; 36 unsigned i = [documents count]; 37 id result = nil; 38 39 if (i > 0) 40 { 41 while (i-- > 0) 42 { 43 id doc = [documents objectAtIndex: i]; 44 if ([doc isActive] == YES) 45 { 46 result = doc; 47 break; 48 } 49 } 50 } 51 52 return result; 53} 54 55- (void) buildDocumentForType: (GormDocumentType)documentType 56{ 57 GormDocument *doc = nil; 58 59 NSDebugLog(@"In gorm document controller..."); 60 doc = (GormDocument *)[[self documents] lastObject]; // get the latest document... 61 62 switch (documentType) 63 { 64 case GormApplication: 65 { 66 NSMenu *aMenu; 67 NSWindow *aWindow; 68 NSRect frame = [[NSScreen mainScreen] frame]; 69 unsigned style = NSTitledWindowMask | NSClosableWindowMask 70 | NSResizableWindowMask | NSMiniaturizableWindowMask; 71 72 if ([NSMenu respondsToSelector: @selector(allocSubstitute)]) 73 { 74 aMenu = [[NSMenu allocSubstitute] init]; 75 } 76 else 77 { 78 aMenu = [[NSMenu alloc] init]; 79 } 80 81 if ([NSWindow respondsToSelector: @selector(allocSubstitute)]) 82 { 83 aWindow = [[NSWindow allocSubstitute] 84 initWithContentRect: NSMakeRect(0,0,600, 400) 85 styleMask: style 86 backing: NSBackingStoreBuffered 87 defer: NO]; 88 } 89 else 90 { 91 aWindow = [[NSWindow alloc] 92 initWithContentRect: NSMakeRect(0,0,600, 400) 93 styleMask: style 94 backing: NSBackingStoreBuffered 95 defer: NO]; 96 } 97 [aWindow setFrameTopLeftPoint: 98 NSMakePoint(230, frame.size.height-100)]; 99 [aWindow setTitle: _(@"My Window")]; 100 [doc setName: @"My Window" forObject: aWindow]; 101 [doc attachObject: aWindow toParent: nil]; 102 [doc setObject: aWindow isVisibleAtLaunch: YES]; 103 104 [aMenu setTitle: _(@"Main Menu")]; 105 [aMenu addItemWithTitle: _(@"Hide") 106 action: @selector(hide:) 107 keyEquivalent: @"h"]; 108 [aMenu addItemWithTitle: _(@"Quit") 109 action: @selector(terminate:) 110 keyEquivalent: @"q"]; 111 112 // the first menu attached becomes the main menu. 113 [doc attachObject: aMenu toParent: nil]; 114 } 115 break; 116 case GormInspector: 117 { 118 NSPanel *aWindow; 119 NSRect frame = [[NSScreen mainScreen] frame]; 120 unsigned style = NSTitledWindowMask | NSClosableWindowMask; 121 122 if ([NSPanel respondsToSelector: @selector(allocSubstitute)]) 123 { 124 aWindow = [[NSPanel allocSubstitute] 125 initWithContentRect: NSMakeRect(0,0, IVW, IVH) 126 styleMask: style 127 backing: NSBackingStoreBuffered 128 defer: NO]; 129 } 130 else 131 { 132 aWindow = [[NSPanel alloc] 133 initWithContentRect: NSMakeRect(0,0, IVW, IVH) 134 styleMask: style 135 backing: NSBackingStoreBuffered 136 defer: NO]; 137 } 138 139 [aWindow setFrameTopLeftPoint: 140 NSMakePoint(230, frame.size.height-100)]; 141 [aWindow setTitle: _(@"Inspector Window")]; 142 [doc setName: @"InspectorWin" forObject: aWindow]; 143 [doc attachObject: aWindow toParent: nil]; 144 } 145 break; 146 case GormPalette: 147 { 148 NSPanel *aWindow; 149 NSRect frame = [[NSScreen mainScreen] frame]; 150 unsigned style = NSTitledWindowMask | NSClosableWindowMask; 151 152 if ([NSPanel respondsToSelector: @selector(allocSubstitute)]) 153 { 154 aWindow = [[NSPanel allocSubstitute] 155 initWithContentRect: NSMakeRect(0,0,272,160) 156 styleMask: style 157 backing: NSBackingStoreBuffered 158 defer: NO]; 159 } 160 else 161 { 162 aWindow = [[NSPanel alloc] 163 initWithContentRect: NSMakeRect(0,0,272,160) 164 styleMask: style 165 backing: NSBackingStoreBuffered 166 defer: NO]; 167 } 168 169 [aWindow setFrameTopLeftPoint: 170 NSMakePoint(230, frame.size.height-100)]; 171 [aWindow setTitle: _(@"Palette Window")]; 172 [doc setName: @"PaletteWin" forObject: aWindow]; 173 [doc attachObject: aWindow toParent: nil]; 174 } 175 break; 176 case GormEmpty: 177 { 178 // nothing to do... 179 } 180 break; 181 default: 182 { 183 NSLog(@"Unknown document type..."); 184 } 185 } 186 187 // set the filetype and touch the document. 188 [doc setFileType: @"GSGormFileType"]; 189} 190 191- (void) newDocument: (id)sender 192{ 193 GormDocumentType documentType = GormApplication; 194 195 if([sender respondsToSelector: @selector(tag)]) 196 { 197 documentType = (GormDocumentType)[sender tag]; 198 } 199 200 [super newDocument: sender]; 201 [self buildDocumentForType: documentType]; 202} 203 204- (id) openDocumentWithContentsOfURL:(NSURL *)url 205{ 206 return [self openDocumentWithContentsOfURL:url display:YES]; 207} 208@end 209