1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/* BrowserViewerPref.m
*
* Copyright (C) 2003-2016 Free Software Foundation, Inc.
*
* Author: Enrico Sersale <enrico@imago.ro>
* Date: August 2001
*
* This file is part of the GNUstep GWorkspace application
*
* 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., 31 Milk Street #960789 Boston, MA 02196 USA.
*/
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <GNUstepBase/GNUstep.h>
#import "BrowserViewerPref.h"
#define RESIZER_W 16
#define RESIZER_Y 48
#define MINIMUM_WIDTH 120
#define DEFAULT_WIDTH 150
#define MAXIMUM_WIDTH 362
static NSString *nibName = @"BrowserViewerPref";
@implementation Resizer
- (void)dealloc
{
RELEASE (arrow);
[super dealloc];
}
- (id)initForController:(id)acontroller
{
self = [super init];
[self setFrame: NSMakeRect(0, 0, RESIZER_W, RESIZER_W)];
controller = acontroller;
ASSIGN (arrow, [NSImage imageNamed: @"RightArr.tiff"]);
return self;
}
- (void)mouseDown:(NSEvent *)theEvent
{
[controller mouseDownOnResizer: theEvent];
}
- (void)drawRect:(NSRect)rect
{
[super drawRect: rect];
[arrow compositeToPoint: NSZeroPoint operation: NSCompositeSourceOver];
}
@end
@implementation BrowserViewerPref
- (void)dealloc
{
RELEASE (colExample);
RELEASE (prefbox);
[super dealloc];
}
- (id)init
{
self = [super init];
if (self)
{
if ([NSBundle loadNibNamed: nibName owner: self] == NO)
{
NSLog(@"failed to load %@!", nibName);
}
else
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *widthStr = [defaults objectForKey: @"browserColsWidth"];
RETAIN (prefbox);
RELEASE (win);
if (widthStr)
columnsWidth = [widthStr intValue];
else
columnsWidth = DEFAULT_WIDTH;
[colExample setBorderType: NSBezelBorder];
[colExample setHasHorizontalScroller: NO];
[colExample setHasVerticalScroller: YES];
resizer = [[Resizer alloc] initForController: self];
[resizer setFrame: NSMakeRect(0, 0, RESIZER_W, RESIZER_W)];
[resizerBox setContentView: resizer];
[self tile];
/* Internationalization */
[controlsbox setTitle: NSLocalizedString(@"Column Width", @"")];
[setButt setTitle: NSLocalizedString(@"Use Default Settings", @"")];
}
}
return self;
}
- (NSView *)prefView
{
return prefbox;
}
- (NSString *)prefName
{
return NSLocalizedString(@"Browser", @"");
}
- (void)tile
{
NSRect frameRect;
frameRect = [colExample frame];
frameRect.size.width = columnsWidth;
[colExample setFrame: frameRect];
[resizerBox setFrameOrigin: NSMakePoint(columnsWidth + frameRect.origin.x, RESIZER_Y)];
[controlsbox setNeedsDisplay: YES];
}
- (void)mouseDownOnResizer:(NSEvent *)theEvent
{
NSApplication *app = [NSApplication sharedApplication];
int orx = (int)[controlsbox convertPoint: [theEvent locationInWindow] fromView: nil].x;
NSUInteger eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
int newWidth = (int)[colExample bounds].size.width;
NSEvent *e;
[controlsbox lockFocus];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
e = [app nextEventMatchingMask: eventMask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
while ([e type] != NSLeftMouseUp)
{
int x = (int)[controlsbox convertPoint: [e locationInWindow] fromView: nil].x;
int diff = x - orx;
if ((newWidth + diff < MAXIMUM_WIDTH) && (newWidth + diff > MINIMUM_WIDTH))
{
NSRect frameExample;
frameExample = [colExample frame];
newWidth += diff;
[resizerBox setFrameOrigin: NSMakePoint(frameExample.origin.x + newWidth, RESIZER_Y)];
[resizerBox setNeedsDisplay: YES];
frameExample.size.width = newWidth;
[colExample setFrame: frameExample];
[colExample setNeedsDisplay: YES];
[controlsbox setNeedsDisplay: YES];
orx = x;
}
e = [app nextEventMatchingMask: eventMask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
[controlsbox unlockFocus];
[self setNewWidth: (int)[colExample bounds].size.width];
[setButt setEnabled: YES];
}
- (void)setNewWidth:(int)w
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: [NSString stringWithFormat: @"%i", w]
forKey: @"browserColsWidth"];
columnsWidth = w;
[[NSNotificationCenter defaultCenter]
postNotificationName: @"GWBrowserColumnWidthChangedNotification"
object: [NSNumber numberWithInt: w]];
[defaults synchronize];
}
- (IBAction)setDefaultWidth:(id)sender
{
columnsWidth = DEFAULT_WIDTH;
[self setNewWidth: columnsWidth];
[self tile];
[setButt setEnabled: NO];
}
@end
|