class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
{
protected:
QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
}
/*!
\internal
*/
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
: QObject(dd, 0), QPaintDevice()
{
Q_D(QWidget);
QT_TRY {
d->init(parent, f);
} QT_CATCH(
) {
QWidgetExceptionCleaner::cleanup(this, d_func());
QT_RETHROW;
}
}
//键盘事件的传递
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CHAR: {
MSG msg1;
bool anyMsg = PeekMessage(&msg1, msg.hwnd, 0, 0, PM_NOREMOVE);
if (anyMsg && msg1.message == WM_DEADCHAR) {
result = true; // consume event since there is a dead char next
break;
}
QWidget *g = QWidget::keyboardGrabber();
if (g && qt_get_tablet_widget() && hwnd == qt_get_tablet_widget()->winId()) {
// if we get an event for the internal tablet widget,
// then don't send it to the keyboard grabber, but
// send it to the widget itself (we don't use it right
// now, just in case).
g = 0;
}
if (g)
widget = (QETWidget*)g;
else if (QApplication::activePopupWidget())
widget = (QETWidget*)QApplication::activePopupWidget()->focusWidget()
? (QETWidget*)QApplication::activePopupWidget()->focusWidget()
: (QETWidget*)QApplication::activePopupWidget();
else if (QApplication::focusWidget()) //这里条件为真
widget = (QETWidget*)QApplication::focusWidget(); //得到具有输入焦点的widget
else if (!widget || widget->internalWinId() == GetFocus()) // We faked the message to go to exactly that widget.
widget = (QETWidget*)widget->window();
if (widget->isEnabled())
result = sm_blockUserInput
? true
: qt_keymapper_private()->translateKeyEvent(widget, msg, g != 0);
break;
}
//..
}
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (qt_is_translatable_mouse_event(message)) {
if (QApplication::activePopupWidget() != 0) { // in popup mode
POINT curPos = msg.pt;
QWidget* w = QApplication::widgetAt(curPos.x, curPos.y);
if (w)
widget = (QETWidget*)w;
}
if (!qt_tabletChokeMouse) {
result = widget->translateMouseEvent(msg);
}
}
}
{
protected:
QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
}
/*!
\internal
*/
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
: QObject(dd, 0), QPaintDevice()
{
Q_D(QWidget);
QT_TRY {
d->init(parent, f);
} QT_CATCH(

QWidgetExceptionCleaner::cleanup(this, d_func());
QT_RETHROW;
}
}
//键盘事件的传递
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CHAR: {
MSG msg1;
bool anyMsg = PeekMessage(&msg1, msg.hwnd, 0, 0, PM_NOREMOVE);
if (anyMsg && msg1.message == WM_DEADCHAR) {
result = true; // consume event since there is a dead char next
break;
}
QWidget *g = QWidget::keyboardGrabber();
if (g && qt_get_tablet_widget() && hwnd == qt_get_tablet_widget()->winId()) {
// if we get an event for the internal tablet widget,
// then don't send it to the keyboard grabber, but
// send it to the widget itself (we don't use it right
// now, just in case).
g = 0;
}
if (g)
widget = (QETWidget*)g;
else if (QApplication::activePopupWidget())
widget = (QETWidget*)QApplication::activePopupWidget()->focusWidget()
? (QETWidget*)QApplication::activePopupWidget()->focusWidget()
: (QETWidget*)QApplication::activePopupWidget();
else if (QApplication::focusWidget()) //这里条件为真
widget = (QETWidget*)QApplication::focusWidget(); //得到具有输入焦点的widget
else if (!widget || widget->internalWinId() == GetFocus()) // We faked the message to go to exactly that widget.
widget = (QETWidget*)widget->window();
if (widget->isEnabled())
result = sm_blockUserInput
? true
: qt_keymapper_private()->translateKeyEvent(widget, msg, g != 0);
break;
}
//..
}
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (qt_is_translatable_mouse_event(message)) {
if (QApplication::activePopupWidget() != 0) { // in popup mode
POINT curPos = msg.pt;
QWidget* w = QApplication::widgetAt(curPos.x, curPos.y);
if (w)
widget = (QETWidget*)w;
}
if (!qt_tabletChokeMouse) {
result = widget->translateMouseEvent(msg);
}
}
}