commit 2641b454cb61538ee0e751e7d51a57c832807162
Author: Koji Yokota <[email protected]>
Date: Sat Oct 31 14:53:17 2026 +0900
Move Cocoa code of MenusMacOS.mm into AppleSupport.m
Split greyOutBindings() into the Qt part, which stays in Menus.cpp,
and the Cocoa part, which is moved to appleGreyOutMenuSuffixes() in
support/AppleSupport.m. This removes the only Objective-C++ source
and the Objective-C++ build setup introduced in commit abb138b6.
Assisted-by: Claude (Opus 5.5)
---
configure.ac | 4 ---
src/frontends/qt/CMakeLists.txt | 12 ++-----
src/frontends/qt/Makefile.am | 5 ---
src/frontends/qt/Menus.cpp | 44 +++++++++++++++++++++---
src/frontends/qt/MenusMacOS.mm | 75 -----------------------------------------
src/support/AppleSupport.h | 3 ++
src/support/AppleSupport.m | 27 +++++++++++++++
7 files changed, 71 insertions(+), 99 deletions(-)
diff --git a/configure.ac b/configure.ac
index 4e49e9c8fd..1dae44109a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,10 +67,6 @@ AC_LANG(C++)
AC_PROG_OBJC
_AM_DEPENDENCIES([OBJC])
-### Objective-C++ compiler
-AC_PROG_OBJCXX
-_AM_DEPENDENCIES([OBJCXX])
-
### Add extra directories to check for libraries.
LYX_WITH_DIR([extra-lib],[extra library directory],extra_lib, NONE)
LYX_LOOP_DIR($lyx_cv_extra_lib,LYX_ADD_LIB_DIR(lyx_ldflags,$dir))
diff --git a/src/frontends/qt/CMakeLists.txt b/src/frontends/qt/CMakeLists.txt
index ab2ecfb8c2..05d4c4abf4 100644
--- a/src/frontends/qt/CMakeLists.txt
+++ b/src/frontends/qt/CMakeLists.txt
@@ -27,12 +27,6 @@ file(GLOB moc_files
${TOP_SRC_DIR}/src/frontends/qt/${LYX_MOC_FILES})
list(REMOVE_ITEM frontends_qt_sources ${moc_files} .)
-if(APPLE)
- set(frontends_qt_objcxx_sources
${TOP_SRC_DIR}/src/frontends/qt/MenusMacOS.mm)
-else()
- set(frontends_qt_objcxx_sources "")
-endif()
-
file(GLOB frontends_qt_headers
${TOP_SRC_DIR}/src/frontends/qt/${LYX_HPP_FILES})
file(GLOB frontend_qt_UI ${TOP_SRC_DIR}/src/frontends/qt/ui/*.ui)
@@ -63,9 +57,9 @@ if(LYX_MERGE_FILES)
set_source_files_properties(_allinone_const.C PROPERTIES OBJECT_DEPENDS
"${depends_moc_uic}")
set_source_files_properties(_allinone_touched.C PROPERTIES
OBJECT_DEPENDS "${depends_moc_uic}")
add_library(frontend_qt ${library_type}
- ${_allinone_files} ${frontends_qt_objcxx_sources}
${frontends_qt_headers} ${ui_files} ${resource_files})
+ ${_allinone_files} ${frontends_qt_headers} ${ui_files}
${resource_files})
else()
- add_library(frontend_qt ${library_type} ${frontends_qt_sources}
${frontends_qt_objcxx_sources} ${frontends_qt_headers} ${ui_files}
${resource_files})
+ add_library(frontend_qt ${library_type} ${frontends_qt_sources}
${frontends_qt_headers} ${ui_files} ${resource_files})
endif()
set_target_properties(frontend_qt PROPERTIES FOLDER "applications/LyX"
QT_NO_UNICODE_DEFINES TRUE)
@@ -89,8 +83,6 @@ lyx_add_gcc_pch(frontend_qt)
if(WIN32)
target_link_libraries(frontend_qt gdi32)
-elseif(APPLE)
- target_link_libraries(frontend_qt "-framework AppKit")
endif()
project_source_group("${GROUP_CODE}" frontends_qt_sources frontends_qt_headers)
diff --git a/src/frontends/qt/Makefile.am b/src/frontends/qt/Makefile.am
index 4705295799..e87478abe8 100644
--- a/src/frontends/qt/Makefile.am
+++ b/src/frontends/qt/Makefile.am
@@ -365,9 +365,4 @@ liblyxqt_a_SOURCES = \
$(MOCHEADER) \
$(NOMOCHEADER)
-if INSTALL_MACOSX
-liblyxqt_a_SOURCES += MenusMacOS.mm
-AM_OBJCXXFLAGS = $(AM_CXXFLAGS)
-endif
-
EXTRA_DIST = CMakeLists.txt $(UIFILES:%=ui/%)
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index e630235bbd..91bf977cd0 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -72,7 +72,12 @@
#include "support/Lexer.h"
#include "support/lstrings.h"
+#ifdef Q_OS_MACOS
+#include "support/AppleSupport.h"
+#endif
+
#include <QHash>
+#include <QKeySequence>
#include <QList>
#include <QMenuBar>
#include <QProxyStyle>
@@ -89,14 +94,43 @@ using namespace lyx::support;
namespace lyx {
namespace frontend {
+namespace {
+
#if defined(Q_OS_MACOS)
-// Defined in MenusMacOS.mm. Shows the key bindings appended to the labels of
-// the native menu items of \p qmenu (and its submenus) in a dimmed color.
-void greyOutBindings(QMenu * qmenu);
+// Mimic the original macOS menu style so that shortcuts are presented as
+// a greyed-out color in the native menu items of \p qmenu (and its submenus)
+void greyOutBindings(QMenu * qmenu)
+{
+ // The native menu may contain items added by macOS itself (e.g. in the
+ // Edit menu), so we cannot rely on the native items and the Qt actions
+ // matching one to one. Look for the binding suffixes in the titles
instead.
+ vector<string> suffixes;
+ for (QAction * act : qmenu->actions()) {
+ if (QMenu * sub = act->menu())
+ greyOutBindings(sub);
+ QString const binding = act->property("lyx_binding").toString();
+ if (binding.isEmpty())
+ continue;
+ // Qt parses the text after '\t' of the label. A single key is
+ // registered as a native key equivalent and drawn by AppKit,
while
+ // a longer sequence is appended to the title as " (...)"
+ // (see QCocoaMenuItem::sync())
+ QKeySequence const seq(binding, QKeySequence::NativeText);
+ if (seq.count() > 1)
+ suffixes.push_back(fromqstr(" (" +
seq.toString(QKeySequence::NativeText) + ')'));
+ }
+ if (suffixes.empty())
+ return;
+ void * nsmenu = qmenu->toNSMenu();
+ if (!nsmenu)
+ return;
+ vector<char const *> csuffixes;
+ for (string const & s : suffixes)
+ csuffixes.push_back(s.c_str());
+ appleGreyOutMenuSuffixes(nsmenu, csuffixes.data(),
int(csuffixes.size()));
+}
#endif
-namespace {
-
// macOS specific stuff is at the end.
class MenuDefinition;
diff --git a/src/frontends/qt/MenusMacOS.mm b/src/frontends/qt/MenusMacOS.mm
deleted file mode 100644
index 7f2a9b9627..0000000000
--- a/src/frontends/qt/MenusMacOS.mm
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * \file MenusMacOS.mm
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Koji Yokota
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include <QAction>
-#include <QKeySequence>
-#include <QList>
-#include <QMenu>
-#include <QString>
-
-#import <AppKit/AppKit.h>
-
-
-namespace lyx {
-namespace frontend {
-
-// Mimic the original macOS menu style so that shortcuts are presented as
-// a greyed-out color
-void greyOutBindings(QMenu * qmenu)
-{
- NSMenu * nsmenu = qmenu->toNSMenu();
- if (!nsmenu)
- return;
- // The native menu may contain items added by macOS itself (e.g. in the
- // Edit menu), so we cannot rely on the native items and the Qt actions
- // matching one to one. Look for the binding suffixes in the titles
instead.
- NSMutableArray<NSString *> * suffixes = [NSMutableArray array];
- for (QAction * act : qmenu->actions()) {
- if (QMenu * sub = act->menu())
- greyOutBindings(sub);
- QString const binding = act->property("lyx_binding").toString();
- if (binding.isEmpty())
- continue;
- // Qt parses the text after '\t' of the label. A single key is
- // registered as a native key equivalent and drawn by AppKit,
while
- // a longer sequence is appended to the title as " (...)"
- // (see QCocoaMenuItem::sync())
- QKeySequence const seq(binding, QKeySequence::NativeText);
- if (seq.count() > 1)
- [suffixes addObject:(" (" +
seq.toString(QKeySequence::NativeText)
- + ')').toNSString()];
- }
- if (suffixes.count == 0)
- return;
- for (NSMenuItem * item in nsmenu.itemArray) {
- NSString * title = item.title;
- NSString * suffix = nil;
- for (NSString * s in suffixes)
- if ([title hasSuffix:s]) {
- suffix = s;
- break;
- }
- if (!suffix)
- continue;
- NSMutableAttributedString * str = [[NSMutableAttributedString
alloc]
- initWithString:title
- attributes:@{NSFontAttributeName : [NSFont
menuFontOfSize:0]}];
- [str addAttribute:NSForegroundColorAttributeName
- value:[NSColor disabledControlTextColor]
- range:NSMakeRange(title.length - suffix.length,
suffix.length)];
- item.attributedTitle = str;
- [str release];
- }
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/support/AppleSupport.h b/src/support/AppleSupport.h
index b2cfb415f1..da6cae8251 100644
--- a/src/support/AppleSupport.h
+++ b/src/support/AppleSupport.h
@@ -19,6 +19,9 @@ extern "C" {
void appleCleanupViewMenu();
// stop the Cocoa text system from swallowing Control-Q as "quote next
key"
void appleDisableQuotedKeystroke();
+ // show the given title suffixes (multi-stroke key bindings appended by
Qt)
+ // of the items in the NSMenu nsmenu in a greyed-out color
+ void appleGreyOutMenuSuffixes(void * nsmenu, char const * const *
suffixes, int count);
// query the system preferences for users tabbing preference
bool appleUserTabbingPreferenceAlways();
diff --git a/src/support/AppleSupport.m b/src/support/AppleSupport.m
index 1a70b77856..3b5f2c60dd 100644
--- a/src/support/AppleSupport.m
+++ b/src/support/AppleSupport.m
@@ -48,6 +48,33 @@ void appleDisableQuotedKeystroke() {
}
+void appleGreyOutMenuSuffixes(void * menu, char const * const * suffixes, int
count) {
+ NSMenu * nsmenu = (NSMenu *)menu;
+ NSMutableArray<NSString *> * nssuffixes = [NSMutableArray
arrayWithCapacity:count];
+ for (int i = 0; i < count; ++i)
+ [nssuffixes addObject:[NSString
stringWithUTF8String:suffixes[i]]];
+ for (NSMenuItem * item in nsmenu.itemArray) {
+ NSString * title = item.title;
+ NSString * suffix = nil;
+ for (NSString * s in nssuffixes)
+ if ([title hasSuffix:s]) {
+ suffix = s;
+ break;
+ }
+ if (!suffix)
+ continue;
+ NSMutableAttributedString * str = [[NSMutableAttributedString
alloc]
+ initWithString:title
+ attributes:@{NSFontAttributeName : [NSFont
menuFontOfSize:0]}];
+ [str addAttribute:NSForegroundColorAttributeName
+ value:[NSColor disabledControlTextColor]
+ range:NSMakeRange(title.length - suffix.length,
suffix.length)];
+ item.attributedTitle = str;
+ [str release];
+ }
+}
+
+
bool appleUserTabbingPreferenceAlways() {
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED
>= 101200)
return [NSWindow respondsToSelector:@selector(userTabbingPreference)] &&
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs