5#include <AppKit/AppKit.h>
7#include <qpa/qplatformtheme.h>
12#include <qpa/qplatformscreen.h>
13#include <private/qguiapplication_p.h>
14#include <private/qwindow_p.h>
15#include <QtGui/private/qcoregraphics_p.h>
26Q_LOGGING_CATEGORY(lcQpaScreen,
"qt.qpa.screen", QtCriticalMsg);
29Q_LOGGING_CATEGORY(lcQpaDialogs,
"qt.qpa.dialogs")
30Q_LOGGING_CATEGORY(lcQpaMenus,
"qt.qpa.menus")
36QStringList qt_mac_NSArrayToQStringList(NSArray<NSString *> *array)
39 for (NSString *string in array)
40 result << QString::fromNSString(string);
46 NSMutableArray<NSString *> *result = [NSMutableArray<NSString *> arrayWithCapacity:list.size()];
47 for (
const QString &string : list)
48 [result addObject:string.toNSString()];
60 { NSDragOperationLink, Qt::LinkAction,
true },
61 { NSDragOperationMove, Qt::MoveAction,
true },
62 { NSDragOperationDelete, Qt::MoveAction,
true },
63 { NSDragOperationCopy, Qt::CopyAction,
true },
64 { NSDragOperationGeneric, Qt::CopyAction,
false },
65 { NSDragOperationEvery, Qt::ActionMask,
false },
66 { NSDragOperationNone, Qt::IgnoreAction,
false }
71 for (
int i=0;
dnd_enums[i].qt_code; i++) {
76 return NSDragOperationNone;
81 NSDragOperation nsActions = NSDragOperationNone;
82 for (
int i=0;
dnd_enums[i].qt_code; i++) {
91 Qt::DropAction action = Qt::IgnoreAction;
92 for (
int i=0;
dnd_enums[i].mac_code; i++) {
101 Qt::DropActions actions = Qt::IgnoreAction;
103 for (
int i=0;
dnd_enums[i].mac_code; i++) {
104 if (dnd_enums[i].mac_code == NSDragOperationEvery)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
131 return qt_objc_cast<QNSView *>(view);
142 bool forceTransform =
true;
143 CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
144 CFSTR(
"LSUIElement"));
146 CFTypeID valueType = CFGetTypeID(value);
149 if (valueType == CFStringGetTypeID())
150 forceTransform = !(QString::fromCFString(
static_cast<CFStringRef>(value)).toInt());
151 else if (valueType == CFBooleanGetTypeID())
152 forceTransform = !CFBooleanGetValue(
static_cast<CFBooleanRef>(value));
153 else if (valueType == CFNumberGetTypeID()) {
155 CFNumberGetValue(
static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
156 forceTransform = !valueAsInt;
160 if (forceTransform) {
161 value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
162 CFSTR(
"LSBackgroundOnly"));
164 CFTypeID valueType = CFGetTypeID(value);
165 if (valueType == CFBooleanGetTypeID())
166 forceTransform = !CFBooleanGetValue(
static_cast<CFBooleanRef>(value));
167 else if (valueType == CFStringGetTypeID())
168 forceTransform = !(QString::fromCFString(
static_cast<CFStringRef>(value)).toInt());
169 else if (valueType == CFNumberGetTypeID()) {
171 CFNumberGetValue(
static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
172 forceTransform = !valueAsInt;
177 if (forceTransform) {
178 [[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
185 CFTypeRef string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR(
"CFBundleName"));
187 appName = QString::fromCFString(
static_cast<CFStringRef>(string));
189 if (appName.isEmpty()) {
190 QString arg0 = QGuiApplicationPrivate::instance()->appName();
191 if (arg0.contains(
"/")) {
192 QStringList parts = arg0.split(u'/');
193 appName = parts.at(parts.count() - 1);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
222 return QPointF(pos.x(), reference.height() - pos.y());
227 return QRectF(qt_mac_flip(rect.bottomLeft(), reference), rect.size());
233
234
235
236
237
238
239
240
241
244 if (buttonNum >= 0 && buttonNum <= 31)
245 return Qt::MouseButton(1 << buttonNum);
250
251
252
253
254
255
256
257
258
259
260
261
264 if (cocoaEvent2QtMouseEvent(event) == QEvent::MouseMove)
267 switch (event.type) {
268 case NSEventTypeRightMouseUp:
269 case NSEventTypeRightMouseDown:
270 return Qt::RightButton;
276 return cocoaButton2QtButton(event.buttonNumber);
280
281
282
283
286 switch (event.type) {
287 case NSEventTypeLeftMouseDown:
288 case NSEventTypeRightMouseDown:
289 case NSEventTypeOtherMouseDown:
290 return QEvent::MouseButtonPress;
292 case NSEventTypeLeftMouseUp:
293 case NSEventTypeRightMouseUp:
294 case NSEventTypeOtherMouseUp:
295 return QEvent::MouseButtonRelease;
297 case NSEventTypeLeftMouseDragged:
298 case NSEventTypeRightMouseDragged:
299 case NSEventTypeOtherMouseDragged:
300 return QEvent::MouseMove;
302 case NSEventTypeMouseMoved:
303 return QEvent::MouseMove;
313
314
315
316
319 return static_cast<Qt::MouseButton>(pressedMouseButtons & Qt::MouseButtonMask);
323
324
325
326
329 return cocoaMouseButtons2QtMouseButtons(NSEvent.pressedMouseButtons);
334 return QPlatformTheme::removeMnemonics(s).trimmed();
339 static const NSBundle *appKit = [NSBundle bundleForClass:NSApplication.
class];
343 return [appKit localizedStringForKey:key value:nil table:table];
349
350
351
352
353
354
355
356
357@implementation QNSPanelContentsWrapper {
359 NSButton *_cancelButton;
360 NSView *_panelContents;
361 NSEdgeInsets _panelContentsMargins;
364@synthesize okButton = _okButton;
365@synthesize cancelButton = _cancelButton;
366@synthesize panelContents = _panelContents;
367@synthesize panelContentsMargins = _panelContentsMargins;
369- (instancetype)initWithPanelDelegate:(id<QNSPanelDelegate>)panelDelegate
371 if ((self = [super initWithFrame:NSZeroRect])) {
373 _okButton = [self createButtonWithTitle:QPlatformDialogHelper::Ok];
374 _okButton.action = @selector(onOkClicked);
375 _okButton.target = panelDelegate;
376 _cancelButton = [self createButtonWithTitle:QPlatformDialogHelper::Cancel];
377 _cancelButton.action = @selector(onCancelClicked);
378 _cancelButton.target = panelDelegate;
380 _panelContents = nil;
382 _panelContentsMargins = NSEdgeInsetsMake(0, 0, 0, 0);
392 [_cancelButton release];
395 _panelContents = nil;
400- (NSButton *)createButtonWithTitle:(QPlatformDialogHelper::StandardButton)type
402 NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect];
403 button.buttonType = NSButtonTypeMomentaryLight;
404 button.bezelStyle = NSBezelStyleRounded;
405 const QString &cleanTitle =
406 QPlatformTheme::removeMnemonics(QGuiApplicationPrivate::platformTheme()->standardButtonText(type));
408 button.title = (NSString *)cleanTitle.toCFString();
409 ((NSButtonCell *)button.cell).font =
410 [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSControlSizeRegular]];
411 [self addSubview:button];
417 static const CGFloat ButtonMinWidth = 78.0;
418 static const CGFloat ButtonMinHeight = 32.0;
419 static const CGFloat ButtonSpacing = 0.0;
420 static const CGFloat ButtonTopMargin = 0.0;
421 static const CGFloat ButtonBottomMargin = 7.0;
422 static const CGFloat ButtonSideMargin = 9.0;
424 NSSize frameSize = self.frame.size;
426 [self.okButton sizeToFit];
427 NSSize okSizeHint = self.okButton.frame.size;
429 [self.cancelButton sizeToFit];
430 NSSize cancelSizeHint = self.cancelButton.frame.size;
432 const CGFloat buttonWidth = qMin(qMax(ButtonMinWidth,
433 qMax(okSizeHint.width, cancelSizeHint.width)),
434 CGFloat((frameSize.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5));
435 const CGFloat buttonHeight = qMax(ButtonMinHeight,
436 qMax(okSizeHint.height, cancelSizeHint.height));
438 NSRect okRect = { { frameSize.width - ButtonSideMargin - buttonWidth,
439 ButtonBottomMargin },
440 { buttonWidth, buttonHeight } };
441 self.okButton.frame = okRect;
442 self.okButton.needsDisplay = YES;
444 NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - buttonWidth,
445 ButtonBottomMargin },
446 { buttonWidth, buttonHeight } };
447 self.cancelButton.frame = cancelRect;
448 self.cancelButton.needsDisplay = YES;
451 if (!self.panelContents)
452 for (NSView *view in self.subviews)
453 if (view != self.okButton && view != self.cancelButton) {
454 _panelContents = view;
458 const CGFloat buttonBoxHeight = ButtonBottomMargin + buttonHeight + ButtonTopMargin;
459 const NSRect panelContentsFrame = NSMakeRect(
460 self.panelContentsMargins.left,
461 buttonBoxHeight + self.panelContentsMargins.bottom,
462 frameSize.width - (self.panelContentsMargins.left + self.panelContentsMargins.right),
463 frameSize.height - buttonBoxHeight - (self.panelContentsMargins.top + self.panelContentsMargins.bottom));
464 self.panelContents.frame = panelContentsFrame;
465 self.panelContents.needsDisplay = YES;
467 self.needsDisplay = YES;
477InputMethodQueryResult queryInputMethod(QObject *object, Qt::InputMethodQueries queries)
480 QInputMethodQueryEvent queryEvent(queries | Qt::ImEnabled);
481 if (QCoreApplication::sendEvent(object, &queryEvent)) {
482 if (queryEvent.value(Qt::ImEnabled).toBool()) {
483 InputMethodQueryResult result;
484 static QMetaEnum queryEnum = QMetaEnum::fromType<Qt::InputMethodQuery>();
485 for (
int i = 0; i < queryEnum.keyCount(); ++i) {
486 auto query = Qt::InputMethodQuery(queryEnum.value(i));
488 result.insert(query, queryEvent.value(query));
501 if (range.location == NSNotFound) {
502 QDebugStateSaver saver(debug);
503 debug.nospace() <<
"{NSNotFound, " << range.length <<
"}";
505 debug << NSStringFromRange(range);
512 debug << NSStringFromSelector(selector);
\inmodule QtCore\reentrant
Qt::MouseButtons cocoaMouseButtons2QtMouseButtons(NSInteger pressedMouseButtons)
Returns the Qt::MouseButtons that corresponds to an NSEvent.pressedMouseButtons.
NSString * qt_mac_AppKitString(NSString *table, NSString *key)
Qt::MouseButton cocoaButton2QtButton(NSEvent *event)
Returns the Qt::Button that corresponds to an NSEvent.buttonNumber.
QNSView * qnsview_cast(NSView *view)
Returns the view cast to a QNSview if possible.
QEvent::Type cocoaEvent2QtMouseEvent(NSEvent *event)
Returns the QEvent::Type that corresponds to an NSEvent.type.
Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions)
QString qt_mac_applicationName()
QPointF qt_mac_flip(const QPointF &pos, const QRectF &reference)
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
Returns the Qt::Button that corresponds to an NSEvent.buttonNumber.
void qt_mac_transformProccessToForegroundApplication()
static dndenum_mapper dnd_enums[]
NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions)
Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions)
QString qt_mac_removeAmpersandEscapes(QString s)
QRectF qt_mac_flip(const QRectF &rect, const QRectF &reference)
Flips the Y coordinate of the point/rect between quadrant I and IV.
NSDragOperation qt_mac_mapDropAction(Qt::DropAction action)
NSMutableArray< NSString * > * qt_mac_QStringListToNSMutableArray(const QStringList &list)
Qt::MouseButtons currentlyPressedMouseButtons()
Returns the Qt::MouseButtons that corresponds to an NSEvent.pressedMouseButtons.
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)