File: minputcontextconnection.h

package info (click to toggle)
maliit-framework 2.3.0-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,488 kB
  • sloc: cpp: 13,098; ansic: 2,506; xml: 299; sh: 34; makefile: 23; sed: 4
file content (399 lines) | stat: -rw-r--r-- 15,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/* * This file is part of Maliit framework *
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * and appearing in the file LICENSE.LGPL included in the packaging
 * of this file.
 */

#ifndef MINPUTCONTEXTCONNECTION_H
#define MINPUTCONTEXTCONNECTION_H

#include <maliit/namespace.h>

#include <QtCore>
#include <QWindow>

QT_BEGIN_NAMESPACE
class QKeyEvent;
QT_END_NAMESPACE

class MInputContextConnectionPrivate;
class MAbstractInputMethod;
class MAttributeExtensionId;
class MImPluginSettingsInfo;

/*! \internal
 * \ingroup maliitserver
 * \brief Base class of the input method communication implementation between
 * the input context and the input method server.
 */
class MInputContextConnection: public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY(MInputContextConnection)

public:
    explicit MInputContextConnection(QObject *parent = 0);
    virtual ~MInputContextConnection();

    /*!
     * \brief Returns focus state if output parameter \a valid is \c true.
     *
     * By focus state it is meant to be focus state of an input widget
     * on application side. If returned value is valid and is \c true then this
     * means that input widget is focused. Otherwise, if returned value is
     * \c false then no input widget is focused.
     *
     * \param valid An output parameter stating whether return value is valid.
     */
    virtual bool focusState(bool &valid);

    /*!
     * \brief returns content type for focused widget if output parameter valid is true,
     * value matches enum M::TextContentType
     */
    virtual int contentType(bool &valid);

    /*!
     * \brief returns input method correction hint if output parameter valid is true.
     */
    virtual bool correctionEnabled(bool &valid);

    /*!
     * \brief returns input methoContextd word prediction hint if output parameter valid is true.
     */
    virtual bool predictionEnabled(bool &valid);

    /*!
     * \brief returns input method auto-capitalization hint if output parameter valid is true.
     */
    virtual bool autoCapitalizationEnabled(bool &valid);

    /*!
     * \brief get surrounding text and cursor position information
     */
    virtual bool surroundingText(QString &text, int &cursorPosition);

    /*!
     * \brief returns true if there is selecting text
     */
    virtual bool hasSelection(bool &valid);

    /*!
     * \brief get input method mode
     */
    virtual int inputMethodMode(bool &valid);

    /*!
     * \brief get preedit rectangle
     */
    virtual QRect preeditRectangle(bool &valid);

    /*!
     * \brief get cursor rectangle
     */
    virtual QRect cursorRectangle(bool &valid);

    /*!
     * \brief true if text input is being made hidden, e.g. with password fields
     */
    virtual bool hiddenText(bool &valid);

    /*!
     * \brief Updates pre-edit string in the application widget
     *
     * Implement this method to update the pre-edit string
     * \param string    The new pre-edit string
     * \param preeditFormats Selects visual stylings for each part of preedit
     * \param replacementStart The position at which characters are to be replaced relative
     *  from the start of the preedit string.
     * \param replacementLength The number of characters to be replaced in the preedit string.
     * \param cursorPos The cursor position inside preedit
     */
    virtual void sendPreeditString(const QString &string,
                                   const QList<Maliit::PreeditTextFormat> &preeditFormats,
                                   int replacementStart = 0,
                                   int replacementLength = 0,
                                   int cursorPos = -1);

    /*!
     * \brief Updates commit string in the application widget, and set cursor position.
     *
     * Implement this method to update the commit string
     * \param string    The string to be committed
     * \param replaceStart The position at which characters are to be replaced relative
     *  from the start of the preedit string.
     * \param replaceLength The number of characters to be replaced in the preedit string.
     * \param cursorPos The cursor position to be set. the cursorPos is the position relative
     *  to commit string start. Negative values are used as commit string end position
     */
    virtual void sendCommitString(const QString &string, int replaceStart = 0,
                                  int replaceLength = 0, int cursorPos = -1);

    /*!
     * \brief Sends key event to the application
     *
     * This method is used to deliver the key event to active widget.
     * A \a MInputMethodState::keyPress or \a MInputMethodState::keyRelease
     * event is also emitted. Depending on the value of \a requestType
     * parameter, a Qt::KeyEvent and/or a signal is emitted.
     * \param keyEvent The event to send
     * \param requestType The type of the request: event, signal, or both.
     */
    virtual void sendKeyEvent(const QKeyEvent &keyEvent,
                              Maliit::EventRequestType requestType
                              = Maliit::EventRequestBoth);

    /*!
     * \brief notifies about hiding initiated by the input method server side
     */
    virtual void notifyImInitiatedHiding();

    /*!
     * \brief calls actions like "copy" or "paste" on the focused text entry.
     *
     * \param action The action to call
     * \param sequence The fall-back key sequence when action is not available
     */
    virtual void invokeAction(const QString &action,
                              const QKeySequence &sequence);

    /*!
     * \brief Set if the input method wants to process all raw key events
     * from hardware keyboard (via \a processKeyEvent calls).
     */
    virtual void setRedirectKeys(bool enabled);

    /*!
     * \brief Set detectable autorepeat for X on/off
     *
     * Detectable autorepeat means that instead of press, release, press, release, press,
     * release... sequence of key events you get press, press, press, release key events
     * when a key is repeated.  The setting is X client specific.  This is intended to be
     * used when key event redirection is enabled with \a setRedirectKeys.
     */
    virtual void setDetectableAutoRepeat(bool enabled);

    /*!
     * \brief set global correction option enable/disable
     */
    virtual void setGlobalCorrectionEnabled(bool);

    /*!
     *\brief Sets selection text start from \a start with \a length in the application widget.
     */
    virtual void setSelection(int start, int length);

    /*!
     * \brief returns the position of the selection anchor.
     *
     * This may be less or greater than cursor position, depending on which side of selection
     * the cursor is. If there is no selection, it returns the same as cursor position.
     */
    virtual int anchorPosition(bool &valid);

    /*!
     * \brief returns the current cursor position within the preedit region
     */
    virtual int preeditClickPos(bool &valid) const;

    /*!
     * \brief returns the selecting text
     */
    virtual QString selection(bool &valid);

    /*!
     * \brief Sets current language of active input method.
     * \param language ICU format locale ID string
     */
    virtual void setLanguage(const QString &language);

    virtual void sendActivationLostEvent();

    QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const;

