void UIWidget::mouse_down_func() { if (disabled) return; // call this function on the children first for (auto &child : ElementID::recast_collection<UIWidget>(get_children())) child->mouse_down_func(); // now do the execution of the function if (mouse_over) { mouse_down_on_over = true; on_mouse_down(); focused = true; on_focus(); } else { if (focused) { focused = false; on_blur(); } } }
bool TopWindow::on_event(const SDL_Event &event) { switch (event.type) { Window *w; case SDL_VIDEOEXPOSE: invalidated_lock.Lock(); invalidated = false; invalidated_lock.Unlock(); expose(); return true; case SDL_KEYDOWN: w = get_focused_window(); if (w == NULL) w = this; return w->on_key_down(event.key.keysym.sym); case SDL_KEYUP: w = get_focused_window(); if (w == NULL) w = this; return w->on_key_up(event.key.keysym.sym); case SDL_MOUSEMOTION: // XXX keys return on_mouse_move(event.motion.x, event.motion.y, 0); case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_WHEELUP) return on_mouse_wheel(event.button.x, event.button.y, 1); else if (event.button.button == SDL_BUTTON_WHEELDOWN) return on_mouse_wheel(event.button.x, event.button.y, -1); static PeriodClock double_click; return double_click.check_always_update(300) ? on_mouse_down(event.button.x, event.button.y) : on_mouse_double(event.button.x, event.button.y); case SDL_MOUSEBUTTONUP: if (event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) /* the wheel has already been handled in SDL_MOUSEBUTTONDOWN */ return false; return on_mouse_up(event.button.x, event.button.y); case SDL_QUIT: return on_close(); } return false; }
bool TopWindow::on_event(const SDL_Event &event) { switch (event.type) { case SDL_MOUSEMOTION: // XXX keys return on_mouse_move(event.motion.x, event.motion.y, 0); case SDL_MOUSEBUTTONDOWN: return on_mouse_down(event.button.x, event.button.y); case SDL_MOUSEBUTTONUP: return on_mouse_up(event.button.x, event.button.y); } return false; }
LRESULT Window::on_message(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (IsEmbedded() && !IsAltair()) { /* some older iPaqs such as the H3900 send only WM_KEYUP for VK_APP*, but never VK_KEYDOWN; the hx4700 has an additional set of undocumented key codes (0xca..0xcd) for the APP keys, but sends WM_KEYUP/VK_APP* additionally; the following rules hopefully catch all of these obscurities */ if (message == WM_KEYUP && wParam >= 0x80) /* convert to WM_KEYDOWN to make all handlers catch it */ message = WM_KEYDOWN; else if (message == WM_KEYDOWN && wParam >= 0x80) /* ignore the real WM_KEYDOWN, just in case it really happens */ return 0; } switch (message) { case WM_CREATE: on_create(); return 0; case WM_DESTROY: on_destroy(); return 0; case WM_CLOSE: if (on_close()) /* true returned: message was handled */ return 0; break; case WM_SIZE: on_resize(LOWORD(lParam), HIWORD(lParam)); return 0; case WM_MOUSEMOVE: if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam)) return 0; break; case WM_LBUTTONDOWN: if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONUP: if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONDBLCLK: if (!double_clicks) /* instead of disabling CS_DBLCLKS (which would affect all instances of a window class), we just translate WM_LBUTTONDBLCLK to WM_LBUTTONDOWN here; this even works for built-in window class such as BUTTON */ return on_message(_hWnd, WM_LBUTTONDOWN, wParam, lParam); if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #ifdef WM_MOUSEWHEEL case WM_MOUSEWHEEL: if (on_mouse_wheel(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), GET_WHEEL_DELTA_WPARAM(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #endif case WM_KEYDOWN: if (on_key_down(::TranscodeKey(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_KEYUP: if (on_key_up(::TranscodeKey(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_COMMAND: if (on_command(LOWORD(wParam), HIWORD(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_CANCELMODE: if (on_cancel_mode()) return 0; break; case WM_SETFOCUS: on_setfocus(); return 0; case WM_KILLFOCUS: on_killfocus(); return 0; case WM_TIMER: if (on_timer(*(WindowTimer *)wParam)) return 0; break; case WM_PAINT: if (custom_painting) { PaintCanvas canvas(*this); on_paint(canvas, canvas.get_dirty()); return 0; } break; case WM_GETDLGCODE: if (on_key_check(wParam)) return DLGC_WANTMESSAGE; break; } if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER)) return 0; return on_unhandled_message(_hWnd, message, wParam, lParam); }
LRESULT Window::on_message(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: return on_create() ? 0 : -1; break; case WM_DESTROY: if (on_destroy()) return 0; break; case WM_CLOSE: if (on_close()) /* true returned: message was handled */ return 0; break; case WM_SIZE: if (on_resize(LOWORD(lParam), HIWORD(lParam))) return 0; break; case WM_MOUSEMOVE: if (on_mouse_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam)) return 0; break; case WM_LBUTTONDOWN: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_down(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONUP: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_up(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_LBUTTONDBLCLK: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_double(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #ifdef WM_MOUSEWHEEL case WM_MOUSEWHEEL: XCSoarInterface::InterfaceTimeoutReset(); if (on_mouse_wheel(GET_WHEEL_DELTA_WPARAM(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; #endif case WM_KEYDOWN: XCSoarInterface::InterfaceTimeoutReset(); if (on_key_down(wParam)) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_KEYUP: XCSoarInterface::InterfaceTimeoutReset(); if (on_key_up(wParam)) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_COMMAND: XCSoarInterface::InterfaceTimeoutReset(); if (on_command(LOWORD(wParam), HIWORD(wParam))) { /* true returned: message was handled */ ResetDisplayTimeOut(); return 0; } break; case WM_SETFOCUS: if (on_setfocus()) return 0; break; case WM_KILLFOCUS: if (on_killfocus()) return 0; break; case WM_TIMER: if (on_timer(wParam)) return 0; break; } if (message >= WM_USER && message <= 0x7FFF && on_user(message - WM_USER)) return 0; return on_unhandled_message(_hWnd, message, wParam, lParam); }