14#include <QtGui/QGuiApplication>
15#include <QtCore/QDebug>
17#include <QtCore/private/qcore_mac_p.h>
18#include <QtGui/private/qguiapplication_p.h>
33 m_nativeMenu = [[NSMenu alloc]
init];
34 qCDebug(lcQpaMenus) <<
"Constructed" <<
this <<
"with" << m_nativeMenu;
39 qCDebug(lcQpaMenus) <<
"Destructing" <<
this <<
"with" << m_nativeMenu;;
40 for (
auto menu : std::as_const(m_menus)) {
43 NSMenuItem *
item = nativeItemForMenu(
menu);
45 menu->setAttachedItem(nil);
62bool QCocoaMenuBar::needsImmediateUpdate()
65 if (m_window->
window()->isActive())
78 if (
cw && !
cw->menubar())
94 qCDebug(lcQpaMenus) <<
"Inserting" <<
menu <<
"before" << before <<
"into" <<
this;
97 qCWarning(lcQpaMenus,
"This menu already belongs to the menubar, remove it first");
102 qCWarning(lcQpaMenus,
"The before menu does not belong to the menubar");
106 int insertionIndex = beforeMenu ? m_menus.
indexOf(beforeMenu) : m_menus.
size();
111 NSMenuItem *
item = [[[NSMenuItem alloc]
init] autorelease];
118 NSMenuItem *beforeItem = nativeItemForMenu(beforeMenu);
119 NSInteger nativeIndex = [m_nativeMenu indexOfItem:beforeItem];
120 [m_nativeMenu insertItem:
item atIndex:nativeIndex];
128 if (needsImmediateUpdate())
136 qCWarning(lcQpaMenus) <<
"Trying to remove" <<
menu <<
"that does not belong to" <<
this;
140 NSMenuItem *
item = nativeItemForMenu(
menu);
142 menu->setAttachedItem(nil);
149 [m_nativeMenu removeItemAtIndex:nativeIndex];
165 BOOL shouldHide = YES;
171 if (!
item.separatorItem && !
item.hidden) {
180 NSString *menuTitle = cocoaMenu->
nsMenu().title;
206 if ([menuTitle
isEqual:
@"Edit"] || [menuTitle
isEqual:
tr(
"Edit").toNSString()]) {
207 static const NSBundle *appKit = [NSBundle bundleForClass:NSApplication.class];
208 menuItem.title = [appKit localizedStringForKey:
@"Edit" value:menuTitle
table:
@"InputManager"];
212 menuItem.title = menuTitle;
215 menuItem.hidden = shouldHide;
219NSMenuItem *QCocoaMenuBar::nativeItemForMenu(
QCocoaMenu *
menu)
const
224 return [m_nativeMenu itemWithTag:
reinterpret_cast<NSInteger>(
menu)];
229 qCDebug(lcQpaMenus) <<
"Reparenting" <<
this <<
"to" << newParentWindow;
234 if (!newParentWindow) {
237 newParentWindow->create();
238 m_window =
static_cast<QCocoaWindow*
>(newParentWindow->handle());
247 return m_window ? m_window->
window() :
nullptr;
253 if (
qApp->focusWindow())
262 if (menubar->m_window.isNull())
282 NSApplication *
app = [NSApplication sharedApplication];
287 if (!appDelegate.inLaunch)
291 if (
cw &&
cw->menubar())
297 qCDebug(lcQpaMenus) <<
"Updating" << mb <<
"immediately for" <<
cw;
299 bool disableForModal = mb->shouldDisable(
cw);
301 for (
auto menu : std::as_const(mb->m_menus)) {
304 NSMenuItem *
item = mb->nativeItemForMenu(
menu);
306 menu->setMenuParent(mb);
309 menu->propagateEnabledState(!disableForModal);
315 NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:mb->
merged().
count()] retain];
316 for (
auto mergedItem : mb->
merged()) {
317 [mergedItems addObject:mergedItem->nsItem()];
318 mergedItem->syncMerged();
322 for (NSMenuItem *mergeable
in [
loader mergeable]) {
323 if (![mergedItems containsObject:mergeable]) {
324 mergeable.hidden = YES;
325 mergeable.enabled = NO;
330 [NSApp setMainMenu:mb->
nsMenu()];
332 [
loader qtTranslateApplicationMenu];
340 NSApplication *
app = NSApplication.sharedApplication;
344 NSMenu *mainMenu =
app.mainMenu;
345 NSMenuItem *winMenuItem = [[[NSMenuItem alloc] initWithTitle:
@"QtWindowMenu"
346 action:nil keyEquivalent:
@""] autorelease];
348 winMenuItem.hidden = YES;
350 winMenuItem.submenu = [[[NSMenu alloc] initWithTitle:
@"QtWindowMenu"] autorelease];
351 [mainMenu insertItem:winMenuItem atIndex:mainMenu.itemArray.count];
352 app.windowsMenu = winMenuItem.submenu;
361 for (NSWindow *
win in app.windows) {
362 win.excludedFromWindowsMenu = !
win.excludedFromWindowsMenu;
363 win.excludedFromWindowsMenu = !
win.excludedFromWindowsMenu;
370 for (
auto menu : std::as_const(m_menus)) {
373 r.append(
menu->merged());
379bool QCocoaMenuBar::shouldDisable(
QCocoaWindow *active)
const
384 if (m_window == active) {
393 for (
auto *
window :
std::as_const(topWindows)) {
396 for (
auto *
other :
std::as_const(topWindows)) {
417 for (
auto menu : std::as_const(m_menus))
426 for (
auto menu : std::as_const(m_menus)) {
429 if (
item->effectiveRole() == role)
430 return item->nsItem();
439 return m_window.
data();
444#include "moc_qcocoamenubar.cpp"
static bool isEqual(const aiUVTransform &a, const aiUVTransform &b)
void setMenubar(QCocoaMenuBar *mb)
QCocoaMenuBar * menubar() const
virtual bool closeAllPopups()
static QGuiApplicationPrivate * instance()
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
qsizetype size() const noexcept
iterator insert(qsizetype i, parameter_type t)
bool removeOne(const AT &t)
qsizetype count() const noexcept
const QObjectList & children() const
Returns a list of child objects.
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Qt::WindowModality modality
the modality of the window
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
#define qCDebug(category,...)
GLenum GLenum GLsizei void * table
static const struct TessellationWindingOrderTab cw[]
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QApplication app(argc, argv)
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
bool contains(const AT &t) const noexcept