source: trunk/src/gui/inputmethod/qinputcontextfactory.cpp@ 203

Last change on this file since 203 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/****************************************************************************
43**
44** Implementation of QInputContextFactory class
45**
46** Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
47**
48** This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
49** license. You may use this file under your Qt license. Following
50** description is copied from their original file headers. Contact
51** [email protected] if any conditions of this licensing are
52** not clear to you.
53**
54****************************************************************************/
55
56#include "qinputcontextfactory.h"
57
58#ifndef QT_NO_IM
59
60#include "qcoreapplication.h"
61#include "qinputcontext.h"
62#include "qinputcontextplugin.h"
63
64#ifdef Q_WS_X11
65#include "private/qt_x11_p.h"
66#include "qximinputcontext_p.h"
67#endif
68#ifdef Q_WS_WIN
69#include "qwininputcontext_p.h"
70#endif
71#ifdef Q_WS_MAC
72#include "qmacinputcontext_p.h"
73#endif
74
75#include "private/qfactoryloader_p.h"
76#include "qmutex.h"
77
78QT_BEGIN_NAMESPACE
79
80#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
81Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
82 (QInputContextFactoryInterface_iid, QLatin1String("/inputmethods")))
83#endif
84
85/*!
86 \class QInputContextFactory
87 \brief The QInputContextFactory class creates QInputContext objects.
88
89 \ingroup appearance
90
91 The input context factory creates a QInputContext object for a
92 given key with QInputContextFactory::create().
93
94 The input contexts are either built-in or dynamically loaded from
95 an input context plugin (see QInputContextPlugin).
96
97 keys() returns a list of valid keys. The
98 keys are the names used, for example, to identify and specify
99 input methods for the input method switching mechanism. The names
100 have to be consistent with QInputContext::identifierName(), and
101 may only contain ASCII characters.
102
103 A key can be used to retrieve the associated input context's
104 supported languages using languages(). You
105 can retrieve the input context's description using
106 description() and finally you can get a user
107 friendly internationalized name of the QInputContext object
108 specified by the key using displayName().
109
110 \legalese
111 Copyright (C) 2003-2004 immodule for Qt Project. All rights reserved.
112
113 This file is written to contribute to Nokia Corporation and/or its subsidiary(-ies) under their own
114 license. You may use this file under your Qt license. Following
115 description is copied from their original file headers. Contact
116 [email protected] if any conditions of this licensing are
117 not clear to you.
118 \endlegalese
119
120 \sa QInputContext, QInputContextPlugin
121*/
122
123/*!
124 Creates and returns a QInputContext object for the input context
125 specified by \a key with the given \a parent. Keys are case
126 sensitive.
127
128 \sa keys()
129*/
130QInputContext *QInputContextFactory::create( const QString& key, QObject *parent )
131{
132 QInputContext *result = 0;
133#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
134 if (key == QLatin1String("xim")) {
135 result = new QXIMInputContext;
136 }
137#endif
138#if defined(Q_WS_WIN)
139 if (key == QLatin1String("win")) {
140 result = new QWinInputContext;
141 }
142#endif
143#if defined(Q_WS_MAC)
144 if (key == QLatin1String("mac")) {
145 result = new QMacInputContext;
146 }
147#endif
148#if defined(QT_NO_LIBRARY) || defined(QT_NO_SETTINGS)
149 Q_UNUSED(key);
150#else
151 if (QInputContextFactoryInterface *factory =
152 qobject_cast<QInputContextFactoryInterface*>(loader()->instance(key))) {
153 result = factory->create(key);
154 }
155#endif
156 if (result)
157 result->setParent(parent);
158 return result;
159}
160
161
162/*!
163 Returns the list of keys this factory can create input contexts
164 for.
165
166 The keys are the names used, for example, to identify and specify
167 input methods for the input method switching mechanism. The names
168 have to be consistent with QInputContext::identifierName(), and
169 may only contain ASCII characters.
170
171 \sa create(), displayName(), QInputContext::identifierName()
172*/
173QStringList QInputContextFactory::keys()
174{
175 QStringList result;
176#if defined(Q_WS_X11) && !defined(QT_NO_XIM)
177 result << QLatin1String("xim");
178#endif
179#if defined(Q_WS_WIN) && !defined(QT_NO_XIM)
180 result << QLatin1String("win");
181#endif
182#if defined(Q_WS_MAC)
183 result << QLatin1String("mac");
184#endif
185#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
186 result += loader()->keys();
187#endif // QT_NO_LIBRARY
188 return result;
189}
190