Skip to content

Commit

Permalink
Merge branch 'master' into NSBrowser_bindings_branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Oct 14, 2024
2 parents 5a16976 + 40fc3ab commit 5fd4ff0
Showing 1 changed file with 105 additions and 4 deletions.
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

0 comments on commit 5fd4ff0

Please sign in to comment.