5 #include "../../rtlib/win32/fb_private_console.h"
8 #define WM_MOUSEENTER WM_USER
10 #ifndef WM_XBUTTONDOWN
11 #define WM_XBUTTONDOWN 523
12 #define WM_XBUTTONUP 524
13 #define WM_XBUTTONDBLCLK 525
16 #ifndef WM_MOUSEHWHEEL
17 #define WM_MOUSEHWHEEL 526
21 #define MK_XBUTTON1 32
22 #define MK_XBUTTON2 64
25 #ifndef MONITOR_DEFAULTTONEAREST
26 #define MONITOR_DEFAULTTONEAREST 0x00000002
78 GetClientRect(fb_win32.
wnd, &rc);
81 ClientToScreen(fb_win32.
wnd, &point);
86 ClientToScreen(fb_win32.
wnd, &point);
104 if (fb_win32.
init()) {
117 POINT pt, rect_pt[2];
118 RECT *
rect = (RECT *)rect_pt;
120 GetClientRect(fb_win32.
wnd, rect);
121 MapWindowPoints(fb_win32.
wnd,
NULL, rect_pt, 2);
123 if ((!PtInRect(rect, pt)) || (WindowFromPoint(pt) != fb_win32.
wnd)) {
124 KillTimer(fb_win32.
wnd, idEvent);
125 PostMessage(fb_win32.
wnd, WM_MOUSELEAVE, 0, 0);
131 if (e->dwFlags == TME_LEAVE)
139 TRACKMOUSEEVENT track_e;
140 POINT mouse_pos, rect_pt[2];
141 RECT *
rect = (RECT *)rect_pt;
149 GetClientRect(fb_win32.
wnd, rect);
150 MapWindowPoints(fb_win32.
wnd,
NULL, rect_pt, 2);
151 GetCursorPos(&mouse_pos);
152 mouse_on = PtInRect(rect, mouse_pos);
157 is_minimized = HIWORD(wParam);
158 fb_win32.
is_active = ((!is_minimized) && (LOWORD(wParam) != WA_INACTIVE));
168 SetThreadPriority(
handle, THREAD_PRIORITY_ABOVE_NORMAL );
170 SetThreadPriority(
handle, THREAD_PRIORITY_NORMAL );
181 KillTimer(fb_win32.
wnd, TME_LEAVE);
183 if (!((LOWORD(wParam)) && (is_minimized))) {
203 SetCursor(LoadCursor(
NULL, IDC_ARROW));
209 mouse_y = e.
y = (lParam >> 16) & 0xFFFF;
231 case WM_LBUTTONDBLCLK:
247 case WM_RBUTTONDBLCLK:
263 case WM_MBUTTONDBLCLK:
305 if ((
signed)wParam > 0)
316 if ((
signed)wParam > 0)
330 int is_alt_enter = ((message == WM_SYSKEYDOWN) && (wParam == VK_RETURN) && (lParam & 0x20000000));
331 int is_maximize = ((message == WM_SIZE) && (wParam == SIZE_MAXIMIZED));
332 if ( is_maximize || is_alt_enter) {
340 if( message!=WM_SYSKEYDOWN )
347 WORD wVkCode = (WORD) wParam;
348 WORD wVsCode = (WORD) (( lParam & 0xFF0000 ) >> 16);
349 int is_ext_keycode = ( lParam & 0x1000000 )!=0;
350 size_t repeat_count = ( lParam & 0xFFFF );
351 int is_repeated = (lParam & 0x40000000);
352 DWORD dwControlKeyState = 0;
357 GetKeyboardState(key_state);
359 if( (key_state[VK_SHIFT] | key_state[VK_LSHIFT] | key_state[VK_RSHIFT]) & 0x80 )
360 dwControlKeyState ^= SHIFT_PRESSED;
361 if( (key_state[VK_LCONTROL] | key_state[VK_CONTROL]) & 0x80 )
362 dwControlKeyState ^= LEFT_CTRL_PRESSED;
363 if( key_state[VK_RCONTROL] & 0x80 )
364 dwControlKeyState ^= RIGHT_CTRL_PRESSED;
365 if( (key_state[VK_LMENU] | key_state[VK_MENU]) & 0x80 )
366 dwControlKeyState ^= LEFT_ALT_PRESSED;
367 if( key_state[VK_RMENU] & 0x80 )
368 dwControlKeyState ^= RIGHT_ALT_PRESSED;
370 dwControlKeyState |= ENHANCED_KEY;
372 is_dead_key = (MapVirtualKey( wVkCode, 2 ) & 0x80000000)!=0;
375 if( ToAscii( wVkCode, wVsCode, key_state, &wKey, 0 )==1 ) {
376 chAsciiChar = (char) wKey;
390 if (message == WM_KEYDOWN) {
396 while( repeat_count-- ) {
406 e.
ascii = ((key < 0) || (key > 0xFF)) ? 0 :
key;
409 if( wVkCode == VK_F10 || wVkCode == VK_MENU || key ==
KEY_QUIT )
416 size_t repeat_count = ( lParam & 0xFFFF );
417 int key = (int) wParam;
423 while( repeat_count-- ) {
438 BeginPaint(fb_win32.
wnd, &ps);
440 EndPaint(fb_win32.
wnd, &ps);
443 case WM_DISPLAYCHANGE:
453 case WM_GETMINMAXINFO:
455 mmi = (MINMAXINFO *)lParam;
456 mmi->ptMaxSize.x = fb_win32.
fullw;
457 mmi->ptMaxSize.y = fb_win32.
fullh;
458 mmi->ptMinTrackSize.x = fb_win32.
fullw;
459 mmi->ptMinTrackSize.y = fb_win32.
fullh;
460 mmi->ptMaxTrackSize.x = fb_win32.
fullw;
461 mmi->ptMaxTrackSize.y = fb_win32.
fullh;
465 if ((message == WM_MOUSEMOVE) || (message ==
WM_MOUSEENTER)) {
467 track_e.cbSize =
sizeof(TRACKMOUSEEVENT);
468 track_e.dwFlags = TME_LEAVE;
469 track_e.hwndTrack = hWnd;
485 return DefWindowProc(hWnd, message, wParam, lParam);
491 while (PeekMessage(&message, fb_win32.
wnd, 0, 0, PM_REMOVE)) {
492 TranslateMessage(&message);
493 DispatchMessage(&message);
508 SetWindowPos(fb_win32.
wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOSENDCHANGING);
510 SetForegroundWindow(fb_win32.
wnd);
514 int fb_hWin32Init(
char *title,
int w,
int h,
int depth,
int refresh_rate,
int flags)
522 info.dwOSVersionInfoSize =
sizeof(info);
524 fb_win32.
version = (info.dwMajorVersion << 8) | info.dwMinorVersion;
526 module = GetModuleHandle(
"USER32");
548 SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,
FALSE,
NULL, 0);
560 fb_win32.
depth = depth;
561 fb_win32.
flags = flags;
566 fb_win32.
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
569 fb_win32.
wndclass.hIcon = LoadIcon(
NULL, IDI_APPLICATION);
583 if( events[0] ==
NULL ) {
590 unsigned int thrdaddr;
591 events[1] = (
HANDLE)_beginthreadex(
NULL, 0, fb_win32.
thread, events[0], 0, &thrdaddr );
594 events[1] = CreateThread(
NULL, 0, fb_win32.
thread, events[0], 0, &dwThreadId );
596 if( events[1] ==
NULL ) {
597 CloseHandle(events[0]);
601 result = WaitForMultipleObjects(2, events,
FALSE, INFINITE);
602 CloseHandle(events[0]);
604 if (result != WAIT_OBJECT_0)
608 SetThreadPriority(
handle, THREAD_PRIORITY_ABOVE_NORMAL);
629 WaitForSingleObject(
handle, INFINITE);
661 fb_win32.
palette[index].peRed = r;
662 fb_win32.
palette[index].peGreen = g;
663 fb_win32.
palette[index].peBlue = b;
664 fb_win32.
palette[index].peFlags = PC_NOCOLLAPSE;
692 point.x =
MID(0, x, fb_win32.
w - 1);
693 point.y =
MID(0, y, fb_win32.
h - 1);
695 ClientToScreen(fb_win32.
wnd, &point);
696 SetCursorPos(point.x, point.y);
703 PostMessage(fb_win32.
wnd, WM_SETCURSOR, 0, 0);
707 PostMessage(fb_win32.
wnd, WM_SETCURSOR, 0, 0);
725 SetWindowText(fb_win32.
wnd, title);
735 if( (x == 0x80000000) && (y == 0x80000000) ) {
738 if( GetWindowRect( fb_win32.
wnd, &rc ) ) {
741 return (x & 0xFFFF) | (y << 16);
745 SetWindowPos( fb_win32.
wnd, HWND_TOP, x, y, 0, 0,
746 SWP_ASYNCWINDOWPOS | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER );
752 void fb_hScreenInfo(ssize_t *width, ssize_t *height, ssize_t *depth, ssize_t *refresh)
757 *width = GetDeviceCaps(hdc, HORZRES);
758 *height = GetDeviceCaps(hdc, VERTRES);
759 *depth = GetDeviceCaps(hdc, BITSPIXEL);
760 *refresh = GetDeviceCaps(hdc, VREFRESH);
761 ReleaseDC(
NULL, hdc);
766 return (ssize_t)fb_win32.
wnd;
780 void *
p = realloc( k->
v, (nchars+1) * charsize );
811 int length1, length2;
817 length1 = MultiByteToWideChar( source_cp, 0,
821 if( length1 > keyconv1.
size )
827 length1 = MultiByteToWideChar( source_cp, 0,
829 keyconv1.
w, keyconv1.
size );
831 keyconv1.
w[length1] = 0;
834 length2 = WideCharToMultiByte( dest_cp, 0,
835 (LPCWSTR)keyconv1.
w, length1,
839 if( length2 > keyconv2.
size )
845 length2 = WideCharToMultiByte( dest_cp, 0,
846 (LPCWSTR)keyconv1.
w, length1,
847 (LPSTR)keyconv2.
a, keyconv2.
size,
850 keyconv2.
a[length2] = 0;
852 return keyconv2.
a[0];