2002-06-02 21:00:34 +00:00
|
|
|
/* GSNamedColorPicker.m
|
|
|
|
|
|
|
|
Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
Date: January 2001
|
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
2002-06-02 21:00:34 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2002-06-02 21:00:34 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-13 15:26:20 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <AppKit/AppKit.h>
|
2002-06-02 21:00:34 +00:00
|
|
|
|
2012-06-28 19:44:50 +00:00
|
|
|
@interface GSNamedColorPicker: NSColorPicker <NSColorPickingCustom, NSTextFieldDelegate>
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
NSView *baseView;
|
|
|
|
NSComboBox *cb;
|
|
|
|
NSBrowser *browser;
|
|
|
|
NSColorList *currentList;
|
2003-07-26 13:27:19 +00:00
|
|
|
NSMutableArray *lists;
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) loadViews;
|
|
|
|
- (void) listSelected: (int)index;
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) colorSelected: (id)sender;
|
2002-06-02 21:00:34 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSNamedColorPicker
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (id) initWithPickerMask: (int)aMask
|
|
|
|
colorPanel: (NSColorPanel *)colorPanel
|
|
|
|
{
|
|
|
|
if (aMask & NSColorPanelColorListModeMask)
|
|
|
|
{
|
2011-03-14 22:59:20 +00:00
|
|
|
self = [super initWithPickerMask: aMask
|
2003-07-26 13:27:19 +00:00
|
|
|
colorPanel: colorPanel];
|
2011-03-14 22:59:20 +00:00
|
|
|
if (nil == self)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
lists = [[NSColorList availableColorLists] mutableCopy];
|
|
|
|
return self;
|
2003-07-26 13:27:19 +00:00
|
|
|
}
|
|
|
|
RELEASE(self);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2002-06-02 21:00:34 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(cb);
|
|
|
|
RELEASE(browser);
|
|
|
|
RELEASE(baseView);
|
|
|
|
RELEASE(lists);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) finishInstantiate
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) attachColorList: (NSColorList *)colorList
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
2003-07-26 13:27:19 +00:00
|
|
|
[lists addObject: colorList];
|
|
|
|
[cb noteNumberOfItemsChanged];
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) detachColorList: (NSColorList *)colorList
|
|
|
|
{
|
|
|
|
[lists removeObjectIdenticalTo: colorList];
|
|
|
|
[cb noteNumberOfItemsChanged];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) currentMode
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return NSColorListModeColorPanel;
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (BOOL) supportsMode: (int)mode
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return mode == NSColorListModeColorPanel;
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (NSView *) provideNewView: (BOOL)initialRequest
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
if (initialRequest)
|
|
|
|
{
|
|
|
|
[self loadViews];
|
|
|
|
}
|
|
|
|
return baseView;
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) setColor: (NSColor *)color
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
NSColor *c = [color colorUsingColorSpaceName: NSNamedColorSpace];
|
|
|
|
NSString *list;
|
|
|
|
NSString *name;
|
2011-12-17 17:16:09 +00:00
|
|
|
NSUInteger index;
|
2002-06-02 21:00:34 +00:00
|
|
|
|
|
|
|
if (c == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list = [c catalogNameComponent];
|
|
|
|
name = [c colorNameComponent];
|
2011-03-13 15:26:20 +00:00
|
|
|
// Select the correspondig entries in the lists
|
|
|
|
index = [self comboBox: cb
|
|
|
|
indexOfItemWithStringValue: list];
|
|
|
|
if (index == NSNotFound)
|
|
|
|
return;
|
|
|
|
[cb selectItemAtIndex: index];
|
|
|
|
|
|
|
|
index = [[currentList allKeys] indexOfObject: name];
|
|
|
|
if (index == NSNotFound)
|
|
|
|
return;
|
|
|
|
[browser selectRow: index inColumn: 0];
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) loadViews
|
|
|
|
{
|
|
|
|
baseView = [[NSView alloc] initWithFrame: NSMakeRect(0, 0, 200, 110)];
|
|
|
|
[baseView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
|
|
|
|
|
|
|
cb = [[NSComboBox alloc] initWithFrame: NSMakeRect(0, 85, 196, 20)];
|
|
|
|
[cb setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)];
|
|
|
|
[cb setUsesDataSource: YES];
|
|
|
|
[cb setDataSource: self];
|
|
|
|
[cb setDelegate: self];
|
|
|
|
[cb setEditable: NO];
|
|
|
|
[baseView addSubview: cb];
|
|
|
|
|
|
|
|
browser = [[NSBrowser alloc] initWithFrame: NSMakeRect(0, 5, 196, 75)];
|
|
|
|
[browser setDelegate: self];
|
|
|
|
[browser setMaxVisibleColumns: 1];
|
|
|
|
[browser setAllowsMultipleSelection: NO];
|
|
|
|
[browser setAllowsEmptySelection: NO];
|
|
|
|
[browser setHasHorizontalScroller: NO];
|
|
|
|
[browser setTitled: NO];
|
|
|
|
[browser setTakesTitleFromPreviousColumn: NO];
|
|
|
|
[browser setPath: @"/"];
|
|
|
|
[browser setTarget: self];
|
|
|
|
[browser setDoubleAction: @selector(colorSelected:)];
|
|
|
|
[browser setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
|
|
|
[baseView addSubview: browser];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) listSelected: (int)index
|
|
|
|
{
|
|
|
|
currentList = [lists objectAtIndex: index];
|
2003-07-26 13:27:19 +00:00
|
|
|
[browser loadColumnZero];
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) colorSelected: (id)sender
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
2003-07-26 13:27:19 +00:00
|
|
|
NSCell *aCell;
|
|
|
|
NSColor *col;
|
|
|
|
|
|
|
|
aCell = [sender selectedCell];
|
|
|
|
col = [aCell representedObject];
|
|
|
|
[_colorPanel setColor: col];
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
-(NSString *) browser: (NSBrowser *)sender
|
2013-08-09 14:24:48 +00:00
|
|
|
titleOfColumn: (NSInteger)column
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
-(void) browser: (NSBrowser *)sender
|
2013-08-09 14:24:48 +00:00
|
|
|
createRowsForColumn: (NSInteger)column
|
2003-07-26 13:27:19 +00:00
|
|
|
inMatrix: (NSMatrix *)matrix
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
NSBrowserCell *cell;
|
|
|
|
NSColor *cl;
|
|
|
|
NSArray *keys = [currentList allKeys];
|
|
|
|
NSString *name;
|
|
|
|
|
|
|
|
count = [keys count];
|
2003-07-26 13:27:19 +00:00
|
|
|
//NSLog(@"In create with %@ %d", currentList, count);
|
2002-06-02 21:00:34 +00:00
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
[matrix addColumn];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
[matrix addRow];
|
|
|
|
name = [keys objectAtIndex: i];
|
2003-07-26 13:27:19 +00:00
|
|
|
//cl = [currentList colorWithKey: name];
|
|
|
|
cl = [NSColor colorWithCatalogName: [currentList name]
|
|
|
|
colorName: name];
|
2002-06-02 21:00:34 +00:00
|
|
|
cell = [matrix cellAtRow: i
|
|
|
|
column: 0];
|
|
|
|
[cell setStringValue: name];
|
|
|
|
[cell setRepresentedObject: cl];
|
|
|
|
[cell setLeaf: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) browser: (NSBrowser*)sender
|
2013-08-09 14:24:48 +00:00
|
|
|
selectRow: (NSInteger)row
|
|
|
|
inColumn: (NSInteger)column
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
2006-04-30 08:29:58 +00:00
|
|
|
return NO;
|
2002-06-02 21:00:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) browser: (NSBrowser *)sender
|
|
|
|
willDisplayCell: (id)cell
|
2013-08-09 14:24:48 +00:00
|
|
|
atRow: (NSInteger)row
|
|
|
|
column: (NSInteger)column
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-09 14:24:48 +00:00
|
|
|
- (NSInteger) numberOfItemsInComboBox: (NSComboBox *)aComboBox
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return [lists count];
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (id) comboBox: (NSComboBox *)aComboBox
|
2013-08-09 14:24:48 +00:00
|
|
|
objectValueForItemAtIndex: (NSInteger)index
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return [(NSColorList*)[lists objectAtIndex: index] name];
|
|
|
|
}
|
|
|
|
|
2013-08-09 14:24:48 +00:00
|
|
|
- (NSUInteger) comboBox: (NSComboBox *)aComboBox
|
2003-07-26 13:27:19 +00:00
|
|
|
indexOfItemWithStringValue: (NSString *)string
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
return [lists indexOfObject: [NSColorList colorListNamed: string]];
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:27:19 +00:00
|
|
|
- (void) comboBoxSelectionDidChange: (NSNotification *)notification
|
2002-06-02 21:00:34 +00:00
|
|
|
{
|
|
|
|
[self listSelected: [cb indexOfSelectedItem]];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|