public: // Inbound communication handlers
    //! ipc method provided to application, makes the application the active one
    void activateContext(unsigned int connectionId);

    //! ipc method provided to the application, shows input method
    void showInputMethod(unsigned int clientId);

    //! ipc method provided to the application, hides input method
    void hideInputMethod(unsigned int clientId);

    //! ipc method provided to the application, signals mouse click on preedit
    void mouseClickedOnPreedit(unsigned int clientId,
                               const QPoint &pos, const QRect &preeditRect);

    //! ipc method provided to the application, sets preedit
    void setPreedit(unsigned int clientId, const QString &text, int cursorPos);

    void updateWidgetInformation(unsigned int clientId,
                                 const QMap<QString, QVariant> &stateInformation,
                                 bool focusChanged);

    //! ipc method provided to the application, resets the input method
    void reset(unsigned int clientId);

    /*!
     * \brief Target application is changing orientation
     */
    void receivedAppOrientationAboutToChange(unsigned int clientId, int angle);

    /*!
     * \brief Target application changed orientation (already finished)
     */
    void receivedAppOrientationChanged(unsigned int clientId, int angle);

    /*! \brief Set copy/paste state for appropriate UI elements in the input method server
     *  \param copyAvailable bool TRUE if text is selected
     *  \param pasteAvailable bool TRUE if clipboard content is not empty
     */
    void setCopyPasteState(unsigned int clientId,
                           bool copyAvailable, bool pasteAvailable);

    /*!
     * \brief Process a key event redirected from hardware keyboard to input method plugin(s).
     *
     * This is called only if one has enabled redirection by calling \a setRedirectKeys.
     */
    void processKeyEvent(unsigned int clientId, QEvent::Type keyType, Qt::Key keyCode,
                         Qt::KeyboardModifiers modifiers, const QString &text, bool autoRepeat,
                         int count, quint32 nativeScanCode, quint32 nativeModifiers, unsigned long time);

    /*!
     * \brief Register an input method attribute extension which is defined in \a fileName with the
     * unique identifier \a id.
     *
     *  The \a id should be unique, and the \a fileName is the absolute file name of the
     *  attribute extension.
     */
    void registerAttributeExtension(unsigned int clientId, int id, const QString &fileName);

    /*!
     * \brief Unregister an input method attribute extension which unique identifier is \a id.
     */
    void unregisterAttributeExtension(unsigned int clientId, int id);

    /*!
     * \brief Sets the \a attribute for the \a target in the extended attribute which has unique \a id to \a value.
     */
    void setExtendedAttribute(unsigned int clientId, int id, const QString &target,
                              const QString &targetItem, const QString &attribute, const QVariant &value);

    /*!
     * \brief Requests information about plugin/server settings.
     */
    void loadPluginSettings(int connectionId, const QString &descriptionLanguage);

