1/* DesktopPref.m 2 * 3 * Copyright (C) 2005-2016 Free Software Foundation, Inc. 4 * 5 * Author: Enrico Sersale <enrico@imago.ro> 6 * Riccardo Mottola <rm@gnu.org> 7 * Date: January 2005 8 * 9 * This file is part of the GNUstep GWorkspace application 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. 24 */ 25 26#import <Foundation/Foundation.h> 27#import <AppKit/AppKit.h> 28#import "DesktopPref.h" 29#import "GWDesktopManager.h" 30#import "GWorkspace.h" 31#import "GWDesktopView.h" 32#import "Dock.h" 33#import "TShelf/TShelfWin.h" 34 35static NSString *nibName = @"DesktopPref"; 36 37@implementation DesktopPref 38 39- (void)dealloc 40{ 41 RELEASE (prefbox); 42 RELEASE (imagePath); 43 RELEASE (imagesDir); 44 45 [super dealloc]; 46} 47 48- (id)init 49{ 50 self = [super init]; 51 52 if (self) 53 { 54 if ([NSBundle loadNibNamed: nibName owner: self] == NO) 55 { 56 NSLog(@"failed to load %@!", nibName); 57 } 58 else 59 { 60 NSString *impath; 61 DockPosition dockpos; 62 DockStyle dockstyle; 63 id cell; 64 65 RETAIN (prefbox); 66 RELEASE (win); 67 68 manager = [GWDesktopManager desktopManager]; 69 gworkspace = [GWorkspace gworkspace]; 70 71 // Color 72 [NSColorPanel setPickerMask: NSColorPanelWheelModeMask 73 | NSColorPanelRGBModeMask 74 | NSColorPanelColorListModeMask]; 75 [NSColorPanel setPickerMode: NSWheelModeColorPanel]; 76 [colorWell setColor: [[manager desktopView] currentColor]]; 77 78 // Background image 79 [imageView setEditable: NO]; 80 [imageView setImageScaling: NSScaleProportionally]; 81 82 impath = [[manager desktopView] backImagePath]; 83 if (impath) { 84 ASSIGN (imagePath, impath); 85 } 86 87 if (imagePath) 88 { 89 CREATE_AUTORELEASE_POOL (pool); 90 NSImage *image = [[NSImage alloc] initWithContentsOfFile: imagePath]; 91 92 if (image) 93 { 94 [imageView setImage: image]; 95 RELEASE (image); 96 } 97 RELEASE (pool); 98 } 99 100 [imagePosMatrix selectCellAtRow: [[manager desktopView] backImageStyle] column: 0]; 101 102 BOOL useImage = [[manager desktopView] useBackImage]; 103 [imageView setEnabled: useImage]; 104 [chooseImageButt setEnabled: useImage]; 105 [imagePosMatrix setEnabled: useImage]; 106 [useImageSwitch setState: useImage ? NSOnState : NSOffState]; 107 108 // General 109 [omnipresentCheck setState: ([manager usesXBundle] ? NSOnState : NSOffState)]; 110 [useDockCheck setState: ([manager dockActive] ? NSOnState : NSOffState)]; 111 dockpos = [manager dockPosition]; 112 [dockPosMatrix selectCellAtRow: dockpos column: 0]; 113 dockstyle = [[manager dock] style]; 114 [dockStyleMatrix selectCellAtRow: dockstyle column: 0]; 115 [hideTShelfCheck setState: (([[gworkspace tabbedShelf] autohide]) ? NSOnState : NSOffState)]; 116 117 118 119 /* Internationalization */ 120 [[tabView tabViewItemAtIndex: 0] setLabel: NSLocalizedString(@"Background", @"")]; 121 [[tabView tabViewItemAtIndex: 1] setLabel: NSLocalizedString(@"General", @"")]; 122 123 [colorLabel setStringValue:_(@"Color:")]; 124 cell = [imagePosMatrix cellAtRow: BackImageCenterStyle column: 0]; 125 [cell setTitle: NSLocalizedString(@"center", @"")]; 126 cell = [imagePosMatrix cellAtRow: BackImageFitStyle column: 0]; 127 [cell setTitle: NSLocalizedString(@"fit", @"")]; 128 cell = [imagePosMatrix cellAtRow: BackImageTileStyle column: 0]; 129 [cell setTitle: NSLocalizedString(@"tile", @"")]; 130 cell = [imagePosMatrix cellAtRow: BackImageScaleStyle column: 0]; 131 [cell setTitle: NSLocalizedString(@"scale", @"")]; 132 [useImageSwitch setTitle: NSLocalizedString(@"Use image", @"")]; 133 [chooseImageButt setTitle: NSLocalizedString(@"Choose", @"")]; 134 135 [dockBox setTitle: _(@"Dock")]; 136 [useDockCheck setTitle: NSLocalizedString(@"Show Dock", @"")]; 137 [dockPosLabel setStringValue: NSLocalizedString(@"Position:", @"")]; 138 cell = [dockPosMatrix cellAtRow: 0 column: 0]; 139 [cell setTitle: NSLocalizedString(@"Left", @"")]; 140 cell = [dockPosMatrix cellAtRow: 1 column: 0]; 141 [cell setTitle: NSLocalizedString(@"Right", @"")]; 142 [dockStyleLabel setStringValue: NSLocalizedString(@"Style:", @"")]; 143 cell = [dockStyleMatrix cellAtRow: 0 column: 0]; 144 [cell setTitle: NSLocalizedString(@"Classic", @"")]; 145 cell = [dockStyleMatrix cellAtRow: 1 column: 0]; 146 [cell setTitle: NSLocalizedString(@"Modern", @"")]; 147 148 [omnipresentCheck setTitle: _(@"Omnipresent")]; 149 [hideTShelfCheck setTitle: NSLocalizedString(@"Autohide Tabbed Shelf", @"")]; 150 } 151 } 152 153 return self; 154} 155 156- (NSView *)prefView 157{ 158 return prefbox; 159} 160 161- (NSString *)prefName 162{ 163 return NSLocalizedString(@"Desktop", @""); 164} 165 166// Color 167 168- (IBAction)setColor:(id)sender 169{ 170 [[manager desktopView] setCurrentColor: [colorWell color]]; 171 [gworkspace tshelfBackgroundDidChange]; 172} 173 174 175// Background image 176- (IBAction)chooseImage:(id)sender 177{ 178 NSOpenPanel *openPanel; 179 NSInteger result; 180 181 openPanel = [NSOpenPanel openPanel]; 182 [openPanel setTitle: NSLocalizedString(@"Choose Image", @"")]; 183 [openPanel setAllowsMultipleSelection: NO]; 184 [openPanel setCanChooseFiles: YES]; 185 [openPanel setCanChooseDirectories: NO]; 186 187 if (imagesDir == nil) { 188 ASSIGN (imagesDir, NSHomeDirectory()); 189 } 190 191 result = [openPanel runModalForDirectory: imagesDir 192 file: nil 193 types: [NSImage imageFileTypes]]; 194 195 if (result == NSOKButton) { 196 CREATE_AUTORELEASE_POOL (pool); 197 NSString *impath = [openPanel filename]; 198 NSImage *image = [[NSImage alloc] initWithContentsOfFile: impath]; 199 200 if (image) { 201 [imageView setImage: image]; 202 ASSIGN (imagePath, impath); 203 ASSIGN (imagesDir, [imagePath stringByDeletingLastPathComponent]); 204 RELEASE (image); 205 } 206 207 RELEASE (pool); 208 } 209 210 if (imagePath) { 211 [[manager desktopView] setBackImageAtPath: imagePath]; 212 [imagePosMatrix selectCellAtRow: [[manager desktopView] backImageStyle] 213 column: 0]; 214 [gworkspace tshelfBackgroundDidChange]; 215 } 216} 217 218- (IBAction)setImage:(id)sender 219{ 220 // FIXME: Handle image dropped on image view? 221} 222 223- (IBAction)setImageStyle:(id)sender 224{ 225 id cell = [imagePosMatrix selectedCell]; 226 NSInteger row, col; 227 228 [imagePosMatrix getRow: &row column: &col ofCell: cell]; 229 [[manager desktopView] setBackImageStyle: row]; 230 [gworkspace tshelfBackgroundDidChange]; 231} 232 233- (IBAction)setUseImage:(id)sender 234{ 235 BOOL useImage = ([sender state] == NSOnState); 236 [[manager desktopView] setUseBackImage: useImage]; 237 [gworkspace tshelfBackgroundDidChange]; 238 [imageView setEnabled: useImage]; 239 [chooseImageButt setEnabled: useImage]; 240 [imagePosMatrix setEnabled: useImage]; 241} 242 243 244// General 245- (IBAction)setOmnipresent:(id)sender 246{ 247 [manager setUsesXBundle: ([sender state] == NSOnState)]; 248 if ([manager usesXBundle] == NO) { 249 [sender setState: NSOffState]; 250 } 251} 252 253- (IBAction)setUsesDock:(id)sender 254{ 255 [manager setDockActive: ([sender state] == NSOnState)]; 256} 257 258- (IBAction)setDockPosition:(id)sender 259{ 260 id cell = [dockPosMatrix selectedCell]; 261 NSInteger row, col; 262 263 [dockPosMatrix getRow: &row column: &col ofCell: cell]; 264 [manager setDockPosition: (row == 0) ? DockPositionLeft : DockPositionRight]; 265} 266 267- (IBAction)setDockStyle:(id)sender 268{ 269 id cell = [dockStyleMatrix selectedCell]; 270 NSInteger row, col; 271 272 [dockStyleMatrix getRow: &row column: &col ofCell: cell]; 273 [[manager dock] setStyle: (row == 0) ? DockStyleClassic : DockStyleModern]; 274} 275- (IBAction)setTShelfAutohide:(id)sender 276{ 277 [[gworkspace tabbedShelf] setAutohide: ([sender state] == NSOnState)]; 278} 279 280@end 281