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")
31Q_LOGGING_CATEGORY(lcQpaAccessibility,
"qt.qpa.accessibility")
37QStringList qt_mac_NSArrayToQStringList(NSArray<NSString *> *array)
40 for (NSString *string in array)
41 result << QString::fromNSString(string);
47 NSMutableArray<NSString *> *result = [NSMutableArray<NSString *> arrayWithCapacity:list.size()];
48 for (
const QString &string : list)
49 [result addObject:string.toNSString()];
61 { NSDragOperationLink, Qt::LinkAction,
true },
62 { NSDragOperationMove, Qt::MoveAction,
true },
63 { NSDragOperationDelete, Qt::MoveAction,
true },
64 { NSDragOperationCopy, Qt::CopyAction,
true },
65 { NSDragOperationGeneric, Qt::CopyAction,
false },
66 { NSDragOperationEvery, Qt::ActionMask,
false },
67 { NSDragOperationNone, Qt::IgnoreAction,
false }
72 for (
int i=0;
dnd_enums[i].qt_code; i++) {
77 return NSDragOperationNone;
82 NSDragOperation nsActions = NSDragOperationNone;
83 for (
int i=0;
dnd_enums[i].qt_code; i++) {
92 Qt::DropAction action = Qt::IgnoreAction;
93 for (
int i=0;
dnd_enums[i].mac_code; i++) {
102 Qt::DropActions actions = Qt::IgnoreAction;
104 for (
int i=0;
dnd_enums[i].mac_code; i++) {
105 if (dnd_enums[i].mac_code == NSDragOperationEvery)
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
132 return qt_objc_cast<QNSView *>(view);
143 bool forceTransform =
true;
144 CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
145 CFSTR(
"LSUIElement"));
147 CFTypeID valueType = CFGetTypeID(value);
150 if (valueType == CFStringGetTypeID())
151 forceTransform = !(QString::fromCFString(
static_cast<CFStringRef>(value)).toInt());
152 else if (valueType == CFBooleanGetTypeID())
153 forceTransform = !CFBooleanGetValue(
static_cast<CFBooleanRef>(value));
154 else if (valueType == CFNumberGetTypeID()) {
156 CFNumberGetValue(
static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
157 forceTransform = !valueAsInt;
161 if (forceTransform) {
162 value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
163 CFSTR(
"LSBackgroundOnly"));
165 CFTypeID valueType = CFGetTypeID(value);
166 if (valueType == CFBooleanGetTypeID())
167 forceTransform = !CFBooleanGetValue(
static_cast<CFBooleanRef>(value));
168 else if (valueType == CFStringGetTypeID())
169 forceTransform = !(QString::fromCFString(
static_cast<CFStringRef>(value)).toInt());
170 else if (valueType == CFNumberGetTypeID()) {
172 CFNumberGetValue(
static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
173 forceTransform = !valueAsInt;
178 if (forceTransform) {
179 [[NSApplication sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
186 CFTypeRef string = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), CFSTR(
"CFBundleName"));
188 appName = QString::fromCFString(
static_cast<CFStringRef>(string));
190 if (appName.isEmpty()) {
191 QString arg0 = QGuiApplicationPrivate::instance()->appName();
192 if (arg0.contains(
"/")) {
193 QStringList parts = arg0.split(u'/');
194 appName = parts.at(parts.count() - 1);
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
223 return QPointF(pos.x(), reference.height() - pos.y());
228 return QRectF(qt_mac_flip(rect.bottomLeft(), reference), rect.size());
234
235
236
237
238
239
240
241
242
245 if (buttonNum >= 0 && buttonNum <= 31)
246 return Qt::MouseButton(1 << buttonNum);
251
252
253
254
255
256
257
258
259
260
261
262
265 if (cocoaEvent2QtMouseEvent(event) == QEvent::MouseMove)
268 switch (event.type) {
269 case NSEventTypeRightMouseUp:
270 case NSEventTypeRightMouseDown:
271 return Qt::RightButton;
277 return cocoaButton2QtButton(event.buttonNumber);
281
282
283
284
287 switch (event.type) {
288 case NSEventTypeLeftMouseDown:
289 case NSEventTypeRightMouseDown:
290 case NSEventTypeOtherMouseDown:
291 return QEvent::MouseButtonPress;
293 case NSEventTypeLeftMouseUp:
294 case NSEventTypeRightMouseUp:
295 case NSEventTypeOtherMouseUp:
296 return QEvent::MouseButtonRelease;
298 case NSEventTypeLeftMouseDragged:
299 case NSEventTypeRightMouseDragged:
300 case NSEventTypeOtherMouseDragged:
301 return QEvent::MouseMove;
303 case NSEventTypeMouseMoved:
304 return QEvent::MouseMove;
315 return cocoaEvent2QtMouseEvent(event) != QEvent::None;
319
320
321
322
325 return static_cast<Qt::MouseButton>(pressedMouseButtons & Qt::MouseButtonMask);
329
330
331
332
335 return cocoaMouseButtons2QtMouseButtons(NSEvent.pressedMouseButtons);
340 return QPlatformTheme::removeMnemonics(s).trimmed();
345 static const NSBundle *appKit = [NSBundle bundleForClass:NSApplication.
class];
349 return [appKit localizedStringForKey:key value:nil table:table];
355
356
357
358
359
360
361
362
363@implementation QNSPanelContentsWrapper {
365 NSButton *_cancelButton;
366 NSView *_panelContents;
367 NSEdgeInsets _panelContentsMargins;
370@synthesize okButton = _okButton;
371@synthesize cancelButton = _cancelButton;
372@synthesize panelContents = _panelContents;
373@synthesize panelContentsMargins = _panelContentsMargins;
375- (instancetype)initWithPanelDelegate:(id<QNSPanelDelegate>)panelDelegate
377 if ((self = [super initWithFrame:NSZeroRect])) {
379 _okButton = [self createButtonWithTitle:QPlatformDialogHelper::Ok];
380 _okButton.action = @selector(onOkClicked);
381 _okButton.target = panelDelegate;
382 _cancelButton = [self createButtonWithTitle:QPlatformDialogHelper::Cancel];
383 _cancelButton.action = @selector(onCancelClicked);
384 _cancelButton.target = panelDelegate;
386 _panelContents = nil;
388 _panelContentsMargins = NSEdgeInsetsMake(0, 0, 0, 0);
398 [_cancelButton release];
401 _panelContents = nil;
406- (NSButton *)createButtonWithTitle:(QPlatformDialogHelper::StandardButton)type
408 NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect];
409 button.buttonType = NSButtonTypeMomentaryLight;
410 button.bezelStyle = NSBezelStyleRounded;
411 const QString &cleanTitle =
412 QPlatformTheme::removeMnemonics(QGuiApplicationPrivate::platformTheme()->standardButtonText(type));
414 button.title = (NSString *)cleanTitle.toCFString();
415 ((NSButtonCell *)button.cell).font =
416 [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSControlSizeRegular]];
417 [self addSubview:button];
423 static const CGFloat ButtonMinWidth = 78.0;
424 static const CGFloat ButtonMinHeight = 32.0;
425 static const CGFloat ButtonSpacing = 0.0;
426 static const CGFloat ButtonTopMargin = 0.0;
427 static const CGFloat ButtonBottomMargin = 7.0;
428 static const CGFloat ButtonSideMargin = 9.0;
430 NSSize frameSize = self.frame.size;
432 [self.okButton sizeToFit];
433 NSSize okSizeHint = self.okButton.frame.size;
435 [self.cancelButton sizeToFit];
436 NSSize cancelSizeHint = self.cancelButton.frame.size;
438 const CGFloat buttonWidth = qMin(qMax(ButtonMinWidth,
439 qMax(okSizeHint.width, cancelSizeHint.width)),
440 CGFloat((frameSize.width - 2.0 * ButtonSideMargin - ButtonSpacing) * 0.5));
441 const CGFloat buttonHeight = qMax(ButtonMinHeight,
442 qMax(okSizeHint.height, cancelSizeHint.height));
444 NSRect okRect = { { frameSize.width - ButtonSideMargin - buttonWidth,
445 ButtonBottomMargin },
446 { buttonWidth, buttonHeight } };
447 self.okButton.frame = okRect;
448 self.okButton.needsDisplay = YES;
450 NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - buttonWidth,
451 ButtonBottomMargin },
452 { buttonWidth, buttonHeight } };
453 self.cancelButton.frame = cancelRect;
454 self.cancelButton.needsDisplay = YES;
457 if (!self.panelContents)
458 for (NSView *view in self.subviews)
459 if (view != self.okButton && view != self.cancelButton) {
460 _panelContents = view;
464 const CGFloat buttonBoxHeight = ButtonBottomMargin + buttonHeight + ButtonTopMargin;
465 const NSRect panelContentsFrame = NSMakeRect(
466 self.panelContentsMargins.left,
467 buttonBoxHeight + self.panelContentsMargins.bottom,
468 frameSize.width - (self.panelContentsMargins.left + self.panelContentsMargins.right),
469 frameSize.height - buttonBoxHeight - (self.panelContentsMargins.top + self.panelContentsMargins.bottom));
470 self.panelContents.frame = panelContentsFrame;
471 self.panelContents.needsDisplay = YES;
473 self.needsDisplay = YES;
483InputMethodQueryResult queryInputMethod(QObject *object, Qt::InputMethodQueries queries)
486 QInputMethodQueryEvent queryEvent(queries | Qt::ImEnabled);
487 if (QCoreApplication::sendEvent(object, &queryEvent)) {
488 if (queryEvent.value(Qt::ImEnabled).toBool()) {
489 InputMethodQueryResult result;
490 static QMetaEnum queryEnum = QMetaEnum::fromType<Qt::InputMethodQuery>();
491 for (
int i = 0; i < queryEnum.keyCount(); ++i) {
492 auto query = Qt::InputMethodQuery(queryEnum.value(i));
494 result.insert(query, queryEvent.value(query));
507 if (range.location == NSNotFound) {
508 QDebugStateSaver saver(debug);
509 debug.nospace() <<
"{NSNotFound, " << range.length <<
"}";
511 debug << NSStringFromRange(range);
518 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.
bool qt_mac_isMouseEvent(NSEvent *event)
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.
QDebug operator<<(QDebug debug, QDir::Filters filters)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)