Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/inputmethod/qwininputcontext_win.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4646#include "qwidget.h"
    4747#include "qapplication.h"
    48 #include "qlibrary.h"
    4948#include "qevent.h"
    5049#include "qtextformat.h"
     50#include "qtextboundaryfinder.h"
    5151
    5252//#define Q_IME_DEBUG
    53 
    54 /* Active Input method support on Win95/98/NT */
    55 #include <objbase.h>
    56 #include <initguid.h>
    5753
    5854#ifdef Q_IME_DEBUG
     
    6056#endif
    6157
    62 #if defined(Q_OS_WINCE)
     58#if defined(Q_WS_WINCE)
    6359extern void qt_wince_show_SIP(bool show);   // defined in qguifunctions_wince.cpp
    6460#endif
     
    219215    : QInputContext(parent), recursionGuard(false)
    220216{
    221     if (QSysInfo::WindowsVersion < QSysInfo::WV_2000) {
    222         // try to get the Active IMM COM object on Win95/98/NT, where english versions don't
    223         // support the regular Windows input methods.
    224         if (CoCreateInstance(CLSID_CActiveIMM, NULL, CLSCTX_INPROC_SERVER,
    225             IID_IActiveIMMApp, (LPVOID *)&aimm) != S_OK) {
    226             aimm = 0;
    227         }
    228         if (aimm && (aimm->QueryInterface(IID_IActiveIMMMessagePumpOwner, (LPVOID *)&aimmpump) != S_OK ||
    229                         aimm->Activate(true) != S_OK)) {
    230             aimm->Release();
    231             aimm = 0;
    232             if (aimmpump)
    233                 aimmpump->Release();
    234             aimmpump = 0;
    235         }
    236         if (aimmpump)
    237             aimmpump->Start();
    238     }
    239 
    240 #ifndef Q_OS_WINCE
     217#ifndef Q_WS_WINCE
    241218    QSysInfo::WinVersion ver = QSysInfo::windowsVersion();
    242219    if (ver & QSysInfo::WV_NT_based  && ver >= QSysInfo::WV_VISTA) {
     
    263240        }
    264241    } else {
    265             // figure out whether a RTL language is installed
    266         typedef BOOL(WINAPI *PtrIsValidLanguageGroup)(DWORD,DWORD);
    267         PtrIsValidLanguageGroup isValidLanguageGroup = (PtrIsValidLanguageGroup)QLibrary::resolve(QLatin1String("kernel32"), "IsValidLanguageGroup");
    268         if (isValidLanguageGroup) {
    269                 qt_use_rtl_extensions = isValidLanguageGroup(LGRPID_ARABIC, LGRPID_INSTALLED)
    270                                          || isValidLanguageGroup(LGRPID_HEBREW, LGRPID_INSTALLED);
    271         }
    272         qt_use_rtl_extensions |= IsValidLocale(MAKELCID(MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
    273                                   || IsValidLocale(MAKELCID(MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
     242        // figure out whether a RTL language is installed
     243        qt_use_rtl_extensions = IsValidLanguageGroup(LGRPID_ARABIC, LGRPID_INSTALLED)
     244                                || IsValidLanguageGroup(LGRPID_HEBREW, LGRPID_INSTALLED)
     245                                || IsValidLocale(MAKELCID(MAKELANGID(LANG_ARABIC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
     246                                || IsValidLocale(MAKELCID(MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
    274247#ifdef LANG_SYRIAC
    275                               || IsValidLocale(MAKELCID(MAKELANGID(LANG_SYRIAC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
    276 #endif
    277                                   || IsValidLocale(MAKELCID(MAKELANGID(LANG_FARSI, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED);
     248                                || IsValidLocale(MAKELCID(MAKELANGID(LANG_SYRIAC, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED)
     249#endif
     250                                || IsValidLocale(MAKELCID(MAKELANGID(LANG_FARSI, SUBLANG_DEFAULT), SORT_DEFAULT), LCID_INSTALLED);
    278251    }
    279252#else
     
    281254#endif
    282255
    283     WM_MSIME_MOUSE = QT_WA_INLINE(RegisterWindowMessage(L"MSIMEMouseOperation"), RegisterWindowMessageA("MSIMEMouseOperation"));
     256    WM_MSIME_MOUSE = RegisterWindowMessage(L"MSIMEMouseOperation");
    284257}
    285258
     
    338311}
    339312
    340 static LONG getCompositionString(HIMC himc, DWORD dwIndex, LPVOID lpbuf, DWORD dBufLen, bool *unicode = 0)
     313static LONG getCompositionString(HIMC himc, DWORD dwIndex, LPVOID lpbuf, DWORD dBufLen)
    341314{
    342315    LONG len = 0;
    343     if (unicode)
    344         *unicode = true;
    345316    if (aimm)
    346317        aimm->GetCompositionStringW(himc, dwIndex, dBufLen, &len, lpbuf);
    347318    else
    348     {
    349         if(QSysInfo::WindowsVersion != QSysInfo::WV_95) {
    350             len = ImmGetCompositionStringW(himc, dwIndex, lpbuf, dBufLen);
    351         }
    352 #if !defined(Q_OS_WINCE)
    353         else {
    354             len = ImmGetCompositionStringA(himc, dwIndex, lpbuf, dBufLen);
    355             if (unicode)
    356                 *unicode = false;
    357         }
    358 #endif
    359     }
     319        len = ImmGetCompositionString(himc, dwIndex, lpbuf, dBufLen);
    360320    return len;
    361321}
     
    368328static QString getString(HIMC himc, DWORD dwindex, int *selStart = 0, int *selLength = 0)
    369329{
    370     static char *buffer = 0;
    371     static int buflen = 0;
    372 
    373     int len = getCompositionString(himc, dwindex, 0, 0) + 1;
    374     if (!buffer || len > buflen) {
    375         delete [] buffer;
    376         buflen = qMin(len, 256);
    377         buffer = new char[buflen];
    378     }
    379 
    380     bool unicode = true;
    381     len = getCompositionString(himc, dwindex, buffer, buflen, &unicode);
     330    const int bufferSize = 256;
     331    wchar_t buffer[bufferSize];
     332    int len = getCompositionString(himc, dwindex, buffer, bufferSize * sizeof(wchar_t));
    382333
    383334    if (selStart) {
    384         static char *attrbuffer = 0;
    385         static int attrbuflen = 0;
    386         int attrlen = getCompositionString(himc, dwindex, 0, 0) + 1;
    387         if (!attrbuffer || attrlen> attrbuflen) {
    388             delete [] attrbuffer;
    389             attrbuflen = qMin(attrlen, 256);
    390             attrbuffer = new char[attrbuflen];
    391         }
    392         attrlen = getCompositionString(himc, GCS_COMPATTR, attrbuffer, attrbuflen);
     335        char attrbuffer[bufferSize];
     336        int attrlen = getCompositionString(himc, GCS_COMPATTR, attrbuffer, bufferSize);
    393337        *selStart = attrlen+1;
    394338        *selLength = -1;
     
    404348    if (len <= 0)
    405349        return QString();
    406     if (unicode) {
    407         return QString((QChar *)buffer, len/sizeof(QChar));
    408     }
    409     else {
    410         buffer[len] = 0;
    411         WCHAR *wc = new WCHAR[len+1];
    412         int l = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
    413             buffer, len, wc, len+1);
    414         QString res = QString((QChar *)wc, l);
    415         delete [] wc;
    416         return res;
    417     }
     350
     351    return QString((QChar*)buffer, len / sizeof(QChar));
    418352}
    419353
     
    429363    if (!aimm || aimm->OnDefWindowProc(hwnd, msg, wParam, lParam, &retval) != S_OK)
    430364    {
    431         QT_WA({
    432             retval = ::DefWindowProc(hwnd, msg, wParam, lParam);
    433         } , {
    434             retval = ::DefWindowProcA(hwnd,msg, wParam, lParam);
    435         });
     365        retval = ::DefWindowProc(hwnd, msg, wParam, lParam);
    436366    }
    437367    return retval;
     
    455385    hf = f.handle();
    456386
    457     QT_WA({
    458         LOGFONT lf;
    459         if (GetObject(hf, sizeof(lf), &lf))
    460             if (aimm)
    461                 aimm->SetCompositionFontW(imc, &lf);
    462             else
    463                 ImmSetCompositionFont(imc, &lf);
    464     } , {
    465         LOGFONTA lf;
    466         if (GetObjectA(hf, sizeof(lf), &lf))
    467             if (aimm)
    468                 aimm->SetCompositionFontA(imc, &lf);
    469             else
    470                 ImmSetCompositionFontA(imc, &lf);
    471     });
     387    LOGFONT lf;
     388    if (GetObject(hf, sizeof(lf), &lf)) {
     389        if (aimm)
     390            aimm->SetCompositionFontW(imc, &lf);
     391        else
     392            ImmSetCompositionFont(imc, &lf);
     393    }
    472394
    473395    QRect r = w->inputMethodQuery(Qt::ImMicroFocus).toRect();
     
    540462
    541463    if (!fw)
    542         fw = qApp->focusWidget();
     464        fw = QApplication::focusWidget();
    543465
    544466    if (fw) {
     
    638560        return true;
    639561
    640     QWidget *fw = qApp->focusWidget();
     562    QWidget *fw = QApplication::focusWidget();
    641563    if (fw) {
    642564        Q_ASSERT(fw->testAttribute(Qt::WA_WState_Created));
     
    739661        if (defaultContext)
    740662            ImmAssociateContext(w->effectiveWinId(), defaultContext);
    741 #ifdef Q_OS_WINCE
     663#ifdef Q_WS_WINCE
    742664        if (qApp->autoSipEnabled())
    743665            qt_wince_show_SIP(true);
     
    748670        if (!defaultContext)
    749671            defaultContext = oldimc;
    750 #ifdef Q_OS_WINCE
     672#ifdef Q_WS_WINCE
    751673        if (qApp->autoSipEnabled())
    752674            qt_wince_show_SIP(false);
     
    756678
    757679
    758 void QInputContextPrivate::updateImeStatus(QWidget *w, bool hasFocus)
     680void QWinInputContext::updateImeStatus(QWidget *w, bool hasFocus)
    759681{
    760682    if (!w)
    761683        return;
    762     bool e = w->testAttribute(Qt::WA_InputMethodEnabled) && w->isEnabled();
     684    // It's always the proxy that carries the hints.
     685    QWidget *focusProxyWidget = w->focusProxy();
     686    if (!focusProxyWidget)
     687        focusProxyWidget = w;
     688    bool e = w->testAttribute(Qt::WA_InputMethodEnabled) && w->isEnabled()
     689            && !(focusProxyWidget->inputMethodHints() & (Qt::ImhExclusiveInputMask | Qt::ImhHiddenText));
    763690    bool hasIme = e && hasFocus;
    764691#ifdef Q_IME_DEBUG
     
    825752void QWinInputContext::setFocusWidget(QWidget *w)
    826753{
     754    QWidget *oldFocus = focusWidget();
     755    if (oldFocus == w)
     756        return;
     757    if (w) {
     758        QWinInputContext::updateImeStatus(w, true);
     759    } else {
     760        if (oldFocus)
     761            QWinInputContext::updateImeStatus(oldFocus , false);
     762    }
    827763    QInputContext::setFocusWidget(w);
    828764    update();
     
    861797}
    862798
     799int QWinInputContext::reconvertString(RECONVERTSTRING *reconv)
     800{
     801    QWidget *w = focusWidget();
     802    if(!w)
     803        return -1;
     804
     805    Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
     806    QString surroundingText = qvariant_cast<QString>(w->inputMethodQuery(Qt::ImSurroundingText));
     807    int memSize = sizeof(RECONVERTSTRING)+(surroundingText.length()+1)*sizeof(ushort);
     808    // If memory is not allocated, return the required size.
     809    if (!reconv) {
     810        if (surroundingText.isEmpty())
     811            return -1;
     812        else
     813            return memSize;
     814    }
     815    int pos = qvariant_cast<int>(w->inputMethodQuery(Qt::ImCursorPosition));
     816    // find the word in the surrounding text.
     817    QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText);
     818    bounds.setPosition(pos);
     819    if (bounds.isAtBoundary()) {
     820        if (QTextBoundaryFinder::EndWord == bounds.boundaryReasons())
     821            bounds.toPreviousBoundary();
     822    } else {
     823        bounds.toPreviousBoundary();
     824    }
     825    int startPos = bounds.position();
     826    bounds.toNextBoundary();
     827    int endPos = bounds.position();
     828    // select the text, this will be overwritten by following ime events.
     829    QList<QInputMethodEvent::Attribute> attrs;
     830    attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, startPos, endPos-startPos, QVariant());
     831    QInputMethodEvent e(QString(), attrs);
     832    qt_sendSpontaneousEvent(w, &e);
     833
     834    reconv->dwSize = memSize;
     835    reconv->dwVersion = 0;
     836
     837    reconv->dwStrLen = surroundingText.length();
     838    reconv->dwStrOffset = sizeof(RECONVERTSTRING);
     839    reconv->dwCompStrLen = endPos-startPos;
     840    reconv->dwCompStrOffset = startPos*sizeof(ushort);
     841    reconv->dwTargetStrLen = reconv->dwCompStrLen;
     842    reconv->dwTargetStrOffset = reconv->dwCompStrOffset;
     843    memcpy((char*)(reconv+1), surroundingText.utf16(), surroundingText.length()*sizeof(ushort));
     844    return memSize;
     845}
     846
    863847QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.