Mercurial > dwindows
comparison win/dw.c @ 527:e0ea29c3d1eb
Fixed dw_window_pointer() so it works on Windows. Tried to fix the
timer problems on Windows, but only managed to reduce the problem and
eliminate obsolete timer code. Fixed a calling convention problem
caused by incorrect placement of the definition of API in the compat.h
header. Make dw_beep() not block on OS/2 and Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 23 Mar 2004 11:00:04 +0000 |
parents | d3ce0afa6cf5 |
children | 79696a852401 |
comparison
equal
deleted
inserted
replaced
526:d3ce0afa6cf5 | 527:e0ea29c3d1eb |
---|---|
19 #include <stdio.h> | 19 #include <stdio.h> |
20 #include <process.h> | 20 #include <process.h> |
21 #include <time.h> | 21 #include <time.h> |
22 #include "dw.h" | 22 #include "dw.h" |
23 | 23 |
24 HWND popup = (HWND)NULL, hwndBubble = (HWND)NULL, hwndBubbleLast, DW_HWND_OBJECT = (HWND)NULL; | 24 HWND popup = (HWND)NULL, hwndBubble = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; |
25 | 25 |
26 HINSTANCE DWInstance = NULL; | 26 HINSTANCE DWInstance = NULL; |
27 | 27 |
28 DWORD dwVersion = 0, dwComctlVer = 0; | 28 DWORD dwVersion = 0, dwComctlVer = 0; |
29 DWTID _dwtid = -1; | 29 DWTID _dwtid = -1; |
1428 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) | 1428 if(tmp->message == msg || msg == WM_COMMAND || msg == WM_NOTIFY || tmp->message == WM_USER+1) |
1429 { | 1429 { |
1430 switch(msg) | 1430 switch(msg) |
1431 { | 1431 { |
1432 case WM_TIMER: | 1432 case WM_TIMER: |
1433 { | |
1434 int (*timerfunc)(void *) = tmp->signalfunction; | |
1435 if(tmp->id == (int)mp1) | |
1436 { | 1433 { |
1437 if(!timerfunc(tmp->data)) | 1434 if(!hWnd) |
1438 dw_timer_disconnect(tmp->id); | 1435 { |
1439 tmp = NULL; | 1436 int (*timerfunc)(void *) = tmp->signalfunction; |
1437 if(tmp->id == (int)mp1) | |
1438 { | |
1439 if(!timerfunc(tmp->data)) | |
1440 dw_timer_disconnect(tmp->id); | |
1441 tmp = NULL; | |
1442 } | |
1443 } | |
1444 result = 0; | |
1440 } | 1445 } |
1441 result = 0; | 1446 break; |
1442 } | |
1443 break; | |
1444 case WM_SETFOCUS: | 1447 case WM_SETFOCUS: |
1445 { | 1448 { |
1446 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; | 1449 int (*setfocusfunc)(HWND, void *) = (int (*)(HWND, void *))tmp->signalfunction; |
1447 | 1450 |
1448 if(hWnd == tmp->window) | 1451 if(hWnd == tmp->window) |
1940 /* Free memory before destroying */ | 1943 /* Free memory before destroying */ |
1941 _free_window_memory(hWnd, 0); | 1944 _free_window_memory(hWnd, 0); |
1942 EnumChildWindows(hWnd, _free_window_memory, 0); | 1945 EnumChildWindows(hWnd, _free_window_memory, 0); |
1943 } | 1946 } |
1944 break; | 1947 break; |
1948 case WM_MOUSEMOVE: | |
1949 { | |
1950 HCURSOR cursor; | |
1951 | |
1952 if((cursor = (HCURSOR)dw_window_get_data(hWnd, "_dw_cursor")) || | |
1953 (cursor = (HCURSOR)dw_window_get_data(_toplevel_window(hWnd), "_dw_cursor"))) | |
1954 { | |
1955 SetCursor(cursor); | |
1956 } | |
1957 } | |
1958 break; | |
1945 case WM_CTLCOLORSTATIC: | 1959 case WM_CTLCOLORSTATIC: |
1946 case WM_CTLCOLORLISTBOX: | 1960 case WM_CTLCOLORLISTBOX: |
1947 case WM_CTLCOLORBTN: | 1961 case WM_CTLCOLORBTN: |
1948 case WM_CTLCOLOREDIT: | 1962 case WM_CTLCOLOREDIT: |
1949 case WM_CTLCOLORMSGBOX: | 1963 case WM_CTLCOLORMSGBOX: |
2032 SetActiveWindow(hWnd); | 2046 SetActiveWindow(hWnd); |
2033 SetFocus(hWnd); | 2047 SetFocus(hWnd); |
2034 break; | 2048 break; |
2035 case WM_COMMAND: | 2049 case WM_COMMAND: |
2036 case WM_NOTIFY: | 2050 case WM_NOTIFY: |
2051 case WM_MOUSEMOVE: | |
2037 _wndproc(hWnd, msg, mp1, mp2); | 2052 _wndproc(hWnd, msg, mp1, mp2); |
2038 break; | 2053 break; |
2039 #if 0 | 2054 #if 0 |
2040 case WM_ERASEBKGND: | 2055 case WM_ERASEBKGND: |
2041 { | 2056 { |
2148 { | 2163 { |
2149 ColorInfo *cinfo; | 2164 ColorInfo *cinfo; |
2150 | 2165 |
2151 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2166 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2152 | 2167 |
2168 if(msg == WM_MOUSEMOVE) | |
2169 _wndproc(hWnd, msg, mp1, mp2); | |
2170 | |
2153 if(cinfo) | 2171 if(cinfo) |
2154 { | 2172 { |
2155 switch( msg ) | 2173 switch( msg ) |
2156 { | 2174 { |
2157 case WM_LBUTTONDOWN: | 2175 case WM_LBUTTONDOWN: |
2292 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2310 cinfo = (ColorInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2293 | 2311 |
2294 GetClassName(hWnd, tmpbuf, 99); | 2312 GetClassName(hWnd, tmpbuf, 99); |
2295 if(strcmp(tmpbuf, FRAMECLASSNAME) == 0) | 2313 if(strcmp(tmpbuf, FRAMECLASSNAME) == 0) |
2296 cinfo = &(((Box *)cinfo)->cinfo); | 2314 cinfo = &(((Box *)cinfo)->cinfo); |
2315 | |
2316 if(msg == WM_MOUSEMOVE) | |
2317 _wndproc(hWnd, msg, mp1, mp2); | |
2297 | 2318 |
2298 if(cinfo) | 2319 if(cinfo) |
2299 { | 2320 { |
2300 pOldProc = cinfo->pOldProc; | 2321 pOldProc = cinfo->pOldProc; |
2301 | 2322 |
2502 | 2523 |
2503 switch( msg ) | 2524 switch( msg ) |
2504 { | 2525 { |
2505 case WM_COMMAND: | 2526 case WM_COMMAND: |
2506 case WM_NOTIFY: | 2527 case WM_NOTIFY: |
2528 case WM_MOUSEMOVE: | |
2507 _wndproc(hWnd, msg, mp1, mp2); | 2529 _wndproc(hWnd, msg, mp1, mp2); |
2508 break; | 2530 break; |
2509 case WM_LBUTTONDBLCLK: | 2531 case WM_LBUTTONDBLCLK: |
2510 case WM_CHAR: | 2532 case WM_CHAR: |
2511 { | 2533 { |
2617 | 2639 |
2618 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); | 2640 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); |
2619 | 2641 |
2620 switch( msg ) | 2642 switch( msg ) |
2621 { | 2643 { |
2644 case WM_MOUSEMOVE: | |
2645 _wndproc(hWnd, msg, mp1, mp2); | |
2646 break; | |
2622 case WM_CHAR: | 2647 case WM_CHAR: |
2623 if(LOWORD(mp1) == '\t') | 2648 if(LOWORD(mp1) == '\t') |
2624 { | 2649 { |
2625 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) | 2650 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2626 _shift_focus_back(hWnd); | 2651 _shift_focus_back(hWnd); |
2823 /* This handles drawing the status text areas */ | 2848 /* This handles drawing the status text areas */ |
2824 BOOL CALLBACK _statuswndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) | 2849 BOOL CALLBACK _statuswndproc(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2) |
2825 { | 2850 { |
2826 switch (msg) | 2851 switch (msg) |
2827 { | 2852 { |
2853 case WM_MOUSEMOVE: | |
2854 _wndproc(hwnd, msg, mp1, mp2); | |
2855 break; | |
2828 case WM_SETTEXT: | 2856 case WM_SETTEXT: |
2829 { | 2857 { |
2830 /* Make sure the control redraws when there is a text change */ | 2858 /* Make sure the control redraws when there is a text change */ |
2831 int ret = (int)DefWindowProc(hwnd, msg, mp1, mp2); | 2859 int ret = (int)DefWindowProc(hwnd, msg, mp1, mp2); |
2832 | 2860 |
2974 if(mp1 == VK_LEFT || mp1 == VK_UP) | 3002 if(mp1 == VK_LEFT || mp1 == VK_UP) |
2975 _shift_focus_back(hwnd); | 3003 _shift_focus_back(hwnd); |
2976 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) | 3004 if(mp1 == VK_RIGHT || mp1 == VK_DOWN) |
2977 _shift_focus(hwnd); | 3005 _shift_focus(hwnd); |
2978 break; | 3006 break; |
2979 case WM_TIMER: | |
2980 if (hwndBubble) | |
2981 { | |
2982 _free_window_memory(hwndBubble, 0); | |
2983 DestroyWindow(hwndBubble); | |
2984 hwndBubble = 0; | |
2985 KillTimer(hwnd, 1); | |
2986 } | |
2987 break; | |
2988 | |
2989 case WM_MOUSEMOVE: | 3007 case WM_MOUSEMOVE: |
2990 GetCursorPos(&point); | 3008 GetCursorPos(&point); |
2991 GetWindowRect(hwnd, &rect); | 3009 GetWindowRect(hwnd, &rect); |
2992 | 3010 |
2993 if(PtInRect(&rect, point)) | 3011 if(PtInRect(&rect, point)) |
3005 if(hwndBubble) | 3023 if(hwndBubble) |
3006 { | 3024 { |
3007 _free_window_memory(hwndBubble, 0); | 3025 _free_window_memory(hwndBubble, 0); |
3008 DestroyWindow(hwndBubble); | 3026 DestroyWindow(hwndBubble); |
3009 hwndBubble = 0; | 3027 hwndBubble = 0; |
3010 KillTimer(hwndBubbleLast, 1); | |
3011 } | 3028 } |
3012 | 3029 |
3013 if(!hwndBubble) | 3030 if(!hwndBubble) |
3014 { | 3031 { |
3015 POINTL ptlWork = {0,0}; | 3032 POINTL ptlWork = {0,0}; |
3037 NULL); | 3054 NULL); |
3038 | 3055 |
3039 dw_window_set_font(hwndBubble, DefaultFont); | 3056 dw_window_set_font(hwndBubble, DefaultFont); |
3040 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); | 3057 dw_window_set_color(hwndBubble, DW_CLR_BLACK, DW_CLR_YELLOW); |
3041 | 3058 |
3042 hwndBubbleLast = hwnd; | |
3043 | |
3044 SetTimer(hwnd, 1, 3000, NULL); | 3059 SetTimer(hwnd, 1, 3000, NULL); |
3045 | 3060 |
3046 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); | 3061 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); |
3047 | 3062 |
3048 hdc = GetDC(hwndBubble); | 3063 hdc = GetDC(hwndBubble); |
3081 { | 3096 { |
3082 bMouseOver = 0; | 3097 bMouseOver = 0; |
3083 _free_window_memory(hwndBubble, 0); | 3098 _free_window_memory(hwndBubble, 0); |
3084 DestroyWindow(hwndBubble); | 3099 DestroyWindow(hwndBubble); |
3085 hwndBubble = 0; | 3100 hwndBubble = 0; |
3086 KillTimer(hwndBubbleLast, 1); | |
3087 } | 3101 } |
3088 } | 3102 } |
3103 _wndproc(hwnd, msg, mp1, mp2); | |
3089 break; | 3104 break; |
3090 case WM_CAPTURECHANGED: | 3105 case WM_CAPTURECHANGED: |
3091 /* This message means we are losing the capture for some reason | 3106 /* This message means we are losing the capture for some reason |
3092 * Either because we intentionally lost it or another window | 3107 * Either because we intentionally lost it or another window |
3093 * stole it | 3108 * stole it |
3096 { | 3111 { |
3097 bMouseOver = 0; | 3112 bMouseOver = 0; |
3098 _free_window_memory(hwndBubble, 0); | 3113 _free_window_memory(hwndBubble, 0); |
3099 DestroyWindow(hwndBubble); | 3114 DestroyWindow(hwndBubble); |
3100 hwndBubble = 0; | 3115 hwndBubble = 0; |
3101 KillTimer(hwndBubbleLast, 1); | |
3102 } | 3116 } |
3103 break; | 3117 break; |
3104 } | 3118 } |
3105 | 3119 |
3106 if(!pOldProc) | 3120 if(!pOldProc) |
3745 * handle: Handle to widget for which to change. | 3759 * handle: Handle to widget for which to change. |
3746 * cursortype: ID of the pointer you want. | 3760 * cursortype: ID of the pointer you want. |
3747 */ | 3761 */ |
3748 void API dw_window_set_pointer(HWND handle, int pointertype) | 3762 void API dw_window_set_pointer(HWND handle, int pointertype) |
3749 { | 3763 { |
3750 /* | 3764 HCURSOR cursor = pointertype < 65536 ? LoadCursor(NULL, MAKEINTRESOURCE(pointertype)) : (HCURSOR)pointertype; |
3751 if(pointertype == DW_POINTER_ARROW) | 3765 |
3752 SetClassLong( handle, GCL_HCURSOR, LoadCursor( NULL, IDC_ARROW)); | 3766 dw_window_set_data(handle, "_dw_cursor", (void *)cursor); |
3753 else if(pointertype == DW_POINTER_CLOCK) | 3767 SetCursor(cursor); |
3754 SetClassLong( handle, GCL_HCURSOR, LoadCursor( NULL, IDC_WAIT)); | |
3755 else | |
3756 */ | |
3757 SetCursor(pointertype < 65536 ? LoadCursor(NULL, MAKEINTRESOURCE(pointertype)) : (HCURSOR)pointertype); | |
3758 } | 3768 } |
3759 | 3769 |
3760 /* | 3770 /* |
3761 * Create a new Window Frame. | 3771 * Create a new Window Frame. |
3762 * Parameters: | 3772 * Parameters: |
7604 ReleaseDC(dest, hdcdest); | 7614 ReleaseDC(dest, hdcdest); |
7605 if(!srcp) | 7615 if(!srcp) |
7606 ReleaseDC(src, hdcsrc); | 7616 ReleaseDC(src, hdcsrc); |
7607 } | 7617 } |
7608 | 7618 |
7619 /* Run Beep() in a separate thread so it doesn't block */ | |
7620 void _beepthread(void *data) | |
7621 { | |
7622 int *info = (int *)data; | |
7623 | |
7624 if(data) | |
7625 { | |
7626 Beep(info[0], info[1]); | |
7627 free(data); | |
7628 } | |
7629 } | |
7630 | |
7609 /* | 7631 /* |
7610 * Emits a beep. | 7632 * Emits a beep. |
7611 * Parameters: | 7633 * Parameters: |
7612 * freq: Frequency. | 7634 * freq: Frequency. |
7613 * dur: Duration. | 7635 * dur: Duration. |
7614 */ | 7636 */ |
7615 void API dw_beep(int freq, int dur) | 7637 void API dw_beep(int freq, int dur) |
7616 { | 7638 { |
7617 Beep(freq, dur); | 7639 int *info = malloc(sizeof(int) * 2); |
7640 | |
7641 if(info) | |
7642 { | |
7643 info[0] = freq; | |
7644 info[1] = dur; | |
7645 | |
7646 _beginthread(_beepthread, 100, (void *)info); | |
7647 } | |
7618 } | 7648 } |
7619 | 7649 |
7620 /* Open a shared library and return a handle. | 7650 /* Open a shared library and return a handle. |
7621 * Parameters: | 7651 * Parameters: |
7622 * name: Base name of the shared library. | 7652 * name: Base name of the shared library. |