public Q_SLOTS:
    //! Update \a region covered by virtual keyboard
    virtual void updateInputMethodArea(const QRegion &region);

    /*!
     * \brief Informs current application that input method servers has changed the \a attribute of the \a targetItem
     * in the attribute extension \a target which has unique \a id to \a value.
     */
    virtual void notifyExtendedAttributeChanged(int id,
                                                const QString &target,
                                                const QString &targetItem,
                                                const QString &attribute,
                                                const QVariant &value);

    /*!
     * \brief Informs a list of clients that input method servers has changed the \a attribute of the \a targetItem
     * in the attribute extension \a target which has unique \a id to \a value.
     */
    virtual void notifyExtendedAttributeChanged(const QList<int> &clientIds,
                                                int id,
                                                const QString &target,
                                                const QString &targetItem,
                                                const QString &attribute,
                                                const QVariant &value);

    /*!
     * \brief Sends the list of plugin/server settings to the specified client.
     */
    virtual void pluginSettingsLoaded(int clientId, const QList<MImPluginSettingsInfo> &info);

Q_SIGNALS:
    /* Emitted first */
    void contentOrientationAboutToChange(int angle);
    void contentOrientationChanged(int angle);
    /* Emitted later */
    void contentOrientationAboutToChangeCompleted(int angle);
    void contentOrientationChangeCompleted(int angle);

    void focusChanged(WId id);

    //! Emitted when input method request to be shown.
    void showInputMethodRequest();

    //! Emitted when input method request to be hidden.
    void hideInputMethodRequest();

    void resetInputMethodRequest();

    void copyPasteStateChanged(bool copyAvailable, bool pasteAvailable);
    void widgetStateChanged(unsigned int clientId, const QMap<QString, QVariant> &newState,
                            const QMap<QString, QVariant> &oldState, bool focusChanged);

    void attributeExtensionRegistered(unsigned int connectionId, int id, const QString &attributeExtension);
    void attributeExtensionUnregistered(unsigned int connectionId, int id);
    void extendedAttributeChanged(unsigned int connectionId, int id, const QString &target,
                              const QString &targetName,const QString &attribute, const QVariant &value);

    void pluginSettingsRequested(int connectionId, const QString &descriptionLanguage);

    void clientActivated(unsigned int connectionId);
    void clientDisconnected(unsigned int connectionId);
    void activeClientDisconnected();

    void preeditChanged(const QString &text, int cursorPos);
    void mouseClickedOnPreedit(const QPoint &pos, const QRect &preeditRect);

    void receivedKeyEvent(QEvent::Type keyType, Qt::Key keyCode,
                         Qt::KeyboardModifiers modifiers, const QString &text, bool autoRepeat,
                         int count, quint32 nativeScanCode, quint32 nativeModifiers, unsigned long time);

protected:
    unsigned int activeConnection; // 0 means no active connection

    bool detectableAutoRepeat();
    bool globalCorrectionEnabled();
    bool redirectKeysEnabled();

    void handleActivation(unsigned int connectionId);

    QVariantMap widgetState() const;

public:
    void handleDisconnection(unsigned int connectionId);

private:
    /*!
     * \brief get the X window id of the active app window. Warning: Undefined on non-X11 platforms
     */
    WId winId();

private:
    MInputContextConnectionPrivate *d;
    int lastOrientation;

    /* FIXME: rename with m prefix, and provide protected accessors for derived classes */
    QMap<QString, QVariant> mWidgetState;
    bool mGlobalCorrectionEnabled;
    bool mRedirectionEnabled;
    bool mDetectableAutoRepeat;
    QString preedit;
};
//! \internal_end

#endif