Mercurial > dwindows
comparison os2/dw.c @ 67:ab9b0fa6c66e
Focus fixes and removal of several hack in the OS/2 code base.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 22 Jan 2002 10:55:20 +0000 |
parents | a6801a2260af |
children | 8d6100960adf |
comparison
equal
deleted
inserted
replaced
66:664a274a46a6 | 67:ab9b0fa6c66e |
---|---|
167 HPOINTER hptrIcon; | 167 HPOINTER hptrIcon; |
168 PVOID user; | 168 PVOID user; |
169 | 169 |
170 } CNRITEM, *PCNRITEM; | 170 } CNRITEM, *PCNRITEM; |
171 | 171 |
172 | |
173 /* Find the desktop window handle */ | |
174 HWND _toplevel_window(HWND handle) | |
175 { | |
176 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT); | |
177 | |
178 /* Find the toplevel window */ | |
179 while((box = WinQueryWindow(lastbox, QW_PARENT)) > 0x80000001 && box > 0) | |
180 { | |
181 lastbox = box; | |
182 } | |
183 if(box > 0) | |
184 return lastbox; | |
185 return handle; | |
186 } | |
172 | 187 |
173 /* This function changes the owner of buttons in to the | 188 /* This function changes the owner of buttons in to the |
174 * dynamicwindows handle to fix a problem in notebooks. | 189 * dynamicwindows handle to fix a problem in notebooks. |
175 */ | 190 */ |
176 void _fix_button_owner(HWND handle, HWND dw) | 191 void _fix_button_owner(HWND handle, HWND dw) |
636 * layout and moves the current focus to the next item. | 651 * layout and moves the current focus to the next item. |
637 */ | 652 */ |
638 void _shift_focus(HWND handle) | 653 void _shift_focus(HWND handle) |
639 { | 654 { |
640 Box *thisbox; | 655 Box *thisbox; |
641 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT); | 656 HWND box, lastbox = _toplevel_window(handle); |
642 | |
643 /* Find the toplevel window */ | |
644 while((box = WinQueryWindow(lastbox, QW_PARENT)) > 0x80000001) | |
645 { | |
646 lastbox = box; | |
647 } | |
648 | 657 |
649 box = WinWindowFromID(lastbox, FID_CLIENT); | 658 box = WinWindowFromID(lastbox, FID_CLIENT); |
650 if(box) | 659 if(box) |
651 thisbox = WinQueryWindowPtr(box, QWP_USER); | 660 thisbox = WinQueryWindowPtr(box, QWP_USER); |
652 else | 661 else |
663 * layout and moves the current focus to the next item. | 672 * layout and moves the current focus to the next item. |
664 */ | 673 */ |
665 void _shift_focus_back(HWND handle) | 674 void _shift_focus_back(HWND handle) |
666 { | 675 { |
667 Box *thisbox; | 676 Box *thisbox; |
668 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT); | 677 HWND box, lastbox = _toplevel_window(handle); |
669 | |
670 /* Find the toplevel window */ | |
671 while((box = WinQueryWindow(lastbox, QW_PARENT)) > 0x80000001) | |
672 { | |
673 lastbox = box; | |
674 } | |
675 | 678 |
676 box = WinWindowFromID(lastbox, FID_CLIENT); | 679 box = WinWindowFromID(lastbox, FID_CLIENT); |
677 if(box) | 680 if(box) |
678 thisbox = WinQueryWindowPtr(box, QWP_USER); | 681 thisbox = WinQueryWindowPtr(box, QWP_USER); |
679 else | 682 else |
695 SWP swp; | 698 SWP swp; |
696 | 699 |
697 WinQueryWindowPos(hwndFrame, &swp); | 700 WinQueryWindowPos(hwndFrame, &swp); |
698 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy-1, SWP_SIZE); | 701 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy-1, SWP_SIZE); |
699 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy, SWP_SIZE); | 702 WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, swp.cx, swp.cy, SWP_SIZE); |
700 } | |
701 | |
702 /* Focus toplevel window */ | |
703 void _toplevel_focus(HWND handle) | |
704 { | |
705 HWND box, lastbox = WinQueryWindow(handle, QW_PARENT); | |
706 | |
707 /* Find the toplevel window */ | |
708 while((box = WinQueryWindow(lastbox, QW_PARENT)) > 0x80000001) | |
709 { | |
710 lastbox = box; | |
711 } | |
712 | |
713 box = WinWindowFromID(lastbox, FID_CLIENT); | |
714 if(box) | |
715 WinSetActiveWindow(HWND_DESKTOP, lastbox); | |
716 } | 703 } |
717 | 704 |
718 /* This function will recursively search a box and add up the total height of it */ | 705 /* This function will recursively search a box and add up the total height of it */ |
719 void _count_size(HWND box, int type, int *xsize, int *xorigsize) | 706 void _count_size(HWND box, int type, int *xsize, int *xorigsize) |
720 { | 707 { |
1429 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER); | 1416 WindowData *blah = (WindowData *)WinQueryWindowPtr(hWnd, QWP_USER); |
1430 | 1417 |
1431 switch(msg) | 1418 switch(msg) |
1432 { | 1419 { |
1433 case WM_SETFOCUS: | 1420 case WM_SETFOCUS: |
1434 _toplevel_focus(hWnd); | |
1435 _run_event(hWnd, msg, mp1, mp2); | 1421 _run_event(hWnd, msg, mp1, mp2); |
1436 break; | 1422 break; |
1437 } | 1423 } |
1438 | 1424 |
1439 if(blah && blah->oldproc) | 1425 if(blah && blah->oldproc) |
1476 if(strncmp(tmpbuf, "#38", 4)==0) | 1462 if(strncmp(tmpbuf, "#38", 4)==0) |
1477 _run_event(hWnd, msg, mp1, mp2); | 1463 _run_event(hWnd, msg, mp1, mp2); |
1478 } | 1464 } |
1479 break; | 1465 break; |
1480 case WM_SETFOCUS: | 1466 case WM_SETFOCUS: |
1481 _toplevel_focus(hWnd); | |
1482 _run_event(hWnd, msg, mp1, mp2); | 1467 _run_event(hWnd, msg, mp1, mp2); |
1483 break; | 1468 break; |
1484 case WM_CHAR: | 1469 case WM_CHAR: |
1485 if(SHORT1FROMMP(mp2) == '\t') | 1470 if(SHORT1FROMMP(mp2) == '\t') |
1486 { | 1471 { |
1531 case WM_BUTTON2DOWN: | 1516 case WM_BUTTON2DOWN: |
1532 case WM_BUTTON3DOWN: | 1517 case WM_BUTTON3DOWN: |
1533 _run_event(hWnd, WM_SETFOCUS, (MPARAM)FALSE, (MPARAM)TRUE); | 1518 _run_event(hWnd, WM_SETFOCUS, (MPARAM)FALSE, (MPARAM)TRUE); |
1534 break; | 1519 break; |
1535 case WM_SETFOCUS: | 1520 case WM_SETFOCUS: |
1536 _toplevel_focus(hWnd); | |
1537 _run_event(hWnd, msg, mp1, mp2); | 1521 _run_event(hWnd, msg, mp1, mp2); |
1538 break; | 1522 break; |
1539 case WM_PAINT: | 1523 case WM_PAINT: |
1540 { | 1524 { |
1541 HWND parent = WinQueryWindow(hWnd, QW_PARENT); | 1525 HWND parent = WinQueryWindow(hWnd, QW_PARENT); |
1989 | 1973 |
1990 return (MRESULT)result; | 1974 return (MRESULT)result; |
1991 } | 1975 } |
1992 #endif | 1976 #endif |
1993 | 1977 |
1994 int _warp4_focus_fix(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) | |
1995 { | |
1996 /* This is a hack to stop an infinite loop in the | |
1997 * Warp 4 default window procedure. It seems that | |
1998 * under very rare circumstances, the same WM_FOCUSCHANGE | |
1999 * message will bounce between an entryfield and | |
2000 * the frame it sits on, this will stop duplicate | |
2001 * messages and thus prevent the infinite loop. | |
2002 */ | |
2003 if(msg == WM_FOCUSCHANGE && SHORT1FROMMP(mp2)) | |
2004 { | |
2005 static HWND lastfocus = 0; | |
2006 static time_t lasttime = 0; | |
2007 static int count = 0; | |
2008 time_t currtime = time(NULL); | |
2009 | |
2010 if(lastfocus == (HWND)mp1 && currtime == lasttime) | |
2011 { | |
2012 if(count > 5) | |
2013 { | |
2014 count = 0; | |
2015 return 1; | |
2016 } | |
2017 count++; | |
2018 return 0; | |
2019 } | |
2020 | |
2021 count = 0; | |
2022 lastfocus = (HWND)mp1; | |
2023 lasttime = currtime; | |
2024 } | |
2025 return 0; | |
2026 } | |
2027 | |
2028 /* Handles control messages sent to the box (owner). */ | 1978 /* Handles control messages sent to the box (owner). */ |
2029 MRESULT EXPENTRY _controlproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 1979 MRESULT EXPENTRY _controlproc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2030 { | 1980 { |
2031 Box *blah = WinQueryWindowPtr(hWnd, QWP_USER); | 1981 Box *blah = WinQueryWindowPtr(hWnd, QWP_USER); |
2032 | 1982 |
2036 case WM_CONTROL: | 1986 case WM_CONTROL: |
2037 _run_event(hWnd, msg, mp1, mp2); | 1987 _run_event(hWnd, msg, mp1, mp2); |
2038 break; | 1988 break; |
2039 } | 1989 } |
2040 #endif | 1990 #endif |
2041 | |
2042 if(_warp4_focus_fix(hWnd, msg, mp1, mp2)) | |
2043 return (MRESULT)0; | |
2044 if(msg == WM_SETFOCUS) | |
2045 _toplevel_focus(hWnd); | |
2046 | 1991 |
2047 if(blah && blah->oldproc) | 1992 if(blah && blah->oldproc) |
2048 return blah->oldproc(hWnd, msg, mp1, mp2); | 1993 return blah->oldproc(hWnd, msg, mp1, mp2); |
2049 | 1994 |
2050 return WinDefWindowProc(hWnd, msg, mp1, mp2); | 1995 return WinDefWindowProc(hWnd, msg, mp1, mp2); |
2238 case WM_DESTROY: | 2183 case WM_DESTROY: |
2239 /* Free memory before destroying */ | 2184 /* Free memory before destroying */ |
2240 _free_window_memory(hWnd); | 2185 _free_window_memory(hWnd); |
2241 break; | 2186 break; |
2242 } | 2187 } |
2243 | |
2244 if(_warp4_focus_fix(hWnd, msg, mp1, mp2)) | |
2245 return (MRESULT)0; | |
2246 | 2188 |
2247 if(result != -1) | 2189 if(result != -1) |
2248 return (MRESULT)result; | 2190 return (MRESULT)result; |
2249 else | 2191 else |
2250 return WinDefWindowProc(hWnd, msg, mp1, mp2); | 2192 return WinDefWindowProc(hWnd, msg, mp1, mp2); |
2783 switch(msg) | 2725 switch(msg) |
2784 { | 2726 { |
2785 case WM_BUTTON1DOWN: | 2727 case WM_BUTTON1DOWN: |
2786 case WM_BUTTON2DOWN: | 2728 case WM_BUTTON2DOWN: |
2787 case WM_BUTTON3DOWN: | 2729 case WM_BUTTON3DOWN: |
2788 if(!res) | 2730 if(res) |
2789 _toplevel_focus(hwnd); | 2731 return (MPARAM)TRUE; |
2790 return (MPARAM)TRUE; | |
2791 } | 2732 } |
2792 return WinDefWindowProc(hwnd, msg, mp1, mp2); | 2733 return WinDefWindowProc(hwnd, msg, mp1, mp2); |
2793 } | 2734 } |
2794 | 2735 |
2795 MRESULT EXPENTRY _TreeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 2736 MRESULT EXPENTRY _TreeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) |
2796 { | 2737 { |
2797 Box *blah = WinQueryWindowPtr(hwnd, QWP_USER); | 2738 WindowData *blah = (WindowData *)WinQueryWindowPtr(hwnd, QWP_USER); |
2739 PFNWP oldproc = 0; | |
2740 | |
2741 if(blah) | |
2742 oldproc = blah->oldproc; | |
2743 | |
2744 switch(msg) | |
2745 { | |
2746 case WM_SETFOCUS: | |
2747 _run_event(hwnd, msg, mp1, mp2); | |
2748 break; | |
2749 case WM_CHAR: | |
2750 if(SHORT1FROMMP(mp2) == '\t') | |
2751 { | |
2752 if(CHARMSG(&msg)->fs & KC_SHIFT) | |
2753 _shift_focus_back(hwnd); | |
2754 else | |
2755 _shift_focus(hwnd); | |
2756 return FALSE; | |
2757 } | |
2758 break; | |
2759 } | |
2798 | 2760 |
2799 #ifndef NO_SIGNALS | 2761 #ifndef NO_SIGNALS |
2800 _run_event(hwnd, msg, mp1, mp2); | 2762 _run_event(hwnd, msg, mp1, mp2); |
2801 #endif | 2763 #endif |
2802 if(blah && blah->oldproc) | 2764 if(oldproc) |
2803 return blah->oldproc(hwnd, msg, mp1, mp2); | 2765 return oldproc(hwnd, msg, mp1, mp2); |
2766 | |
2804 return WinDefWindowProc(hwnd, msg, mp1, mp2); | 2767 return WinDefWindowProc(hwnd, msg, mp1, mp2); |
2805 } | 2768 } |
2806 | 2769 |
2807 /* | 2770 /* |
2808 * Initializes the Dynamic Windows engine. | 2771 * Initializes the Dynamic Windows engine. |
3023 { | 2986 { |
3024 int rc = WinSetWindowPos(handle, NULLHANDLE, 0, 0, 0, 0, SWP_SHOW); | 2987 int rc = WinSetWindowPos(handle, NULLHANDLE, 0, 0, 0, 0, SWP_SHOW); |
3025 HSWITCH hswitch; | 2988 HSWITCH hswitch; |
3026 SWCNTRL swcntrl; | 2989 SWCNTRL swcntrl; |
3027 | 2990 |
3028 _fix_button_owner(handle, 0); | 2991 _fix_button_owner(_toplevel_window(handle), 0); |
3029 WinSetFocus(HWND_DESKTOP, handle); | 2992 WinSetFocus(HWND_DESKTOP, handle); |
3030 _initial_focus(handle); | 2993 _initial_focus(handle); |
3031 | 2994 |
3032 /* If this window has a switch list entry make sure it is visible */ | 2995 /* If this window has a switch list entry make sure it is visible */ |
3033 hswitch = WinQuerySwitchHandle(handle, 0); | 2996 hswitch = WinQuerySwitchHandle(handle, 0); |
3697 * id: An ID to be used for getting the resource from the | 3660 * id: An ID to be used for getting the resource from the |
3698 * resource file. | 3661 * resource file. |
3699 */ | 3662 */ |
3700 HWND dw_container_new(ULONG id) | 3663 HWND dw_container_new(ULONG id) |
3701 { | 3664 { |
3665 WindowData *blah = calloc(1, sizeof(WindowData)); | |
3702 HWND tmp = WinCreateWindow(HWND_OBJECT, | 3666 HWND tmp = WinCreateWindow(HWND_OBJECT, |
3703 WC_CONTAINER, | 3667 WC_CONTAINER, |
3704 NULL, | 3668 NULL, |
3705 WS_VISIBLE | CCS_READONLY | | 3669 WS_VISIBLE | CCS_READONLY | |
3706 CCS_SINGLESEL | CCS_AUTOPOSITION, | 3670 CCS_SINGLESEL | CCS_AUTOPOSITION, |
3708 NULLHANDLE, | 3672 NULLHANDLE, |
3709 HWND_TOP, | 3673 HWND_TOP, |
3710 id, | 3674 id, |
3711 NULL, | 3675 NULL, |
3712 NULL); | 3676 NULL); |
3677 blah->oldproc = WinSubclassWindow(tmp, _TreeProc); | |
3678 WinSetWindowPtr(tmp, QWP_USER, blah); | |
3713 dw_window_set_font(tmp, DefaultFont); | 3679 dw_window_set_font(tmp, DefaultFont); |
3714 return tmp; | 3680 return tmp; |
3715 } | 3681 } |
3716 | 3682 |
3717 /* | 3683 /* |
3721 * resource file. | 3687 * resource file. |
3722 */ | 3688 */ |
3723 HWND dw_tree_new(ULONG id) | 3689 HWND dw_tree_new(ULONG id) |
3724 { | 3690 { |
3725 CNRINFO cnrinfo; | 3691 CNRINFO cnrinfo; |
3726 Box *newbox = calloc(1, sizeof(Box)); | 3692 WindowData *blah = calloc(1, sizeof(WindowData)); |
3727 HWND tmp = WinCreateWindow(HWND_OBJECT, | 3693 HWND tmp = WinCreateWindow(HWND_OBJECT, |
3728 WC_CONTAINER, | 3694 WC_CONTAINER, |
3729 NULL, | 3695 NULL, |
3730 WS_VISIBLE | CCS_READONLY | | 3696 WS_VISIBLE | CCS_READONLY | |
3731 CCS_SINGLESEL | CCS_AUTOPOSITION, | 3697 CCS_SINGLESEL | CCS_AUTOPOSITION, |
3739 cnrinfo.flWindowAttr = CV_TREE | CA_TREELINE; | 3705 cnrinfo.flWindowAttr = CV_TREE | CA_TREELINE; |
3740 cnrinfo.slBitmapOrIcon.cx = 16; | 3706 cnrinfo.slBitmapOrIcon.cx = 16; |
3741 cnrinfo.slBitmapOrIcon.cy = 16; | 3707 cnrinfo.slBitmapOrIcon.cy = 16; |
3742 | 3708 |
3743 WinSendMsg(tmp, CM_SETCNRINFO, &cnrinfo, MPFROMLONG(CMA_FLWINDOWATTR | CMA_SLBITMAPORICON)); | 3709 WinSendMsg(tmp, CM_SETCNRINFO, &cnrinfo, MPFROMLONG(CMA_FLWINDOWATTR | CMA_SLBITMAPORICON)); |
3744 newbox->oldproc = WinSubclassWindow(tmp, _TreeProc); | 3710 blah->oldproc = WinSubclassWindow(tmp, _TreeProc); |
3745 WinSetWindowPtr(tmp, QWP_USER, newbox); | 3711 WinSetWindowPtr(tmp, QWP_USER, blah); |
3746 dw_window_set_font(tmp, DefaultFont); | 3712 dw_window_set_font(tmp, DefaultFont); |
3747 return tmp; | 3713 return tmp; |
3748 } | 3714 } |
3749 | 3715 |
3750 /* | 3716 /* |
3816 HWND_TOP, | 3782 HWND_TOP, |
3817 id, | 3783 id, |
3818 NULL, | 3784 NULL, |
3819 NULL); | 3785 NULL); |
3820 dw_window_set_font(tmp, DefaultFont); | 3786 dw_window_set_font(tmp, DefaultFont); |
3821 blah->oldproc = WinSubclassWindow(tmp, _comboentryproc); | 3787 blah->oldproc = WinSubclassWindow(tmp, _entryproc); |
3822 WinSetWindowPtr(tmp, QWP_USER, blah); | 3788 WinSetWindowPtr(tmp, QWP_USER, blah); |
3823 return tmp; | 3789 return tmp; |
3824 } | 3790 } |
3825 | 3791 |
3826 /* | 3792 /* |
5275 CNRINFO cnri; | 5241 CNRINFO cnri; |
5276 int z; | 5242 int z; |
5277 ULONG size = sizeof(RECORDCORE); | 5243 ULONG size = sizeof(RECORDCORE); |
5278 ULONG *offStruct = malloc(count * sizeof(ULONG)); | 5244 ULONG *offStruct = malloc(count * sizeof(ULONG)); |
5279 ULONG *tempflags = malloc((count+1) * sizeof(ULONG)); | 5245 ULONG *tempflags = malloc((count+1) * sizeof(ULONG)); |
5280 ULONG *oldflags = (ULONG *)WinQueryWindowPtr(handle, 0); | 5246 WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); |
5247 ULONG *oldflags = blah ? blah->data : 0; | |
5281 | 5248 |
5282 if(!offStruct || !tempflags) | 5249 if(!offStruct || !tempflags) |
5283 return FALSE; | 5250 return FALSE; |
5284 | 5251 |
5285 memcpy(tempflags, flags, count * sizeof(ULONG)); | 5252 memcpy(tempflags, flags, count * sizeof(ULONG)); |
5286 tempflags[count] = 0; | 5253 tempflags[count] = 0; |
5287 | 5254 |
5288 WinSetWindowPtr(handle, 0, tempflags); | 5255 blah->data = tempflags; |
5289 | 5256 |
5290 if(oldflags) | 5257 if(oldflags) |
5291 free(oldflags); | 5258 free(oldflags); |
5292 | 5259 |
5293 while((first = (PFIELDINFO)WinSendMsg(handle, CM_QUERYDETAILFIELDINFO, 0, MPFROMSHORT(CMA_FIRST))) != NULL) | 5260 while((first = (PFIELDINFO)WinSendMsg(handle, CM_QUERYDETAILFIELDINFO, 0, MPFROMSHORT(CMA_FIRST))) != NULL) |
5409 * handle: Handle to the container window (widget). | 5376 * handle: Handle to the container window (widget). |
5410 * rowcount: The number of items to be populated. | 5377 * rowcount: The number of items to be populated. |
5411 */ | 5378 */ |
5412 void *dw_container_alloc(HWND handle, int rowcount) | 5379 void *dw_container_alloc(HWND handle, int rowcount) |
5413 { | 5380 { |
5414 ULONG *flags = (ULONG *)WinQueryWindowPtr(handle, 0); | 5381 WindowData *wd = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); |
5382 ULONG *flags = wd ? wd->data : 0; | |
5415 int z, size = 0, totalsize, count = 0; | 5383 int z, size = 0, totalsize, count = 0; |
5416 PRECORDCORE temp; | 5384 PRECORDCORE temp; |
5417 ContainerInfo *ci; | 5385 ContainerInfo *ci; |
5418 void *blah = NULL; | 5386 void *blah = NULL; |
5419 | 5387 |
5479 * row: Zero based row of data being set. | 5447 * row: Zero based row of data being set. |
5480 * data: Pointer to the data to be added. | 5448 * data: Pointer to the data to be added. |
5481 */ | 5449 */ |
5482 void dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) | 5450 void dw_container_set_item(HWND handle, void *pointer, int column, int row, void *data) |
5483 { | 5451 { |
5484 ULONG totalsize, size = 0, *flags = (ULONG *)WinQueryWindowPtr(handle, 0); | 5452 WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); |
5453 ULONG totalsize, size = 0, *flags = blah ? blah->data : 0; | |
5485 int z, currentcount; | 5454 int z, currentcount; |
5486 ContainerInfo *ci = (ContainerInfo *)pointer; | 5455 ContainerInfo *ci = (ContainerInfo *)pointer; |
5487 PRECORDCORE temp; | 5456 PRECORDCORE temp; |
5488 CNRINFO cnr; | 5457 CNRINFO cnr; |
5489 void *dest; | 5458 void *dest; |