Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qcocoainputcontext.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <AppKit/AppKit.h>
5
6#include "qnsview.h"
9#include "qcocoawindow.h"
10#include "qcocoahelpers.h"
11
12#include <Carbon/Carbon.h>
13
14#include <QtCore/QRect>
15#include <QtGui/QGuiApplication>
16#include <QtGui/QWindow>
17
19
47 , m_focusWindow(QGuiApplication::focusWindow())
48{
49 m_inputSourceObserver = QMacNotificationObserver(nil,
50 NSTextInputContextKeyboardSelectionDidChangeNotification, [&]() {
51 qCDebug(lcQpaInputMethods) << "Text input source changed";
53 });
54
56}
57
61
68{
69 qCDebug(lcQpaInputMethods) << "Committing composition";
70
71 if (!m_focusWindow)
72 return;
73
74 auto *platformWindow = m_focusWindow->handle();
75 if (!platformWindow)
76 return;
77
78 auto *cocoaWindow = static_cast<QCocoaWindow *>(platformWindow);
79 QNSView *view = qnsview_cast(cocoaWindow->view());
80 if (!view)
81 return;
82
83 [view unmarkText];
84
85 [view.inputContext discardMarkedText];
86 if (view.inputContext != NSTextInputContext.currentInputContext) {
87 // discardMarkedText will activate the TSM document of the given input context,
88 // which may not match the current input context. To ensure the current input
89 // context is not left in an inconsistent state with a deactivated document
90 // we need to manually activate it here.
91 [NSTextInputContext.currentInputContext activate];
92 }
93}
94
95
100{
101 qCDebug(lcQpaInputMethods) << "Resetting input method";
102
103 if (!m_focusWindow)
104 return;
105
106 QCocoaWindow *window = static_cast<QCocoaWindow *>(m_focusWindow->handle());
107 QNSView *view = qnsview_cast(window->view());
108 if (!view)
109 return;
110
111 if (NSTextInputContext *ctxt = [NSTextInputContext currentInputContext]) {
112 [ctxt discardMarkedText];
113 [view unmarkText];
114 }
115}
116
118{
119 qCDebug(lcQpaInputMethods) << "Focus object changed to" << focusObject;
120
121 if (m_focusWindow == QGuiApplication::focusWindow()) {
122 if (!m_focusWindow)
123 return;
124
125 QCocoaWindow *window = static_cast<QCocoaWindow *>(m_focusWindow->handle());
126 if (!window)
127 return;
128 QNSView *view = qnsview_cast(window->view());
129 if (!view)
130 return;
131
132 if (NSTextInputContext *ctxt = [NSTextInputContext currentInputContext]) {
133 [ctxt discardMarkedText];
134 [view cancelComposingText];
135 }
136 } else {
137 m_focusWindow = QGuiApplication::focusWindow();
138 }
139}
140
142{
143 QCFType<TISInputSourceRef> source = TISCopyCurrentKeyboardInputSource();
144 NSArray *languages = static_cast<NSArray*>(TISGetInputSourceProperty(source,
145 kTISPropertyInputSourceLanguages));
146
147 qCDebug(lcQpaInputMethods) << "Input source supports" << languages;
148 if (!languages.count)
149 return;
150
151 QString language = QString::fromNSString(languages.firstObject);
153
154 bool localeUpdated = m_locale != locale;
155 static bool firstUpdate = true;
156
157 m_locale = locale;
158
159 if (localeUpdated && !firstUpdate) {
160 qCDebug(lcQpaInputMethods) << "Reporting new locale" << locale;
162 }
163
164 firstUpdate = false;
165}
166
void reset() override
Cancels a composition.
QLocale locale() const override
void setFocusObject(QObject *object) override
This virtual method gets called to notify updated focus to object.
void commit() override
Commits the current composition if there is one, by "unmarking" the text in the edit buffer,...
\macro qGuiApp
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
\inmodule QtCore
Definition qobject.h:103
The QPlatformInputContext class abstracts the input method dependent data and composing state.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
QNSView * qnsview_cast(NSView *view)
Returns the view cast to a QNSview if possible.
#define qCDebug(category,...)
GLsizei GLsizei GLchar * source
aWidget window() -> setWindowTitle("New Window Title")
[2]
QQuickView * view
[0]