LRESULT APIENTRY DD_WindowProc(HWND hWnd, UINT msg, UINT wParam, LONG lParam) { GF_Event evt; DDContext *ctx; GF_VideoOutput *vout = (GF_VideoOutput *) GetWindowLong(hWnd, GWL_USERDATA); if (!vout) return DefWindowProc (hWnd, msg, wParam, lParam); ctx = (DDContext *)vout->opaque; switch (msg) { case WM_SIZE: /*always notify GPAC since we're not sure the owner of the window is listening to these events*/ evt.type = GF_EVENT_SIZE; evt.size.width = LOWORD(lParam); evt.size.height = HIWORD(lParam); vout->on_event(vout->evt_cbk_hdl, &evt); break; case WM_CLOSE: if (hWnd==ctx->os_hwnd) { evt.type = GF_EVENT_QUIT; vout->on_event(vout->evt_cbk_hdl, &evt); } return 1; case WM_DESTROY: if (ctx->owns_hwnd || (hWnd==ctx->fs_hwnd)) { PostQuitMessage (0); } else if (ctx->orig_wnd_proc) { /*restore window proc*/ SetWindowLong(ctx->os_hwnd, GWL_WNDPROC, ctx->orig_wnd_proc); ctx->orig_wnd_proc = 0L; } break; case WM_ACTIVATE: #if 1 if (ctx->fullscreen && (LOWORD(wParam)==WA_INACTIVE) && (hWnd==ctx->fs_hwnd)) { evt.type = GF_EVENT_SHOWHIDE; vout->on_event(vout->evt_cbk_hdl, &evt); } #endif break; case WM_SETCURSOR: if (ctx->cur_hwnd==hWnd) DD_SetCursor(vout, ctx->cursor_type); return 1; case WM_ERASEBKGND: //InvalidateRect(ctx->cur_hwnd, NULL, TRUE); //break; case WM_PAINT: if (ctx->cur_hwnd==hWnd) { evt.type = GF_EVENT_REFRESH; vout->on_event(vout->evt_cbk_hdl, &evt); } break; case WM_KILLFOCUS: if (hWnd==ctx->os_hwnd) ctx->has_focus = 0; break; case WM_MOUSEMOVE: if (ctx->cur_hwnd!=hWnd) break; if (ctx->last_mouse_pos != lParam) { ctx->last_mouse_pos = lParam; DD_SetCursor(vout, (ctx->cursor_type==GF_CURSOR_HIDE) ? ctx->cursor_type_backup : ctx->cursor_type); evt.type = GF_EVENT_MOUSEMOVE; DD_GetCoordinates(lParam, &evt); vout->on_event(vout->evt_cbk_hdl, &evt); mouse_start_timer(ctx, hWnd, vout); } break; case WM_TIMER: if (wParam==10) { if (ctx->fullscreen && (ctx->cursor_type!=GF_CURSOR_HIDE)) { if (gf_sys_clock() > MOUSE_HIDE_TIMEOUT + ctx->last_mouse_move) { ctx->cursor_type_backup = ctx->cursor_type; DD_SetCursor(vout, GF_CURSOR_HIDE); KillTimer(hWnd, ctx->timer); ctx->timer = 0; } } } break; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: grab_mouse(ctx, vout); evt.type = GF_EVENT_MOUSEDOWN; DD_GetCoordinates(lParam, &evt); evt.mouse.button = GF_MOUSE_LEFT; vout->on_event(vout->evt_cbk_hdl, &evt); if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) { ctx->has_focus = 1; SetFocus(ctx->os_hwnd); } break; case WM_LBUTTONUP: release_mouse(ctx, hWnd, vout); evt.type = GF_EVENT_MOUSEUP; DD_GetCoordinates(lParam, &evt); evt.mouse.button = GF_MOUSE_LEFT; vout->on_event(vout->evt_cbk_hdl, &evt); break; case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: grab_mouse(ctx, vout); evt.type = GF_EVENT_MOUSEDOWN; DD_GetCoordinates(lParam, &evt); evt.mouse.button = GF_MOUSE_RIGHT; vout->on_event(vout->evt_cbk_hdl, &evt); if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) { ctx->has_focus = 1; SetFocus(ctx->os_hwnd); } break; case WM_RBUTTONUP: release_mouse(ctx, hWnd, vout); evt.type = GF_EVENT_MOUSEUP; DD_GetCoordinates(lParam, &evt); evt.mouse.button = GF_MOUSE_RIGHT; vout->on_event(vout->evt_cbk_hdl, &evt); mouse_start_timer(ctx, hWnd, vout); break; case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: grab_mouse(ctx, vout); evt.type = GF_EVENT_MOUSEDOWN; evt.mouse.button = GF_MOUSE_MIDDLE; DD_GetCoordinates(lParam, &evt); vout->on_event(vout->evt_cbk_hdl, &evt); if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) { ctx->has_focus = 1; SetFocus(ctx->os_hwnd); } break; case WM_MBUTTONUP: release_mouse(ctx, hWnd, vout); evt.type = GF_EVENT_MOUSEUP; DD_GetCoordinates(lParam, &evt); evt.mouse.button = GF_MOUSE_MIDDLE; vout->on_event(vout->evt_cbk_hdl, &evt); mouse_start_timer(ctx, hWnd, vout); break; case WM_MOUSEWHEEL: if (ctx->cur_hwnd==hWnd) { DD_SetCursor(vout, (ctx->cursor_type==GF_CURSOR_HIDE) ? ctx->cursor_type_backup : ctx->cursor_type); evt.type = GF_EVENT_MOUSEWHEEL; DD_GetCoordinates(lParam, &evt); evt.mouse.wheel_pos = FLT2FIX( ((Float) (s16) HIWORD(wParam)) / WHEEL_DELTA ); vout->on_event(vout->evt_cbk_hdl, &evt); mouse_start_timer(ctx, hWnd, vout); } return 1; /*there's a bug on alt state (we miss one event)*/ case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_KEYUP: case WM_KEYDOWN: w32_translate_key(wParam, lParam, &evt.key); evt.type = ((msg==WM_SYSKEYDOWN) || (msg==WM_KEYDOWN)) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP; vout->on_event(vout->evt_cbk_hdl, &evt); break; case WM_CHAR: evt.type = GF_EVENT_TEXTINPUT; evt.character.unicode_char = wParam; vout->on_event(vout->evt_cbk_hdl, &evt); break; } return DefWindowProc (hWnd, msg, wParam, lParam); }
LRESULT APIENTRY GAPI_WindowProc(HWND hWnd, UINT msg, UINT wParam, LONG lParam) { GF_Event evt; switch (msg) { case WM_SIZE: { GAPIPriv *ctx = (GAPIPriv *)the_video_driver->opaque; evt.type = GF_EVENT_SIZE; evt.size.width = LOWORD(lParam); evt.size.height = HIWORD(lParam); the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); } break; case WM_CLOSE: evt.type = GF_EVENT_QUIT; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); return 1; case WM_DESTROY: { GAPIPriv *ctx = (GAPIPriv *)the_video_driver->opaque; if (ctx->owns_hwnd ) { PostQuitMessage (0); } else if (ctx->orig_wnd_proc) { /*restore window proc*/ SetWindowLong(ctx->hWnd, GWL_WNDPROC, ctx->orig_wnd_proc); ctx->orig_wnd_proc = 0L; } } break; case WM_ERASEBKGND: evt.type = GF_EVENT_REFRESH; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); break; case WM_PAINT: #ifndef DIRECT_BITBLT { GAPIPriv *gctx = (GAPIPriv *)the_video_driver->opaque; if (gctx->gx_mode || !gctx->bitmap) break; HDC dc = GetDC(gctx->hWnd); BitBlt(dc, gctx->dst_blt.x, gctx->dst_blt.y, gctx->bb_width, gctx->bb_height, gctx->hdcBitmap, 0, 0, SRCCOPY); ReleaseDC(gctx->hWnd, dc); } #endif break; case WM_MOUSEMOVE: GAPI_GetCoordinates(lParam, &evt); evt.type = GF_EVENT_MOUSEMOVE; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); break; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: GAPI_GetCoordinates(lParam, &evt); evt.type = GF_EVENT_MOUSEDOWN; evt.mouse.button = GF_MOUSE_LEFT; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); break; case WM_LBUTTONUP: GAPI_GetCoordinates(lParam, &evt); evt.type = GF_EVENT_MOUSEUP; evt.mouse.button = GF_MOUSE_LEFT; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); break; /*FIXME - there's a bug on alt state (we miss one event)*/ case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_KEYDOWN: case WM_KEYUP: w32_translate_key(wParam, lParam, &evt.key); evt.type = ((msg==WM_SYSKEYDOWN) || (msg==WM_KEYDOWN)) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP; the_video_driver->on_event(the_video_driver->evt_cbk_hdl, &evt); break; case WM_CHAR: evt.type = GF_EVENT_TEXTINPUT; evt.character.unicode_char = wParam; break; } return DefWindowProc (hWnd, msg, wParam, lParam); }