2008年3月31日星期一

解决Qt4.4 beta输入法侯选框的问题

昨天在QInputContext.cpp找了半天,尝试修改代码也没有解决侯选框出不来的问题。在说到解决方法之前,首先感谢souce insight,没有这么好的编辑器,我都不知道要怎么去看这些大型工程的源代码。

查看了一下IME编辑相关的资料,顺代的在qt4.4的源码中搜索与WM_IME开头的消息除理代码,不多,也就几条,最后在qapplication_win.cpp让我给发现了,嘿嘿,就是在处理WM_IME_NOTIFY消息的代码有问题,代码如下:

case WM_IME_NOTIFY:
            // special handling for ime, only for widgets in a popup
            if (wParam  == IMN_OPENCANDIDATE) {
                imeParentWnd = hwnd;
                if (QApplication::activePopupWidget()) {
                    // temporarily disable the mouse grab to allow mouse input in
                    // the ime candidate window. The actual handle is untouched
                    if (autoCaptureWnd)
                        ReleaseCapture();
                }
            } else if (wParam  == IMN_CLOSECANDIDATE) {
                imeParentWnd = 0;
                if (QApplication::activePopupWidget()) {
                    // undo the action above, when candidate window is closed
                    if (autoCaptureWnd)
                        SetCapture(autoCaptureWnd);
                }
            }

result = false;//added by zhongfanglin@gmail.com
            break;
        default:
            result = false;                        // event was not processed
            break;
        }
    }

    if (evt_type != QEvent::None) {                // simple event
        QEvent e(evt_type);
        result = qt_sendSpontaneousEvent(widget, &e);
    }

//add by zhongfanglin@anzsoft.com
    if(AnzSkin->winEventFilter(&msg,&res))
        RETURN(res);
    //end add

    if (result)
        RETURN(false);

do_default:
    RETURN(QWinInputContext::DefWindowProc(hwnd,message,wParam,lParam))
}

 

 

 

作用没太看明白,但是从代码可以看出,WM_IME_NOTIFY被拦截了,并没有交给默认的消息处理函数,所以在case WM_IME_NOTIFY:节添加了一句代码,result = false,重新编译QtGui模块,运行程序,期待已久的输入法侯选框终于出现了。

不过没明白的是,我用的五笔加加在修改这个代码之前是能出侯选框的,看来是五笔加加不是用的IME体系的侯选框处理机制。

顺便发个牢骚,现在好用的拼音输入法真多,又漂亮又好用,为吓咪就没人做好看漂亮又好用的五笔呢。。。。。。只怪用不来拼音输入法,只好老实的用偶的五笔了。

没有评论: