2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSFontPanel</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
<abstract>System generic panel for selecting and previewing fonts</abstract>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
2000-02-22 17:49:28 +00:00
|
|
|
Date: Febuary 2000
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Nicola Pero <n.pero@mi.flashnet.it>
|
2001-01-27 00:03:42 +00:00
|
|
|
Date: January 2001 - sizings and resizings
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1996-05-30 20:03:15 +00:00
|
|
|
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
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
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.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
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.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
2003-07-31 23:52:10 +00:00
|
|
|
#include "config.h"
|
2011-03-04 11:33:22 +00:00
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import "AppKit/NSDragging.h"
|
|
|
|
#import "AppKit/NSFont.h"
|
|
|
|
#import "AppKit/NSFontPanel.h"
|
|
|
|
#import "AppKit/NSFontManager.h"
|
|
|
|
#import "AppKit/NSApplication.h"
|
|
|
|
#import "AppKit/NSSplitView.h"
|
|
|
|
#import "AppKit/NSScrollView.h"
|
|
|
|
#import "AppKit/NSBrowser.h"
|
|
|
|
#import "AppKit/NSBrowserCell.h"
|
|
|
|
#import "AppKit/NSTextView.h"
|
|
|
|
#import "AppKit/NSTextField.h"
|
|
|
|
#import "AppKit/NSTextFieldCell.h"
|
|
|
|
#import "AppKit/NSColor.h"
|
|
|
|
#import "AppKit/NSPanel.h"
|
|
|
|
#import "AppKit/NSButton.h"
|
|
|
|
#import "AppKit/NSBox.h"
|
2011-07-06 18:39:49 +00:00
|
|
|
#import "GNUstepGUI/GSCharacterPanel.h"
|
2011-03-04 11:33:22 +00:00
|
|
|
|
|
|
|
#import "GSGuiPrivate.h"
|
2010-01-03 18:35:25 +00:00
|
|
|
|
2003-06-10 01:26:56 +00:00
|
|
|
#define _SAVE_PANEL_X_PAD 5
|
|
|
|
#define _SAVE_PANEL_Y_PAD 4
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
static inline void _setFloatValue (NSTextField *field, float size)
|
|
|
|
{
|
|
|
|
/* If casting size to int and then back to float we get no change,
|
|
|
|
it means it's an integer */
|
|
|
|
if ((float)((int)size) == size)
|
|
|
|
{
|
|
|
|
/* We prefer using this if it's an int, so that it's
|
|
|
|
displayed like in `8' rather than like in
|
|
|
|
`8.0000000000'. Yes - when NSCell's formatters are
|
|
|
|
finished we won't need this. */
|
|
|
|
[field setIntValue: (int)size];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[field setFloatValue: size];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-22 14:33:41 +00:00
|
|
|
static NSText *sizeFieldText = nil;
|
2001-06-16 11:08:30 +00:00
|
|
|
|
2002-09-22 14:33:41 +00:00
|
|
|
static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
|
|
|
|
14.0, 16.0, 18.0, 24.0, 36.0, 48.0, 64.0};
|
2002-04-03 16:59:43 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
/* Implemented in NSBrowser */
|
|
|
|
@interface GSBrowserTitleCell : NSTextFieldCell
|
2002-04-03 16:59:43 +00:00
|
|
|
{
|
|
|
|
}
|
2001-01-27 00:03:42 +00:00
|
|
|
@end
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2024-10-03 16:21:53 +00:00
|
|
|
@interface FPBrowser : NSBrowser
|
|
|
|
@end
|
|
|
|
@implementation FPBrowser
|
|
|
|
|
|
|
|
static void
|
|
|
|
autoresize(CGFloat oldContainerSize, CGFloat newContainerSize,
|
|
|
|
CGFloat *contentPositionInOut, CGFloat *contentSizeInOut,
|
|
|
|
BOOL minMarginFlexible, BOOL sizeFlexible, BOOL maxMarginFlexible)
|
|
|
|
{
|
|
|
|
const CGFloat change = newContainerSize - oldContainerSize;
|
|
|
|
|
|
|
|
if (change == 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Size
|
|
|
|
if (sizeFlexible)
|
|
|
|
{
|
|
|
|
if (maxMarginFlexible || minMarginFlexible)
|
|
|
|
{
|
|
|
|
*contentSizeInOut += change / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*contentSizeInOut += change;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position
|
|
|
|
if (minMarginFlexible)
|
|
|
|
{
|
|
|
|
if (maxMarginFlexible || sizeFlexible)
|
|
|
|
{
|
|
|
|
*contentPositionInOut += change / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*contentPositionInOut += change;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
|
|
|
|
{
|
|
|
|
NSSize superViewFrameSize;
|
|
|
|
NSRect newFrame = _frame;
|
|
|
|
NSRect newFrameRounded;
|
|
|
|
|
|
|
|
if (_autoresizingMask == NSViewNotSizable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!NSEqualRects(NSZeroRect, _autoresizingFrameError))
|
|
|
|
{
|
|
|
|
newFrame.origin.x -= _autoresizingFrameError.origin.x;
|
|
|
|
newFrame.origin.y -= _autoresizingFrameError.origin.y;
|
|
|
|
newFrame.size.width -= _autoresizingFrameError.size.width;
|
|
|
|
newFrame.size.height -= _autoresizingFrameError.size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
superViewFrameSize = NSMakeSize(0,0);
|
|
|
|
if (_super_view)
|
|
|
|
superViewFrameSize = [_super_view frame].size;
|
|
|
|
|
|
|
|
autoresize(oldSize.width, superViewFrameSize.width, &newFrame.origin.x,
|
|
|
|
&newFrame.size.width, (_autoresizingMask & NSViewMinXMargin),
|
|
|
|
(_autoresizingMask & NSViewWidthSizable),
|
|
|
|
(_autoresizingMask & NSViewMaxXMargin));
|
|
|
|
|
|
|
|
{
|
|
|
|
const BOOL flipped = (_super_view && [_super_view isFlipped]);
|
|
|
|
const BOOL maxMarginFlexible = flipped
|
|
|
|
? (_autoresizingMask & NSViewMinYMargin)
|
|
|
|
: (_autoresizingMask & NSViewMaxYMargin);
|
|
|
|
const BOOL minMarginFlexible = flipped
|
|
|
|
? (_autoresizingMask & NSViewMaxYMargin)
|
|
|
|
: (_autoresizingMask & NSViewMinYMargin);
|
|
|
|
|
|
|
|
autoresize(oldSize.height, superViewFrameSize.height, &newFrame.origin.y,
|
|
|
|
&newFrame.size.height, minMarginFlexible,
|
|
|
|
(_autoresizingMask & NSViewHeightSizable), maxMarginFlexible);
|
|
|
|
}
|
|
|
|
|
|
|
|
newFrameRounded = newFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform rounding to pixel-align the frame if we are not rotated
|
|
|
|
*/
|
|
|
|
if (![self isRotatedFromBase] && [self superview] != nil)
|
|
|
|
{
|
|
|
|
newFrameRounded = [[self superview] centerScanRect: newFrameRounded];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setFrame: newFrameRounded];
|
|
|
|
|
|
|
|
_autoresizingFrameError.origin.x = (newFrameRounded.origin.x - newFrame.origin.x);
|
|
|
|
_autoresizingFrameError.origin.y = (newFrameRounded.origin.y - newFrame.origin.y);
|
|
|
|
_autoresizingFrameError.size.width = (newFrameRounded.size.width - newFrame.size.width);
|
|
|
|
_autoresizingFrameError.size.height = (newFrameRounded.size.height - newFrame.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
@interface NSFontPanel (Private)
|
2000-02-28 07:41:18 +00:00
|
|
|
- (NSFont*) _fontForSelection: (NSFont*) fontObject;
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2004-07-21 17:58:24 +00:00
|
|
|
-(void) _trySelectSize: (float)size
|
|
|
|
updateSizeField: (BOOL)updateSizeField;
|
2002-09-22 14:33:41 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// Some action methods
|
|
|
|
- (void) cancel: (id) sender;
|
|
|
|
- (void) _togglePreview: (id) sender;
|
2002-02-02 00:30:41 +00:00
|
|
|
- (void) _doPreview;
|
2000-02-22 17:49:28 +00:00
|
|
|
- (void) ok: (id) sender;
|
|
|
|
|
2003-06-10 01:26:56 +00:00
|
|
|
- (void) _getOriginalSize;
|
2000-02-22 17:49:28 +00:00
|
|
|
- (id)_initWithoutGModel;
|
2003-10-26 14:25:13 +00:00
|
|
|
|
|
|
|
- (BOOL) _includeFont: (NSString *)fontName delegate: (id)delegate;
|
2000-02-22 17:49:28 +00:00
|
|
|
@end
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSFontPanel
|
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
/*
|
|
|
|
* Class methods
|
|
|
|
*/
|
|
|
|
+ (void) initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
if (self == [NSFontPanel class])
|
|
|
|
{
|
1999-08-31 09:19:39 +00:00
|
|
|
[self setVersion: 1];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/** <p>Creates ( if needed ) and returns the shared NSFontPanel.</p>
|
2000-02-28 07:41:18 +00:00
|
|
|
*/
|
|
|
|
+ (NSFontPanel*) sharedFontPanel
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-02-28 07:41:18 +00:00
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
return [fm fontPanel: YES];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
+ (BOOL) sharedFontPanelExists
|
2000-01-25 14:36:17 +00:00
|
|
|
{
|
2000-02-28 07:41:18 +00:00
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
2000-01-25 14:36:17 +00:00
|
|
|
|
|
|
|
return ([fm fontPanel: NO] != nil);
|
|
|
|
}
|
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
/*
|
|
|
|
* Instance methods
|
|
|
|
*/
|
|
|
|
- (id) init
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2001-04-22 23:01:23 +00:00
|
|
|
// if (![NSBundle loadNibNamed: @"FontPanel" owner: self]);
|
2000-02-22 17:49:28 +00:00
|
|
|
[self _initWithoutGModel];
|
|
|
|
|
|
|
|
ASSIGN(_faceList, [NSArray array]);
|
|
|
|
_face = -1;
|
|
|
|
_family = -1;
|
2002-09-22 14:33:41 +00:00
|
|
|
[self reloadDefaultFontFamilies];
|
2003-06-10 01:26:56 +00:00
|
|
|
[self _getOriginalSize];
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
RELEASE(_panelFont);
|
|
|
|
RELEASE(_familyList);
|
|
|
|
TEST_RELEASE(_faceList);
|
2000-08-27 22:29:24 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
TEST_RELEASE(_accessoryView);
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/** <p>Returns whether the "set" button is enabled.</p>
|
2005-11-17 12:25:07 +00:00
|
|
|
<p>See Also: -setEnabled:</p>
|
2000-02-28 07:41:18 +00:00
|
|
|
*/
|
|
|
|
- (BOOL) isEnabled
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2000-08-27 22:29:24 +00:00
|
|
|
NSButton *setButton = [[self contentView] viewWithTag: NSFPSetButton];
|
|
|
|
|
|
|
|
return [setButton isEnabled];
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/**<p>Sets whether the "set" button is enabled.</p>
|
2005-11-17 12:25:07 +00:00
|
|
|
<p>See Also: -isEnabled</p>
|
|
|
|
*/
|
2000-02-28 07:41:18 +00:00
|
|
|
- (void) setEnabled: (BOOL)flag
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2000-08-27 22:29:24 +00:00
|
|
|
NSButton *setButton = [[self contentView] viewWithTag: NSFPSetButton];
|
|
|
|
|
|
|
|
[setButton setEnabled: flag];
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2001-08-01 22:48:17 +00:00
|
|
|
- (void) reloadDefaultFontFamilies
|
|
|
|
{
|
2002-02-02 00:30:41 +00:00
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
2003-10-26 14:25:13 +00:00
|
|
|
id fmDelegate = [fm delegate];
|
2002-02-02 00:30:41 +00:00
|
|
|
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
|
2003-10-26 14:25:13 +00:00
|
|
|
NSArray *fontFamilies = [fm availableFontFamilies];
|
|
|
|
unsigned int i,j;
|
2013-01-30 22:13:32 +00:00
|
|
|
NSMutableArray *familyList;
|
2003-10-26 14:25:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Build an array of all families that have a font that will be included.
|
|
|
|
*/
|
2013-01-30 22:13:32 +00:00
|
|
|
familyList = [[NSMutableArray alloc]
|
2003-10-26 14:25:13 +00:00
|
|
|
initWithCapacity: [fontFamilies count]];
|
|
|
|
|
|
|
|
for (i = 0; i < [fontFamilies count]; i++)
|
|
|
|
{
|
|
|
|
NSArray *familyMembers;
|
|
|
|
familyMembers = [fm availableMembersOfFontFamily:
|
|
|
|
[fontFamilies objectAtIndex: i]];
|
|
|
|
|
|
|
|
for (j = 0; j < [familyMembers count]; j++)
|
|
|
|
{
|
|
|
|
if ([self _includeFont: [[familyMembers objectAtIndex: j] objectAtIndex: 0]
|
|
|
|
delegate: fmDelegate])
|
|
|
|
{
|
2013-01-30 22:13:32 +00:00
|
|
|
[familyList addObject: [fontFamilies objectAtIndex: i]];
|
2003-10-26 14:25:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-02 00:30:41 +00:00
|
|
|
|
2013-01-30 22:13:32 +00:00
|
|
|
DESTROY(_familyList);
|
|
|
|
_familyList = familyList;
|
2002-02-02 00:30:41 +00:00
|
|
|
// Reload the display.
|
|
|
|
[familyBrowser loadColumnZero];
|
|
|
|
// Reselect the current font. (Hopefully still there)
|
|
|
|
[self setPanelFont: [fm selectedFont]
|
|
|
|
isMultiple: [fm isMultiple]];
|
2001-08-01 22:48:17 +00:00
|
|
|
}
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
- (void) setPanelFont: (NSFont *)fontObject
|
2000-02-28 07:41:18 +00:00
|
|
|
isMultiple: (BOOL)flag
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2001-01-27 00:03:42 +00:00
|
|
|
NSTextField *previewArea;
|
|
|
|
|
|
|
|
previewArea = [[self contentView] viewWithTag: NSFPPreviewField];
|
2000-08-27 22:29:24 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
ASSIGN(_panelFont, fontObject);
|
|
|
|
_multiple = flag;
|
|
|
|
|
|
|
|
if (fontObject == nil)
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
// TODO: Unselect all items and show a message
|
2010-01-03 18:35:25 +00:00
|
|
|
[previewArea setStringValue: _(@"Multiple fonts selected")];
|
2002-02-02 00:30:41 +00:00
|
|
|
_family = -1;
|
|
|
|
_face = -1;
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
|
|
|
NSString *family = [fontObject familyName];
|
|
|
|
NSString *fontName = [fontObject fontName];
|
|
|
|
float size = [fontObject pointSize];
|
2000-08-27 22:29:24 +00:00
|
|
|
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
|
|
|
|
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
|
2000-02-22 17:49:28 +00:00
|
|
|
NSString *face = @"";
|
2003-06-08 00:30:01 +00:00
|
|
|
unsigned int i;
|
2002-02-02 00:30:41 +00:00
|
|
|
|
|
|
|
// Store style information for font
|
|
|
|
_traits = [fm traitsOfFont: fontObject];
|
|
|
|
_weight = [fm weightOfFont: fontObject];
|
2002-09-14 11:38:30 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// Select the row for the font family
|
|
|
|
for (i = 0; i < [_familyList count]; i++)
|
|
|
|
{
|
|
|
|
if ([[_familyList objectAtIndex: i] isEqualToString: family])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < [_familyList count])
|
2000-02-28 07:41:18 +00:00
|
|
|
{
|
2000-08-27 22:29:24 +00:00
|
|
|
[familyBrowser selectRow: i inColumn: 0];
|
2000-02-28 07:41:18 +00:00
|
|
|
_family = i;
|
2013-01-30 22:13:32 +00:00
|
|
|
ASSIGN(_faceList, [fm availableMembersOfFontFamily: family]);
|
2002-02-02 00:30:41 +00:00
|
|
|
[faceBrowser loadColumnZero];
|
2000-02-28 07:41:18 +00:00
|
|
|
_face = -1;
|
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
// Select the row for the font face
|
2000-02-22 17:49:28 +00:00
|
|
|
for (i = 0; i < [_faceList count]; i++)
|
|
|
|
{
|
|
|
|
if ([[[_faceList objectAtIndex: i] objectAtIndex: 0]
|
|
|
|
isEqualToString: fontName])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < [_faceList count])
|
|
|
|
{
|
2000-08-27 22:29:24 +00:00
|
|
|
[faceBrowser selectRow: i inColumn: 0];
|
2000-02-28 07:41:18 +00:00
|
|
|
_face = i;
|
2000-02-22 17:49:28 +00:00
|
|
|
face = [[_faceList objectAtIndex: i] objectAtIndex: 1];
|
|
|
|
}
|
2002-02-02 00:30:41 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// show point size and select the row if there is one
|
2004-07-21 17:58:24 +00:00
|
|
|
[self _trySelectSize: size updateSizeField: YES];
|
2002-02-02 00:30:41 +00:00
|
|
|
|
|
|
|
// Use in preview
|
|
|
|
[previewArea setFont: fontObject];
|
|
|
|
if (_previewString == nil)
|
|
|
|
{
|
|
|
|
[previewArea setStringValue: [NSString stringWithFormat: @"%@ %@ %d PT",
|
|
|
|
family, face, (int)size]];
|
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-05 13:51:04 +00:00
|
|
|
/**<p>Converts the NSFont <var>fontObject</var></p>
|
2000-02-28 07:41:18 +00:00
|
|
|
*/
|
2001-01-27 00:03:42 +00:00
|
|
|
- (NSFont *) panelConvertFont: (NSFont *)fontObject
|
1999-03-23 21:03:52 +00:00
|
|
|
{
|
2000-02-28 07:41:18 +00:00
|
|
|
NSFont *newFont;
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
if (_multiple)
|
|
|
|
{
|
|
|
|
//TODO: We go over every item in the panel and check if a
|
|
|
|
// value is selected. If so we send it on to the manager
|
|
|
|
// newFont = [fm convertFont: fontObject toHaveTrait: NSItalicFontMask];
|
2000-03-16 14:16:46 +00:00
|
|
|
NSLog(@"Multiple font conversion not implemented in NSFontPanel");
|
2000-08-27 22:29:24 +00:00
|
|
|
newFont = [self _fontForSelection: fontObject];
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newFont = [self _fontForSelection: fontObject];
|
|
|
|
}
|
|
|
|
|
2000-08-27 22:29:24 +00:00
|
|
|
if (newFont == nil)
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
newFont = fontObject;
|
|
|
|
}
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
return newFont;
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/**<p>Overides the NSPanel/NSWindow method to always returns YES</p>
|
2000-02-28 07:41:18 +00:00
|
|
|
*/
|
|
|
|
- (BOOL) worksWhenModal
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/** <p>Returns the NSFontPanel's accessory view.</p>
|
2005-11-17 12:25:07 +00:00
|
|
|
<p>See Also: -setAccessoryView:</p>
|
2000-02-28 07:41:18 +00:00
|
|
|
*/
|
|
|
|
- (NSView*) accessoryView
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
|
|
|
return _accessoryView;
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:23:05 +00:00
|
|
|
/** <p>Sets the NSFontPanel's accessory view to <var>aView</var></p>
|
2005-11-17 12:25:07 +00:00
|
|
|
<p>See Also: -accessoryView</p>
|
|
|
|
*/
|
2003-06-10 01:26:56 +00:00
|
|
|
- (void) setAccessoryView: (NSView*)aView
|
|
|
|
{
|
|
|
|
NSRect accessoryViewFrame, bottomFrame;
|
|
|
|
NSRect tmpRect;
|
|
|
|
NSSize contentSize, contentMinSize;
|
|
|
|
float addedHeight, accessoryWidth;
|
|
|
|
|
|
|
|
if (aView == _accessoryView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The following code is very tricky. Please think and test a lot
|
|
|
|
before changing it. */
|
|
|
|
|
|
|
|
/* Remove old accessory view if any */
|
|
|
|
if (_accessoryView != nil)
|
|
|
|
{
|
|
|
|
/* Remove accessory view */
|
|
|
|
accessoryViewFrame = [_accessoryView frame];
|
|
|
|
[_accessoryView removeFromSuperview];
|
|
|
|
|
|
|
|
/* Change the min size before doing the resizing otherwise it
|
|
|
|
could be a problem. */
|
|
|
|
[self setMinSize: _originalMinSize];
|
|
|
|
|
|
|
|
/* Resize the panel to the height without the accessory view.
|
|
|
|
This must be done with the special care of not resizing
|
|
|
|
the heights of the other views. */
|
|
|
|
addedHeight = accessoryViewFrame.size.height + (_SAVE_PANEL_Y_PAD * 2);
|
|
|
|
contentSize = [[self contentView] frame].size;
|
|
|
|
contentSize.height -= addedHeight;
|
|
|
|
// Resize without modifying topView and bottomView height.
|
|
|
|
[_topView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
|
|
|
[self setContentSize: contentSize];
|
|
|
|
[_topView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the panel to its original size. This resizes freely the
|
|
|
|
heights of the views. NB: minSize *must* come first */
|
|
|
|
[self setMinSize: _originalMinSize];
|
|
|
|
[self setContentSize: _originalSize];
|
|
|
|
|
|
|
|
/* Set the new accessory view */
|
|
|
|
_accessoryView = aView;
|
|
|
|
|
|
|
|
/* If there is a new accessory view, plug it in */
|
|
|
|
if (_accessoryView != nil)
|
|
|
|
{
|
|
|
|
/* Make sure the new accessory view behaves - its height must be fixed
|
|
|
|
* and its position relative to the bottom of the superview must not
|
|
|
|
* change - so its position rlative to the top must be changable. */
|
|
|
|
[_accessoryView setAutoresizingMask: NSViewMaxYMargin
|
|
|
|
| ([_accessoryView autoresizingMask]
|
|
|
|
& ~(NSViewHeightSizable | NSViewMinYMargin))];
|
|
|
|
|
|
|
|
/* Compute size taken by the new accessory view */
|
|
|
|
accessoryViewFrame = [_accessoryView frame];
|
|
|
|
addedHeight = accessoryViewFrame.size.height + (_SAVE_PANEL_Y_PAD * 2);
|
|
|
|
accessoryWidth = accessoryViewFrame.size.width + (_SAVE_PANEL_X_PAD * 2);
|
|
|
|
|
|
|
|
/* Resize content size accordingly */
|
|
|
|
contentSize = _originalSize;
|
|
|
|
contentSize.height += addedHeight;
|
|
|
|
if (accessoryWidth > contentSize.width)
|
|
|
|
{
|
|
|
|
contentSize.width = accessoryWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set new content size without resizing heights of topView, bottomView */
|
|
|
|
// Our views should resize horizontally if needed, but not vertically
|
|
|
|
[_topView setAutoresizingMask: NSViewWidthSizable | NSViewMinYMargin];
|
|
|
|
[self setContentSize: contentSize];
|
|
|
|
// Restore the original autoresizing masks
|
|
|
|
[_topView setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
|
|
|
|
/* Compute new min size */
|
|
|
|
contentMinSize = _originalMinSize;
|
|
|
|
contentMinSize.height += addedHeight;
|
|
|
|
// width is more delicate
|
|
|
|
tmpRect = NSMakeRect (0, 0, contentMinSize.width, contentMinSize.height);
|
|
|
|
tmpRect = [NSWindow contentRectForFrameRect: tmpRect
|
|
|
|
styleMask: [self styleMask]];
|
|
|
|
if (accessoryWidth > tmpRect.size.width)
|
|
|
|
{
|
|
|
|
contentMinSize.width += accessoryWidth - tmpRect.size.width;
|
|
|
|
}
|
|
|
|
// Set new min size
|
|
|
|
[self setMinSize: contentMinSize];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pack the Views
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BottomView is ready */
|
|
|
|
bottomFrame = [_bottomView frame];
|
|
|
|
|
|
|
|
/* AccessoryView */
|
|
|
|
accessoryViewFrame.origin.x
|
|
|
|
= (contentSize.width - accessoryViewFrame.size.width) / 2;
|
|
|
|
accessoryViewFrame.origin.y = NSMaxY (bottomFrame) + _SAVE_PANEL_Y_PAD;
|
|
|
|
[_accessoryView setFrameOrigin: accessoryViewFrame.origin];
|
|
|
|
|
|
|
|
/* Add the accessory view */
|
|
|
|
[[self contentView] addSubview: _accessoryView];
|
|
|
|
}
|
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
/*
|
|
|
|
* NSCoding protocol
|
|
|
|
*/
|
2000-02-22 17:49:28 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
|
|
|
[aCoder encodeObject: _panelFont];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_multiple];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_preview];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
|
|
|
[super initWithCoder: aDecoder];
|
|
|
|
|
|
|
|
_panelFont = RETAIN([aDecoder decodeObject]);
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_multiple];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_preview];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2001-06-16 11:08:30 +00:00
|
|
|
/*
|
|
|
|
* Overriding fieldEditor:forObject: because we don't want the field
|
|
|
|
* editor (which is used when you type in the size browser) to use the
|
|
|
|
* font panel, otherwise typing in the size browser can modify the
|
|
|
|
* currently selected font in unexpected ways ! */
|
|
|
|
- (NSText *) fieldEditor: (BOOL)createFlag
|
|
|
|
forObject: (id)anObject
|
|
|
|
{
|
|
|
|
if (([anObject respondsToSelector: @selector(tag)])
|
|
|
|
&& ([anObject tag] == NSFPSizeField))
|
|
|
|
{
|
|
|
|
if ((sizeFieldText == nil) && createFlag)
|
|
|
|
{
|
|
|
|
sizeFieldText = [NSText new];
|
|
|
|
[sizeFieldText setUsesFontPanel: NO];
|
|
|
|
[sizeFieldText setFieldEditor: YES];
|
|
|
|
}
|
|
|
|
return sizeFieldText;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super fieldEditor: createFlag forObject: anObject];
|
|
|
|
}
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
@end
|
|
|
|
|
2003-10-26 14:25:13 +00:00
|
|
|
@implementation NSFontPanel (Private)
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
- (id) _initWithoutGModel
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2010-09-13 00:36:45 +00:00
|
|
|
NSRect contentRect = {{100, 100}, {320, 300}};
|
|
|
|
NSRect topAreaRect = {{0, 42}, {320, 258}};
|
|
|
|
NSRect splitViewRect = {{8, 8}, {304, 243}};
|
|
|
|
NSRect topSplitRect = {{0, 0}, {304, 45}};
|
|
|
|
NSRect previewAreaRect = {{0, 1}, {304, 44}};
|
|
|
|
NSRect bottomSplitRect = {{0, 0}, {304, 190}};
|
2001-01-27 00:03:42 +00:00
|
|
|
NSRect familyBrowserRect = {{0, 0}, {111, 189}};
|
|
|
|
NSRect typefaceBrowserRect = {{113, 0}, {111, 189}};
|
2010-09-13 00:36:45 +00:00
|
|
|
NSRect sizeBrowserRect = {{226, 0}, {78, 143}};
|
|
|
|
NSRect sizeLabelRect = {{226, 145}, {78, 21}};
|
|
|
|
NSRect sizeTitleRect = {{226, 168}, {78, 21}};
|
|
|
|
NSRect bottomAreaRect = {{0, 0}, {320, 42}};
|
|
|
|
NSRect slashRect = {{0, 40}, {320, 2}};
|
|
|
|
NSRect revertButtonRect = {{83, 8}, {71, 24}};
|
|
|
|
NSRect previewButtonRect = {{162, 8}, {71, 24}};
|
|
|
|
NSRect setButtonRect = {{241, 8}, {71, 24}};
|
2011-07-06 18:39:49 +00:00
|
|
|
NSRect characterPanelButtonRect = {{8, 8}, {24, 24}};
|
1999-03-23 21:03:52 +00:00
|
|
|
NSView *v;
|
1999-03-23 22:32:26 +00:00
|
|
|
NSView *topArea;
|
|
|
|
NSView *bottomArea;
|
1999-03-23 21:03:52 +00:00
|
|
|
NSView *topSplit;
|
|
|
|
NSView *bottomSplit;
|
|
|
|
NSSplitView *splitView;
|
2000-08-27 22:29:24 +00:00
|
|
|
NSTextField *previewArea;
|
|
|
|
NSBrowser *sizeBrowser;
|
|
|
|
NSBrowser *familyBrowser;
|
|
|
|
NSBrowser *faceBrowser;
|
1999-03-23 21:03:52 +00:00
|
|
|
NSTextField *label;
|
2000-08-27 22:29:24 +00:00
|
|
|
NSTextField *sizeField;
|
1999-03-23 21:03:52 +00:00
|
|
|
NSButton *revertButton;
|
|
|
|
NSButton *previewButton;
|
2000-08-27 22:29:24 +00:00
|
|
|
NSButton *setButton;
|
2011-07-06 18:39:49 +00:00
|
|
|
NSButton *characterPanelButton;
|
1999-03-25 20:58:12 +00:00
|
|
|
NSBox *slash;
|
1999-03-23 21:03:52 +00:00
|
|
|
|
1999-03-25 20:58:12 +00:00
|
|
|
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
|
2010-08-04 05:10:56 +00:00
|
|
|
| NSResizableWindowMask | NSUtilityWindowMask;
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
self = [super initWithContentRect: contentRect
|
2000-03-08 21:55:05 +00:00
|
|
|
styleMask: style
|
|
|
|
backing: NSBackingStoreRetained
|
2001-06-16 11:08:30 +00:00
|
|
|
defer: YES
|
2000-03-08 21:55:05 +00:00
|
|
|
screen: nil];
|
2012-12-16 22:51:23 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-01-03 18:35:25 +00:00
|
|
|
[self setTitle: _(@"Font Panel")];
|
2010-02-20 00:20:30 +00:00
|
|
|
[self setBecomesKeyOnlyIfNeeded: YES];
|
1999-03-23 21:03:52 +00:00
|
|
|
|
1999-03-23 22:32:26 +00:00
|
|
|
v = [self contentView];
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// preview and selection
|
2001-01-27 00:03:42 +00:00
|
|
|
topArea = [[NSView alloc] initWithFrame: topAreaRect];
|
2000-02-22 17:49:28 +00:00
|
|
|
[topArea setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
2003-06-10 01:26:56 +00:00
|
|
|
_topView = topArea;
|
1999-03-23 22:32:26 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
splitView = [[NSSplitView alloc] initWithFrame: splitViewRect];
|
1999-08-31 09:19:39 +00:00
|
|
|
[splitView setVertical: NO];
|
2000-02-22 17:49:28 +00:00
|
|
|
[splitView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
topSplit = [[NSView alloc] initWithFrame: topSplitRect];
|
|
|
|
[topSplit setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
// Display for the font example
|
2001-01-27 00:03:42 +00:00
|
|
|
previewArea = [[NSTextField alloc] initWithFrame: previewAreaRect];
|
2000-08-27 22:29:24 +00:00
|
|
|
[previewArea setBackgroundColor: [NSColor textBackgroundColor]];
|
|
|
|
[previewArea setDrawsBackground: YES];
|
|
|
|
[previewArea setEditable: NO];
|
|
|
|
[previewArea setSelectable: NO];
|
|
|
|
//[previewArea setUsesFontPanel: NO];
|
|
|
|
[previewArea setAlignment: NSCenterTextAlignment];
|
2010-01-03 18:35:25 +00:00
|
|
|
[previewArea setStringValue: _(@"Font preview")];
|
2001-01-27 00:03:42 +00:00
|
|
|
[previewArea setAutoresizingMask: (NSViewWidthSizable|NSViewHeightSizable)];
|
|
|
|
|
2000-08-27 22:29:24 +00:00
|
|
|
[previewArea setTag: NSFPPreviewField];
|
|
|
|
[topSplit addSubview: previewArea];
|
|
|
|
RELEASE(previewArea);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
bottomSplit = [[NSView alloc] initWithFrame: bottomSplitRect];
|
|
|
|
[bottomSplit setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// Selection of the font family
|
|
|
|
// We use a browser with one column to get a selection list
|
2024-10-03 16:21:53 +00:00
|
|
|
familyBrowser = [[FPBrowser alloc] initWithFrame: familyBrowserRect];
|
2000-08-27 22:29:24 +00:00
|
|
|
[familyBrowser setDelegate: self];
|
|
|
|
[familyBrowser setMaxVisibleColumns: 1];
|
2001-07-23 14:07:38 +00:00
|
|
|
[familyBrowser setMinColumnWidth: 0];
|
2000-08-27 22:29:24 +00:00
|
|
|
[familyBrowser setAllowsMultipleSelection: NO];
|
|
|
|
[familyBrowser setAllowsEmptySelection: YES];
|
|
|
|
[familyBrowser setHasHorizontalScroller: NO];
|
|
|
|
[familyBrowser setTitled: YES];
|
|
|
|
[familyBrowser setTakesTitleFromPreviousColumn: NO];
|
|
|
|
[familyBrowser setTarget: self];
|
|
|
|
[familyBrowser setDoubleAction: @selector(familySelected:)];
|
2002-09-14 11:38:30 +00:00
|
|
|
[familyBrowser setAction: @selector(_familySelectionChanged:)];
|
2001-01-27 00:03:42 +00:00
|
|
|
[familyBrowser setAutoresizingMask: (NSViewWidthSizable
|
|
|
|
| NSViewMaxXMargin
|
|
|
|
| NSViewHeightSizable)];
|
2000-08-27 22:29:24 +00:00
|
|
|
[familyBrowser setTag: NSFPFamilyBrowser];
|
|
|
|
[bottomSplit addSubview: familyBrowser];
|
|
|
|
RELEASE(familyBrowser);
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
// selection of type face
|
|
|
|
// We use a browser with one column to get a selection list
|
2024-10-03 16:21:53 +00:00
|
|
|
faceBrowser = [[FPBrowser alloc] initWithFrame: typefaceBrowserRect];
|
2000-08-27 22:29:24 +00:00
|
|
|
[faceBrowser setDelegate: self];
|
|
|
|
[faceBrowser setMaxVisibleColumns: 1];
|
2001-07-23 14:07:38 +00:00
|
|
|
[faceBrowser setMinColumnWidth: 0];
|
2000-08-27 22:29:24 +00:00
|
|
|
[faceBrowser setAllowsMultipleSelection: NO];
|
|
|
|
[faceBrowser setAllowsEmptySelection: YES];
|
|
|
|
[faceBrowser setHasHorizontalScroller: NO];
|
|
|
|
[faceBrowser setTitled: YES];
|
|
|
|
[faceBrowser setTakesTitleFromPreviousColumn: NO];
|
|
|
|
[faceBrowser setTarget: self];
|
|
|
|
[faceBrowser setDoubleAction: @selector(faceSelected:)];
|
2002-09-14 11:38:30 +00:00
|
|
|
[faceBrowser setAction: @selector(_faceSelectionChanged:)];
|
2001-01-27 00:03:42 +00:00
|
|
|
[faceBrowser setAutoresizingMask: (NSViewWidthSizable
|
|
|
|
| NSViewMinXMargin
|
|
|
|
| NSViewHeightSizable)];
|
2000-08-27 22:29:24 +00:00
|
|
|
[faceBrowser setTag: NSFPFaceBrowser];
|
|
|
|
[bottomSplit addSubview: faceBrowser];
|
|
|
|
RELEASE(faceBrowser);
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
// label for selection of size
|
2001-01-27 00:03:42 +00:00
|
|
|
label = [[NSTextField alloc] initWithFrame: sizeTitleRect];
|
2012-12-16 22:51:23 +00:00
|
|
|
[label setCell: AUTORELEASE([GSBrowserTitleCell new])];
|
2001-01-27 00:03:42 +00:00
|
|
|
[label setFont: [NSFont boldSystemFontOfSize: 0]];
|
1999-03-23 21:03:52 +00:00
|
|
|
[label setAlignment: NSCenterTextAlignment];
|
1999-08-31 09:19:39 +00:00
|
|
|
[label setDrawsBackground: YES];
|
|
|
|
[label setEditable: NO];
|
|
|
|
[label setTextColor: [NSColor windowFrameTextColor]];
|
|
|
|
[label setBackgroundColor: [NSColor controlShadowColor]];
|
2010-01-03 18:35:25 +00:00
|
|
|
[label setStringValue: _(@"Size")];
|
2001-01-27 00:03:42 +00:00
|
|
|
[label setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin];
|
2000-08-27 22:29:24 +00:00
|
|
|
[label setTag: NSFPSizeTitle];
|
1999-08-31 09:19:39 +00:00
|
|
|
[bottomSplit addSubview: label];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(label);
|
|
|
|
|
|
|
|
// this is the size input field
|
2001-01-27 00:03:42 +00:00
|
|
|
sizeField = [[NSTextField alloc] initWithFrame: sizeLabelRect];
|
2000-08-27 22:29:24 +00:00
|
|
|
[sizeField setDrawsBackground: YES];
|
|
|
|
[sizeField setEditable: YES];
|
2002-02-02 00:30:41 +00:00
|
|
|
[sizeField setAllowsEditingTextAttributes: NO];
|
2000-08-27 22:29:24 +00:00
|
|
|
[sizeField setAlignment: NSCenterTextAlignment];
|
2001-01-27 00:03:42 +00:00
|
|
|
[sizeField setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin];
|
2002-09-22 14:33:41 +00:00
|
|
|
[sizeField setDelegate: self];
|
2000-08-27 22:29:24 +00:00
|
|
|
[sizeField setTag: NSFPSizeField];
|
|
|
|
[bottomSplit addSubview: sizeField];
|
|
|
|
RELEASE(sizeField);
|
|
|
|
|
2024-10-03 16:21:53 +00:00
|
|
|
sizeBrowser = [[FPBrowser alloc] initWithFrame: sizeBrowserRect];
|
2000-08-27 22:29:24 +00:00
|
|
|
[sizeBrowser setDelegate: self];
|
|
|
|
[sizeBrowser setMaxVisibleColumns: 1];
|
|
|
|
[sizeBrowser setAllowsMultipleSelection: NO];
|
|
|
|
[sizeBrowser setAllowsEmptySelection: YES];
|
|
|
|
[sizeBrowser setHasHorizontalScroller: NO];
|
|
|
|
[sizeBrowser setTitled: NO];
|
|
|
|
[sizeBrowser setTakesTitleFromPreviousColumn: NO];
|
|
|
|
[sizeBrowser setTarget: self];
|
|
|
|
[sizeBrowser setDoubleAction: @selector(sizeSelected:)];
|
2002-09-14 11:38:30 +00:00
|
|
|
[sizeBrowser setAction: @selector(_sizeSelectionChanged:)];
|
2001-01-27 00:03:42 +00:00
|
|
|
[sizeBrowser setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
|
2000-08-27 22:29:24 +00:00
|
|
|
[sizeBrowser setTag: NSFPSizeBrowser];
|
|
|
|
[bottomSplit addSubview: sizeBrowser];
|
|
|
|
RELEASE(sizeBrowser);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
[splitView addSubview: topSplit];
|
|
|
|
RELEASE(topSplit);
|
|
|
|
[splitView addSubview: bottomSplit];
|
|
|
|
RELEASE(bottomSplit);
|
2001-01-27 00:03:42 +00:00
|
|
|
|
|
|
|
[splitView setDelegate: self];
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
[topArea addSubview: splitView];
|
|
|
|
RELEASE(splitView);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// action buttons
|
2001-01-27 00:03:42 +00:00
|
|
|
bottomArea = [[NSView alloc] initWithFrame: bottomAreaRect];
|
2003-06-10 01:26:56 +00:00
|
|
|
_bottomView = bottomArea;
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
slash = [[NSBox alloc] initWithFrame: slashRect];
|
1999-08-31 09:19:39 +00:00
|
|
|
[slash setBorderType: NSGrooveBorder];
|
2024-10-03 16:21:53 +00:00
|
|
|
[slash setTitlePosition:NSNoTitle];
|
2001-01-27 00:03:42 +00:00
|
|
|
[slash setAutoresizingMask: NSViewWidthSizable];
|
1999-08-31 09:19:39 +00:00
|
|
|
[bottomArea addSubview: slash];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(slash);
|
1999-03-23 22:32:26 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
// cancel button
|
|
|
|
revertButton = [[NSButton alloc] initWithFrame: revertButtonRect];
|
2010-01-03 18:35:25 +00:00
|
|
|
[revertButton setTitle: _(@"Revert")];
|
2000-03-08 21:55:05 +00:00
|
|
|
[revertButton setAction: @selector(cancel:)];
|
2000-02-22 17:49:28 +00:00
|
|
|
[revertButton setTarget: self];
|
2000-08-27 22:29:24 +00:00
|
|
|
[revertButton setTag: NSFPRevertButton];
|
2001-01-27 00:03:42 +00:00
|
|
|
[revertButton setAutoresizingMask: NSViewMinXMargin];
|
1999-08-31 09:19:39 +00:00
|
|
|
[bottomArea addSubview: revertButton];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(revertButton);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// toggle button for preview
|
2001-01-27 00:03:42 +00:00
|
|
|
previewButton = [[NSButton alloc] initWithFrame: previewButtonRect];
|
2010-01-03 18:35:25 +00:00
|
|
|
[previewButton setTitle: _(@"Preview")];
|
1999-08-31 09:19:39 +00:00
|
|
|
[previewButton setButtonType: NSOnOffButton];
|
2000-03-08 21:55:05 +00:00
|
|
|
[previewButton setAction: @selector(_togglePreview:)];
|
2000-02-22 17:49:28 +00:00
|
|
|
[previewButton setTarget: self];
|
2000-08-27 22:29:24 +00:00
|
|
|
[previewButton setTag: NSFPPreviewButton];
|
2001-01-27 00:03:42 +00:00
|
|
|
[previewButton setAutoresizingMask: NSViewMinXMargin];
|
2003-04-05 11:00:28 +00:00
|
|
|
[previewButton setState: NSOnState];
|
|
|
|
_preview = YES;
|
1999-08-31 09:19:39 +00:00
|
|
|
[bottomArea addSubview: previewButton];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(previewButton);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
// button to set the font
|
2001-01-27 00:03:42 +00:00
|
|
|
setButton = [[NSButton alloc] initWithFrame: setButtonRect];
|
2010-01-03 18:35:25 +00:00
|
|
|
[setButton setTitle: _(@"Set")];
|
2000-08-27 22:29:24 +00:00
|
|
|
[setButton setAction: @selector(ok:)];
|
|
|
|
[setButton setTarget: self];
|
|
|
|
[setButton setTag: NSFPSetButton];
|
2001-01-27 00:03:42 +00:00
|
|
|
[setButton setAutoresizingMask: NSViewMinXMargin];
|
2000-08-27 22:29:24 +00:00
|
|
|
[bottomArea addSubview: setButton];
|
2000-02-22 17:49:28 +00:00
|
|
|
// make it the default button
|
2002-02-02 00:30:41 +00:00
|
|
|
[self setDefaultButtonCell: [setButton cell]];
|
2000-08-27 22:29:24 +00:00
|
|
|
RELEASE(setButton);
|
1999-03-23 21:03:52 +00:00
|
|
|
|
2011-07-06 18:39:49 +00:00
|
|
|
// Character Panel button
|
|
|
|
{
|
|
|
|
NSString *label;
|
|
|
|
unichar labelchars[2] = {0x03b1, 0x03b2}; // alpha, beta
|
|
|
|
label = [[[NSString alloc] initWithCharacters: labelchars
|
|
|
|
length: 2] autorelease];
|
|
|
|
|
|
|
|
characterPanelButton = [[NSButton alloc] initWithFrame: characterPanelButtonRect];
|
|
|
|
[characterPanelButton setTitle: label];
|
2011-09-08 05:59:20 +00:00
|
|
|
[characterPanelButton setToolTip: _(@"Character Panel")];
|
2011-07-06 18:39:49 +00:00
|
|
|
[characterPanelButton setAction: @selector(characterPanel:)];
|
|
|
|
[characterPanelButton setTarget: self];
|
|
|
|
[bottomArea addSubview: characterPanelButton];
|
|
|
|
RELEASE(characterPanelButton);
|
|
|
|
}
|
|
|
|
|
2001-06-16 11:08:30 +00:00
|
|
|
// set up the next key view chain
|
|
|
|
[familyBrowser setNextKeyView: faceBrowser];
|
|
|
|
[faceBrowser setNextKeyView: sizeField];
|
|
|
|
[sizeField setNextKeyView: sizeBrowser];
|
|
|
|
[sizeBrowser setNextKeyView: revertButton];
|
|
|
|
[revertButton setNextKeyView: previewButton];
|
|
|
|
[previewButton setNextKeyView: setButton];
|
|
|
|
[setButton setNextKeyView: familyBrowser];
|
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
[v addSubview: topArea];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(topArea);
|
|
|
|
|
|
|
|
// Add the accessory view, if there is one
|
|
|
|
if (_accessoryView != nil)
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
[v addSubview: _accessoryView];
|
|
|
|
}
|
|
|
|
|
|
|
|
[bottomArea setAutoresizingMask: NSViewWidthSizable];
|
1999-08-31 09:19:39 +00:00
|
|
|
[v addSubview: bottomArea];
|
2000-02-22 17:49:28 +00:00
|
|
|
RELEASE(bottomArea);
|
1999-03-23 22:32:26 +00:00
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
[self setMinSize: [self frame].size];
|
2001-06-16 11:08:30 +00:00
|
|
|
|
|
|
|
[self setInitialFirstResponder: setButton];
|
2001-10-16 02:09:09 +00:00
|
|
|
[self setBecomesKeyOnlyIfNeeded: YES];
|
2001-01-27 00:03:42 +00:00
|
|
|
|
1999-03-23 21:03:52 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
- (void) _togglePreview: (id)sender
|
2000-01-25 14:36:17 +00:00
|
|
|
{
|
2000-03-08 21:55:05 +00:00
|
|
|
_preview = (sender == nil) ? YES : [sender state];
|
2002-02-02 00:30:41 +00:00
|
|
|
[self _doPreview];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _doPreview
|
|
|
|
{
|
|
|
|
NSFont *font = nil;
|
|
|
|
NSTextField *previewArea = [[self contentView] viewWithTag: NSFPPreviewField];
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
if (_preview)
|
|
|
|
{
|
2002-02-02 00:30:41 +00:00
|
|
|
font = [self _fontForSelection: _panelFont];
|
|
|
|
// build up a font and use it in the preview area
|
|
|
|
if (font != nil)
|
|
|
|
{
|
|
|
|
[previewArea setFont: font];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_previewString == nil)
|
|
|
|
{
|
2000-08-27 22:29:24 +00:00
|
|
|
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
float size = [sizeField floatValue];
|
2000-03-08 21:55:05 +00:00
|
|
|
NSString *faceName;
|
|
|
|
NSString *familyName;
|
|
|
|
|
|
|
|
if (size == 0 && font != nil)
|
|
|
|
{
|
|
|
|
size = [font pointSize];
|
|
|
|
}
|
|
|
|
if (_family == -1)
|
|
|
|
{
|
2010-01-03 18:35:25 +00:00
|
|
|
familyName = _(@"NoFamily");
|
2000-03-08 21:55:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
familyName = [_familyList objectAtIndex: _family];
|
|
|
|
}
|
2003-10-26 14:25:13 +00:00
|
|
|
if (_face == -1 || ![_faceList count])
|
2000-03-08 21:55:05 +00:00
|
|
|
{
|
2010-01-03 18:35:25 +00:00
|
|
|
faceName = _(@"NoFace");
|
2000-03-08 21:55:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
faceName = [[_faceList objectAtIndex: _face] objectAtIndex: 1];
|
|
|
|
}
|
2000-08-27 22:29:24 +00:00
|
|
|
[previewArea setStringValue: [NSString stringWithFormat: @"%@ %@ %d PT",
|
|
|
|
familyName, faceName, (int)size]];
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
2000-01-25 14:36:17 +00:00
|
|
|
}
|
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
- (void) ok: (id)sender
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-02-22 17:49:28 +00:00
|
|
|
// The set button has been pushed
|
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
|
|
|
|
|
|
|
[fm modifyFontViaPanel: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-02-28 07:41:18 +00:00
|
|
|
- (void) cancel: (id)sender
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2001-01-27 00:03:42 +00:00
|
|
|
// FIXME/TODO
|
|
|
|
|
2000-03-08 21:55:05 +00:00
|
|
|
/*
|
|
|
|
* The cancel button has been pushed
|
|
|
|
* we should reset the items in the panel
|
|
|
|
*/
|
2000-02-22 17:49:28 +00:00
|
|
|
[self setPanelFont: _panelFont
|
2000-02-28 07:41:18 +00:00
|
|
|
isMultiple: _multiple];
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
2000-01-25 14:36:17 +00:00
|
|
|
|
2011-07-06 18:39:49 +00:00
|
|
|
- (void) characterPanel: (id)sender
|
|
|
|
{
|
2011-09-07 19:31:22 +00:00
|
|
|
[[NSApplication sharedApplication] orderFrontCharacterPalette: sender];
|
2011-07-06 18:39:49 +00:00
|
|
|
}
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
- (NSFont *) _fontForSelection: (NSFont *)fontObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-03-08 21:55:05 +00:00
|
|
|
float size;
|
|
|
|
NSString *fontName;
|
2003-10-26 14:25:13 +00:00
|
|
|
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
unsigned i = [_faceList count];
|
2000-02-22 17:49:28 +00:00
|
|
|
|
2000-08-27 22:29:24 +00:00
|
|
|
size = [sizeField floatValue];
|
2000-02-22 17:49:28 +00:00
|
|
|
if (size == 0.0)
|
2000-02-28 07:41:18 +00:00
|
|
|
{
|
|
|
|
if (fontObject == nil)
|
|
|
|
{
|
|
|
|
size = 12.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size = [fontObject pointSize];
|
|
|
|
}
|
|
|
|
}
|
2000-03-08 21:55:05 +00:00
|
|
|
if (_face < 0)
|
2000-02-28 07:41:18 +00:00
|
|
|
{
|
2000-03-08 21:55:05 +00:00
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
return nil; /* Nothing available */
|
|
|
|
}
|
|
|
|
// FIXME - just uses first face
|
2000-02-28 07:41:18 +00:00
|
|
|
fontName = [[_faceList objectAtIndex: 0] objectAtIndex: 0];
|
|
|
|
}
|
2000-01-25 14:36:17 +00:00
|
|
|
else
|
2000-02-28 07:41:18 +00:00
|
|
|
{
|
2003-10-26 14:25:13 +00:00
|
|
|
/*
|
2003-12-31 00:12:36 +00:00
|
|
|
i really should be > 0 here, except for the very obscure case where
|
2003-10-26 14:25:13 +00:00
|
|
|
the delegate has refused all fonts (so that our family and face lists
|
|
|
|
are completely empty).
|
|
|
|
*/
|
|
|
|
if (i)
|
|
|
|
fontName = [[_faceList objectAtIndex: _face] objectAtIndex: 0];
|
|
|
|
else
|
|
|
|
return nil;
|
2000-02-28 07:41:18 +00:00
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
// FIXME: We should check if the font is correct
|
|
|
|
return [NSFont fontWithName: fontName size: size];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
2002-09-22 14:33:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
-(void) _trySelectSize: (float)size
|
2004-07-21 17:58:24 +00:00
|
|
|
updateSizeField: (BOOL)updateSizeField
|
2002-09-22 14:33:41 +00:00
|
|
|
{
|
2003-06-08 00:30:01 +00:00
|
|
|
unsigned int i;
|
2002-09-22 14:33:41 +00:00
|
|
|
NSBrowser *sizeBrowser = [[self contentView] viewWithTag: NSFPSizeBrowser];
|
2003-04-13 23:45:39 +00:00
|
|
|
NSTextField *sizeField;
|
|
|
|
|
2004-07-21 17:58:24 +00:00
|
|
|
if (updateSizeField)
|
|
|
|
{
|
|
|
|
/* Make sure our sizeField is updated. */
|
|
|
|
sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
_setFloatValue (sizeField, size);
|
|
|
|
}
|
2003-04-13 23:45:39 +00:00
|
|
|
|
|
|
|
/* Make sure our column is loaded. */
|
|
|
|
[sizeBrowser loadColumnZero];
|
2002-09-22 14:33:41 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(sizes) / sizeof(float); i++)
|
|
|
|
{
|
|
|
|
if (size == sizes[i])
|
|
|
|
{
|
2003-04-13 23:45:39 +00:00
|
|
|
/* select the cell */
|
2002-09-22 14:33:41 +00:00
|
|
|
[sizeBrowser selectRow: i inColumn: 0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == sizeof(sizes) / sizeof(float))
|
|
|
|
{
|
|
|
|
/* TODO: No matching size found in the list. We should deselect
|
|
|
|
everything. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) controlTextDidChange: (NSNotification *)n
|
|
|
|
{
|
|
|
|
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
float size = [sizeField floatValue];
|
2004-07-21 17:58:24 +00:00
|
|
|
[self _trySelectSize: size updateSizeField: NO];
|
2002-09-22 14:33:41 +00:00
|
|
|
[self _doPreview];
|
|
|
|
}
|
|
|
|
|
2003-10-26 14:25:13 +00:00
|
|
|
/*
|
|
|
|
Ask the NSFontManager:s delegate if a font should be included. For speed,
|
|
|
|
the delegate is an argument; a repeat-caller can then cache it.
|
|
|
|
*/
|
|
|
|
- (BOOL) _includeFont: (NSString*)fontName delegate: (id)fmDelegate
|
|
|
|
{
|
|
|
|
if (fmDelegate != nil
|
|
|
|
&& [fmDelegate respondsToSelector: @selector(fontManager:willIncludeFont:)])
|
|
|
|
{
|
|
|
|
return [fmDelegate fontManager: [NSFontManager sharedFontManager]
|
|
|
|
willIncludeFont: fontName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) _getOriginalSize
|
|
|
|
{
|
|
|
|
/* Used in setMinSize: */
|
|
|
|
_originalMinSize = [self minSize];
|
|
|
|
/* Used in setContentSize: */
|
|
|
|
_originalSize = [[self contentView] frame].size;
|
|
|
|
}
|
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
@end
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-02-22 17:49:28 +00:00
|
|
|
|
|
|
|
@implementation NSFontPanel (NSBrowserDelegate)
|
|
|
|
|
2002-09-21 15:52:42 +00:00
|
|
|
|
|
|
|
static int score_difference(int weight1, int traits1,
|
|
|
|
int weight2, int traits2)
|
|
|
|
{
|
|
|
|
int score, t;
|
|
|
|
|
|
|
|
score = (weight1 - weight2);
|
|
|
|
score = 10 * score * score;
|
|
|
|
|
|
|
|
t = traits1 ^ traits2;
|
|
|
|
|
|
|
|
if (t & NSFixedPitchFontMask) score += 1000;
|
|
|
|
if (t & NSCompressedFontMask) score += 150;
|
|
|
|
if (t & NSPosterFontMask) score += 200;
|
|
|
|
if (t & NSSmallCapsFontMask) score += 200;
|
|
|
|
if (t & NSCondensedFontMask) score += 150;
|
|
|
|
if (t & NSExpandedFontMask) score += 150;
|
|
|
|
if (t & NSNarrowFontMask) score += 150;
|
|
|
|
if (t & NSBoldFontMask) score += 20;
|
|
|
|
if (t & NSItalicFontMask) score += 45;
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
- (void) _familySelectionChanged: (id)sender
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2002-09-14 11:38:30 +00:00
|
|
|
NSFontManager *fm = [NSFontManager sharedFontManager];
|
2003-10-26 14:25:13 +00:00
|
|
|
id fmDelegate = [fm delegate];
|
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
|
|
|
|
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
|
|
|
|
int row = [familyBrowser selectedRowInColumn: 0];
|
2003-10-26 14:25:13 +00:00
|
|
|
|
2003-06-08 00:30:01 +00:00
|
|
|
unsigned int i;
|
2003-10-26 14:25:13 +00:00
|
|
|
NSArray *entireFaceList;
|
2013-01-30 22:13:32 +00:00
|
|
|
NSMutableArray *faceList;
|
2003-10-26 14:25:13 +00:00
|
|
|
|
|
|
|
entireFaceList = [fm availableMembersOfFontFamily:
|
2013-01-30 22:13:32 +00:00
|
|
|
[_familyList objectAtIndex: row]];
|
2003-10-26 14:25:13 +00:00
|
|
|
|
2013-01-30 22:13:32 +00:00
|
|
|
faceList = [[NSMutableArray alloc] initWithCapacity: [entireFaceList count]];
|
2003-10-26 14:25:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < [entireFaceList count]; i++)
|
|
|
|
{
|
|
|
|
id aFace = [entireFaceList objectAtIndex:i];
|
|
|
|
if ([self _includeFont: [aFace objectAtIndex:0] delegate: fmDelegate])
|
|
|
|
{
|
2013-01-30 22:13:32 +00:00
|
|
|
[faceList addObject: aFace];
|
2003-10-26 14:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
2002-02-02 00:30:41 +00:00
|
|
|
|
2013-01-30 22:13:32 +00:00
|
|
|
DESTROY(_faceList);
|
|
|
|
_faceList = faceList;
|
2002-09-14 11:38:30 +00:00
|
|
|
_family = row;
|
2002-09-21 15:52:42 +00:00
|
|
|
|
|
|
|
// Select a face with the same properties
|
2002-09-14 11:38:30 +00:00
|
|
|
for (i = 0; i < [_faceList count]; i++)
|
|
|
|
{
|
|
|
|
NSArray *font_info = [_faceList objectAtIndex: i];
|
2002-09-21 15:52:42 +00:00
|
|
|
|
|
|
|
if (([[font_info objectAtIndex: 2] intValue] == _weight)
|
|
|
|
&& ([[font_info objectAtIndex: 3] unsignedIntValue] == _traits))
|
|
|
|
break;
|
2002-09-14 11:38:30 +00:00
|
|
|
}
|
2002-09-21 15:52:42 +00:00
|
|
|
|
|
|
|
// Find the face that differs the least from what we want
|
|
|
|
if (i == [_faceList count])
|
|
|
|
{
|
|
|
|
int best, best_score, score;
|
|
|
|
|
|
|
|
best_score = 1e6;
|
|
|
|
best = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < [_faceList count]; i++)
|
|
|
|
{
|
|
|
|
NSArray *font_info = [_faceList objectAtIndex: i];
|
|
|
|
score = score_difference(_weight, _traits,
|
|
|
|
[[font_info objectAtIndex: 2] intValue],
|
|
|
|
[[font_info objectAtIndex: 3] unsignedIntValue]);
|
|
|
|
if (score < best_score)
|
|
|
|
{
|
|
|
|
best = i;
|
|
|
|
best_score = score;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best != -1)
|
|
|
|
i = best;
|
|
|
|
}
|
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
if (i == [_faceList count])
|
|
|
|
i = 0;
|
2002-02-02 00:30:41 +00:00
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
_face = i;
|
|
|
|
[faceBrowser loadColumnZero];
|
|
|
|
[faceBrowser selectRow: i inColumn: 0];
|
2002-02-02 00:30:41 +00:00
|
|
|
|
2003-04-27 15:44:28 +00:00
|
|
|
/* Also make sure the size column has some value */
|
|
|
|
{
|
|
|
|
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
float size = [sizeField floatValue];
|
|
|
|
|
|
|
|
if (size == 0.0)
|
|
|
|
{
|
2004-07-21 17:58:24 +00:00
|
|
|
[self _trySelectSize: 12.0 updateSizeField: YES];
|
2003-04-27 15:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-13 23:45:39 +00:00
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
[self _doPreview];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _faceSelectionChanged: (id)sender
|
|
|
|
{
|
|
|
|
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
|
|
|
|
int row = [faceBrowser selectedRowInColumn: 0];
|
|
|
|
NSArray *font_info = [_faceList objectAtIndex: row];
|
|
|
|
|
|
|
|
_face = row;
|
|
|
|
_weight = [[font_info objectAtIndex: 2] intValue];
|
|
|
|
_traits = [[font_info objectAtIndex: 3] unsignedIntValue];
|
2001-01-27 00:03:42 +00:00
|
|
|
|
2002-02-02 00:30:41 +00:00
|
|
|
[self _doPreview];
|
2002-09-14 11:38:30 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
- (void) _sizeSelectionChanged: (id)sender
|
|
|
|
{
|
|
|
|
NSBrowser *sizeBrowser = [[self contentView] viewWithTag: NSFPSizeBrowser];
|
|
|
|
int row = [sizeBrowser selectedRowInColumn: 0];
|
|
|
|
NSTextField *sizeField;
|
|
|
|
|
|
|
|
sizeField = [[self contentView] viewWithTag: NSFPSizeField];
|
|
|
|
_setFloatValue (sizeField, sizes[row]);
|
|
|
|
|
|
|
|
[self _doPreview];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-09-14 11:38:30 +00:00
|
|
|
|
2014-01-26 12:01:38 +00:00
|
|
|
- (NSInteger) browser: (NSBrowser*)sender numberOfRowsInColumn: (NSInteger)column
|
2000-01-25 14:36:17 +00:00
|
|
|
{
|
2001-01-27 00:03:42 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case NSFPFamilyBrowser:
|
|
|
|
{
|
|
|
|
return [_familyList count];
|
|
|
|
}
|
|
|
|
case NSFPFaceBrowser:
|
|
|
|
{
|
|
|
|
return [_faceList count];
|
|
|
|
}
|
|
|
|
case NSFPSizeBrowser:
|
|
|
|
{
|
|
|
|
return sizeof (sizes) / sizeof (float);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2000-01-25 14:36:17 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2014-01-26 12:01:38 +00:00
|
|
|
- (NSString*) browser: (NSBrowser*)sender titleOfColumn: (NSInteger)column
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-01-27 00:03:42 +00:00
|
|
|
switch ([sender tag])
|
|
|
|
{
|
|
|
|
case NSFPFamilyBrowser:
|
|
|
|
{
|
2010-01-03 18:35:25 +00:00
|
|
|
return _(@"Family");
|
2001-01-27 00:03:42 +00:00
|
|
|
}
|
|
|
|
case NSFPFaceBrowser:
|
|
|
|
{
|
2010-01-03 18:35:25 +00:00
|
|
|
return _(@"Typeface");
|
2001-01-27 00:03:42 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
- (void) browser: (NSBrowser *)sender
|
2000-02-28 07:41:18 +00:00
|
|
|
willDisplayCell: (id)cell
|
2013-01-30 22:13:32 +00:00
|
|
|
atRow: (NSInteger)row
|
|
|
|
column: (NSInteger)column
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-02-22 17:49:28 +00:00
|
|
|
NSString *value = nil;
|
2003-06-08 00:30:01 +00:00
|
|
|
|
|
|
|
if (row < 0)
|
|
|
|
return;
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
switch ([sender tag])
|
2000-02-22 17:49:28 +00:00
|
|
|
{
|
2001-01-27 00:03:42 +00:00
|
|
|
case NSFPFamilyBrowser:
|
|
|
|
{
|
2013-01-30 22:13:32 +00:00
|
|
|
if ([_familyList count] > (NSUInteger)row)
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
value = [_familyList objectAtIndex: row];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NSFPFaceBrowser:
|
|
|
|
{
|
2013-01-30 22:13:32 +00:00
|
|
|
if ([_faceList count] > (NSUInteger)row)
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
value = [[_faceList objectAtIndex: row] objectAtIndex: 1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NSFPSizeBrowser:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
value = [NSString stringWithFormat: @"%d", (int) sizes[row]];
|
|
|
|
}
|
2000-02-22 17:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[cell setStringValue: value];
|
|
|
|
[cell setLeaf: YES];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-01-27 00:03:42 +00:00
|
|
|
- (BOOL) browser: (NSBrowser *)sender
|
2014-01-26 12:01:38 +00:00
|
|
|
isColumnValid: (NSInteger)column;
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2000-02-22 17:49:28 +00:00
|
|
|
return NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2001-01-27 00:03:42 +00:00
|
|
|
|
|
|
|
@implementation NSFontPanel (NSSplitViewDelegate)
|
|
|
|
|
|
|
|
- (void) splitView: (NSSplitView *)splitView
|
2014-01-26 12:01:38 +00:00
|
|
|
constrainMinCoordinate: (CGFloat *)min
|
|
|
|
maxCoordinate: (CGFloat *)max
|
|
|
|
ofSubviewAt: (NSInteger)offset
|
2001-01-27 00:03:42 +00:00
|
|
|
{
|
|
|
|
*max = *max - 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|