Changeset 561 for trunk/src/gui/inputmethod/qwininputcontext_win.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/inputmethod/qwininputcontext_win.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 46 46 #include "qwidget.h" 47 47 #include "qapplication.h" 48 #include "qlibrary.h"49 48 #include "qevent.h" 50 49 #include "qtextformat.h" 50 #include "qtextboundaryfinder.h" 51 51 52 52 //#define Q_IME_DEBUG 53 54 /* Active Input method support on Win95/98/NT */55 #include <objbase.h>56 #include <initguid.h>57 53 58 54 #ifdef Q_IME_DEBUG … … 60 56 #endif 61 57 62 #if defined(Q_ OS_WINCE)58 #if defined(Q_WS_WINCE) 63 59 extern void qt_wince_show_SIP(bool show); // defined in qguifunctions_wince.cpp 64 60 #endif … … 219 215 : QInputContext(parent), recursionGuard(false) 220 216 { 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 241 218 QSysInfo::WinVersion ver = QSysInfo::windowsVersion(); 242 219 if (ver & QSysInfo::WV_NT_based && ver >= QSysInfo::WV_VISTA) { … … 263 240 } 264 241 } 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) 274 247 #ifdef LANG_SYRIAC 275 276 #endif 277 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); 278 251 } 279 252 #else … … 281 254 #endif 282 255 283 WM_MSIME_MOUSE = QT_WA_INLINE(RegisterWindowMessage(L"MSIMEMouseOperation"), RegisterWindowMessageA("MSIMEMouseOperation"));256 WM_MSIME_MOUSE = RegisterWindowMessage(L"MSIMEMouseOperation"); 284 257 } 285 258 … … 338 311 } 339 312 340 static LONG getCompositionString(HIMC himc, DWORD dwIndex, LPVOID lpbuf, DWORD dBufLen , bool *unicode = 0)313 static LONG getCompositionString(HIMC himc, DWORD dwIndex, LPVOID lpbuf, DWORD dBufLen) 341 314 { 342 315 LONG len = 0; 343 if (unicode)344 *unicode = true;345 316 if (aimm) 346 317 aimm->GetCompositionStringW(himc, dwIndex, dBufLen, &len, lpbuf); 347 318 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); 360 320 return len; 361 321 } … … 368 328 static QString getString(HIMC himc, DWORD dwindex, int *selStart = 0, int *selLength = 0) 369 329 { 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)); 382 333 383 334 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); 393 337 *selStart = attrlen+1; 394 338 *selLength = -1; … … 404 348 if (len <= 0) 405 349 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)); 418 352 } 419 353 … … 429 363 if (!aimm || aimm->OnDefWindowProc(hwnd, msg, wParam, lParam, &retval) != S_OK) 430 364 { 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); 436 366 } 437 367 return retval; … … 455 385 hf = f.handle(); 456 386 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 } 472 394 473 395 QRect r = w->inputMethodQuery(Qt::ImMicroFocus).toRect(); … … 540 462 541 463 if (!fw) 542 fw = qApp->focusWidget();464 fw = QApplication::focusWidget(); 543 465 544 466 if (fw) { … … 638 560 return true; 639 561 640 QWidget *fw = qApp->focusWidget();562 QWidget *fw = QApplication::focusWidget(); 641 563 if (fw) { 642 564 Q_ASSERT(fw->testAttribute(Qt::WA_WState_Created)); … … 739 661 if (defaultContext) 740 662 ImmAssociateContext(w->effectiveWinId(), defaultContext); 741 #ifdef Q_ OS_WINCE663 #ifdef Q_WS_WINCE 742 664 if (qApp->autoSipEnabled()) 743 665 qt_wince_show_SIP(true); … … 748 670 if (!defaultContext) 749 671 defaultContext = oldimc; 750 #ifdef Q_ OS_WINCE672 #ifdef Q_WS_WINCE 751 673 if (qApp->autoSipEnabled()) 752 674 qt_wince_show_SIP(false); … … 756 678 757 679 758 void Q InputContextPrivate::updateImeStatus(QWidget *w, bool hasFocus)680 void QWinInputContext::updateImeStatus(QWidget *w, bool hasFocus) 759 681 { 760 682 if (!w) 761 683 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)); 763 690 bool hasIme = e && hasFocus; 764 691 #ifdef Q_IME_DEBUG … … 825 752 void QWinInputContext::setFocusWidget(QWidget *w) 826 753 { 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 } 827 763 QInputContext::setFocusWidget(w); 828 764 update(); … … 861 797 } 862 798 799 int 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 863 847 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.