Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Panel autosizing fix #299

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 105 additions & 4 deletions Source/NSFontPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,107 @@ @interface GSBrowserTitleCell : NSTextFieldCell
}
@end

@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

@interface NSFontPanel (Private)
- (NSFont*) _fontForSelection: (NSFont*) fontObject;

Expand Down Expand Up @@ -587,7 +688,7 @@ - (id) _initWithoutGModel

// Selection of the font family
// We use a browser with one column to get a selection list
familyBrowser = [[NSBrowser alloc] initWithFrame: familyBrowserRect];
familyBrowser = [[FPBrowser alloc] initWithFrame: familyBrowserRect];
[familyBrowser setDelegate: self];
[familyBrowser setMaxVisibleColumns: 1];
[familyBrowser setMinColumnWidth: 0];
Expand All @@ -608,7 +709,7 @@ - (id) _initWithoutGModel

// selection of type face
// We use a browser with one column to get a selection list
faceBrowser = [[NSBrowser alloc] initWithFrame: typefaceBrowserRect];
faceBrowser = [[FPBrowser alloc] initWithFrame: typefaceBrowserRect];
[faceBrowser setDelegate: self];
[faceBrowser setMaxVisibleColumns: 1];
[faceBrowser setMinColumnWidth: 0];
Expand Down Expand Up @@ -654,7 +755,7 @@ - (id) _initWithoutGModel
[bottomSplit addSubview: sizeField];
RELEASE(sizeField);

sizeBrowser = [[NSBrowser alloc] initWithFrame: sizeBrowserRect];
sizeBrowser = [[FPBrowser alloc] initWithFrame: sizeBrowserRect];
[sizeBrowser setDelegate: self];
[sizeBrowser setMaxVisibleColumns: 1];
[sizeBrowser setAllowsMultipleSelection: NO];
Expand Down Expand Up @@ -686,7 +787,7 @@ - (id) _initWithoutGModel

slash = [[NSBox alloc] initWithFrame: slashRect];
[slash setBorderType: NSGrooveBorder];
[slash setTitlePosition: NSNoTitle];
[slash setTitlePosition:NSNoTitle];
[slash setAutoresizingMask: NSViewWidthSizable];
[bottomArea addSubview: slash];
RELEASE(slash);
Expand Down
Loading