QMacStyle: Move NSScrollers into cocoaControl() logic

This patch amends b113107419.

Change-Id: Ib305554763457ae4b5a441e41947304cff2853a2
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
bb10
Gabriel de Dietrich 2017-05-15 13:23:08 -07:00
parent d422ba6b4a
commit cdc5f7ab5c
2 changed files with 11 additions and 15 deletions

View File

@ -1873,6 +1873,12 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const
bv = [[NSPopUpButton alloc] init];
else if (widget.first == QCocoaComboBox)
bv = [[NSComboBox alloc] init];
else if (widget.first == QCocoaHorizontalScroller)
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
else if (widget.first == QCocoaVerticalScroller)
// Cocoa sets the orientation from the view's frame
// at construction time, and it cannot be changed later.
bv = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
else if (widget.first == QCocoaHorizontalSlider)
bv = [[NSSlider alloc] init];
else if (widget.first == QCocoaVerticalSlider)
@ -2145,12 +2151,6 @@ QMacStyle::QMacStyle()
name:NSPreferredScrollerStyleDidChangeNotification
object:nil];
// Create scroller objects. Scroller internal direction setup happens
// on initWithFrame and cannot be changed later on. Create two scrollers
// initialized with fake geometry. Correct geometry is set at draw time.
d->horizontalScroller = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 200, 20)];
d->verticalScroller = [[NSScroller alloc] initWithFrame:NSMakeRect(0, 0, 20, 200)];
d->indicatorBranchButtonCell = nil;
}
@ -2159,9 +2159,6 @@ QMacStyle::~QMacStyle()
Q_D(QMacStyle);
QMacAutoReleasePool pool;
[d->horizontalScroller release];
[d->verticalScroller release];
NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver);
[[NSNotificationCenter defaultCenter] removeObserver:receiver];
[receiver release];
@ -5383,7 +5380,9 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
d->setupNSGraphicsContext(cg, NO);
NSScroller *scroller = isHorizontal ? d->horizontalScroller : d-> verticalScroller;
const QCocoaWidget cw(isHorizontal ? QCocoaHorizontalScroller : QCocoaVerticalScroller,
tdi.kind == kThemeSmallScrollBar ? QStyleHelper::SizeMini : QStyleHelper::SizeLarge);
NSScroller *scroller = static_cast<NSScroller *>(d->cocoaControl(cw));
// mac os behaviour: as soon as one color channel is >= 128,
// the bg is considered bright, scroller is dark
const QColor bgColor = QStyleHelper::backgroundColor(opt->palette, widget);
@ -5394,8 +5393,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
else
[scroller setKnobStyle:NSScrollerKnobStyleDefault];
[scroller setControlSize:(tdi.kind == kThemeSmallScrollBar ? NSMiniControlSize
: NSRegularControlSize)];
[scroller setBounds:NSMakeRect(0, 0, slider->rect.width(), slider->rect.height())];
[scroller setScrollerStyle:NSScrollerStyleOverlay];

View File

@ -118,7 +118,6 @@
Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(CGContext);
Q_FORWARD_DECLARE_OBJC_CLASS(NSView);
Q_FORWARD_DECLARE_OBJC_CLASS(NSScroller);
QT_BEGIN_NAMESPACE
@ -143,6 +142,8 @@ enum QCocoaWidgetKind {
QCocoaPullDownButton, // QPushButton with menu
QCocoaPushButton,
QCocoaRadioButton,
QCocoaHorizontalScroller,
QCocoaVerticalScroller,
QCocoaHorizontalSlider,
QCocoaVerticalSlider
};
@ -251,8 +252,6 @@ public:
CFAbsoluteTime defaultButtonStart;
bool mouseDown;
void* receiver;
NSScroller *horizontalScroller;
NSScroller *verticalScroller;
void *indicatorBranchButtonCell;
NSView *backingStoreNSView;
QHash<QCocoaWidget, NSView *> cocoaControls;