comparison win/dw.c @ 1212:5271d5cb27ac

Implemented dw_container_set_row_bg() on Windows. Current immplementation is a bit slow, it does more redrawing than necessary... but it works for now... will look to improve it in the future. Also removed a lot of dead code from a previous attempt at implementation. Also flipped the default colors on Mac since the first index is even (0) not odd (1).
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 09 Oct 2011 09:50:07 +0000
parents 70dca53cb071
children 22cedf18db25
comparison
equal deleted inserted replaced
1211:70dca53cb071 1212:5271d5cb27ac
1510 is_checked = (int)dw_window_get_data(DW_HWND_OBJECT, buffer); 1510 is_checked = (int)dw_window_get_data(DW_HWND_OBJECT, buffer);
1511 is_checked = (is_checked) ? 0 : 1; 1511 is_checked = (is_checked) ? 0 : 1;
1512 dw_menu_item_set_check( window, id, is_checked ); 1512 dw_menu_item_set_check( window, id, is_checked );
1513 } 1513 }
1514 } 1514 }
1515
1516 #ifdef DWDEBUG
1517 long ProcessCustomDraw (LPARAM lParam)
1518 {
1519 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
1520
1521 switch(lplvcd->nmcd.dwDrawStage)
1522 {
1523 case CDDS_PREPAINT : //Before the paint cycle begins
1524 //request notifications for individual listview items
1525 dw_messagebox("LISTVIEW", DW_MB_OK|DW_MB_ERROR, "PREPAINT");
1526 // return CDRF_NOTIFYITEMDRAW;
1527 return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW);
1528
1529 case CDDS_ITEMPREPAINT: //Before an item is drawn
1530 {
1531 dw_messagebox("LISTVIEW", DW_MB_OK|DW_MB_ERROR, "ITEMPREPAINT");
1532 return CDRF_NOTIFYSUBITEMDRAW;
1533 }
1534 break;
1535
1536 case CDDS_SUBITEM | CDDS_ITEMPREPAINT: //Before a subitem is drawn
1537 {
1538 dw_messagebox("LISTVIEW", DW_MB_OK|DW_MB_ERROR, "SUBITEM ITEMPREPAINT %d",lplvcd->iSubItem);
1539 switch(lplvcd->iSubItem)
1540 {
1541 case 0:
1542 {
1543 lplvcd->clrText = RGB(255,255,255);
1544 lplvcd->clrTextBk = RGB(240,55,23);
1545 return CDRF_NEWFONT;
1546 }
1547 break;
1548
1549 case 1:
1550 {
1551 lplvcd->clrText = RGB(255,255,0);
1552 lplvcd->clrTextBk = RGB(0,0,0);
1553 return CDRF_NEWFONT;
1554 }
1555 break;
1556
1557 case 2:
1558 {
1559 lplvcd->clrText = RGB(20,26,158);
1560 lplvcd->clrTextBk = RGB(200,200,10);
1561 return CDRF_NEWFONT;
1562 }
1563 break;
1564
1565 case 3:
1566 {
1567 lplvcd->clrText = RGB(12,15,46);
1568 lplvcd->clrTextBk = RGB(200,200,200);
1569 return CDRF_NEWFONT;
1570 }
1571 break;
1572
1573 case 4:
1574 {
1575 lplvcd->clrText = RGB(120,0,128);
1576 lplvcd->clrTextBk = RGB(20,200,200);
1577 return CDRF_NEWFONT;
1578 }
1579 break;
1580
1581 case 5:
1582 {
1583 lplvcd->clrText = RGB(255,255,255);
1584 lplvcd->clrTextBk = RGB(0,0,150);
1585 return CDRF_NEWFONT;
1586 }
1587 break;
1588
1589 }
1590
1591 }
1592 }
1593 return CDRF_DODEFAULT;
1594 }
1595 #endif
1596 1515
1597 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */ 1516 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */
1598 BOOL CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 1517 BOOL CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
1599 { 1518 {
1600 int result = -1, taskbar = FALSE; 1519 int result = -1, taskbar = FALSE;
1821 NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2; 1740 NMTREEVIEW FAR *tem=(NMTREEVIEW FAR *)mp2;
1822 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2; 1741 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2;
1823 char tmpbuf[100]; 1742 char tmpbuf[100];
1824 1743
1825 GetClassName(tem->hdr.hwndFrom, tmpbuf, 99); 1744 GetClassName(tem->hdr.hwndFrom, tmpbuf, 99);
1826 #ifdef DEBUG_NOTUSED
1827 if ( lem->hdr.code == NM_CUSTOMDRAW )
1828 dw_messagebox("NM_CUSTOMDRAW for (WM_NOTIFY)", DW_MB_OK|DW_MB_ERROR, "%s %d: Classname:%s",__FILE__,__LINE__,tmpbuf);
1829 #endif
1830 1745
1831 if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0) 1746 if(strnicmp(tmpbuf, WC_TREEVIEW, strlen(WC_TREEVIEW))==0)
1832 { 1747 {
1833 if(tem->hdr.code == TVN_SELCHANGED && tmp->message == TVN_SELCHANGED) 1748 if(tem->hdr.code == TVN_SELCHANGED && tmp->message == TVN_SELCHANGED)
1834 { 1749 {
1925 treeselectfunc(tmp->window, 0, (char *)lvi.lParam, tmp->data, 0); 1840 treeselectfunc(tmp->window, 0, (char *)lvi.lParam, tmp->data, 0);
1926 tmp = NULL; 1841 tmp = NULL;
1927 } 1842 }
1928 } 1843 }
1929 } 1844 }
1930 #ifdef DWDEBUG
1931 else if ( lem->hdr.code == NM_CUSTOMDRAW )
1932 {
1933 dw_messagebox("NM_CUSTOMDRAW for WC_LISTVIEW from _wndproc (WM_NOTIFY)", DW_MB_OK|DW_MB_ERROR, "Hello");
1934 SetWindowLong( hWnd, DWL_MSGRESULT, (LONG)ProcessCustomDraw(mp2) );
1935 return TRUE;
1936 }
1937 #endif
1938 } 1845 }
1939 } 1846 }
1940 else if(tmp->message == TCN_SELCHANGE) 1847 else if(tmp->message == TCN_SELCHANGE)
1941 { 1848 {
1942 NMHDR FAR *tem=(NMHDR FAR *)mp2; 1849 NMHDR FAR *tem=(NMHDR FAR *)mp2;
1956 int (*columnclickfunc)(HWND, int, void *) = tmp->signalfunction; 1863 int (*columnclickfunc)(HWND, int, void *) = tmp->signalfunction;
1957 result = columnclickfunc(tem->hdr.hwndFrom, tem->iSubItem, tmp->data); 1864 result = columnclickfunc(tem->hdr.hwndFrom, tem->iSubItem, tmp->data);
1958 tmp = NULL; 1865 tmp = NULL;
1959 } 1866 }
1960 } 1867 }
1961 #ifdef DEBUG_NOTUSED
1962 else
1963 {
1964 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2;
1965 char tmpbuf[100];
1966 GetClassName(lem->hdr.hwndFrom, tmpbuf, 99);
1967 if ( strnicmp( tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1 ) == 0 && lem->hdr.code == NM_CUSTOMDRAW )
1968 {
1969 dw_messagebox("NM_CUSTOMDRAW for WC_LISTVIEW(mp2) from _wndproc (WM_NOTIFY)", DW_MB_OK|DW_MB_ERROR, "Hello");
1970 SetWindowLong( hWnd, DWL_MSGRESULT, (LONG)ProcessCustomDraw(mp2) );
1971 tmp = NULL; //return TRUE;
1972 }
1973 }
1974 #endif
1975 } 1868 }
1976 break; 1869 break;
1977 case WM_COMMAND: 1870 case WM_COMMAND:
1978 { 1871 {
1979 int (*clickfunc)(HWND, void *) = tmp->signalfunction; 1872 int (*clickfunc)(HWND, void *) = tmp->signalfunction;
2152 if(num > -1 && array && array[num]) 2045 if(num > -1 && array && array[num])
2153 SetParent(array[num]->hwnd, tem->hwndFrom); 2046 SetParent(array[num]->hwnd, tem->hwndFrom);
2154 2047
2155 _resize_notebook_page(tem->hwndFrom, num); 2048 _resize_notebook_page(tem->hwndFrom, num);
2156 } 2049 }
2157 #ifdef DWDEBUG
2158 // code to attempt to support containers with different colours for each row - incomplete
2159 else
2160 {
2161 /*
2162 * Check if we have a click_default for this window
2163 */
2164 NMLISTVIEW FAR *lem=(NMLISTVIEW FAR *)mp2;
2165 char tmpbuf[100];
2166 GetClassName(lem->hdr.hwndFrom, tmpbuf, 99);
2167 if ( lem->hdr.code == NM_CUSTOMDRAW )
2168 dw_messagebox("NM_CUSTOMDRAW for (WM_NOTIFY)", DW_MB_OK|DW_MB_ERROR, "%s %d: Classname:%s is it %s",__FILE__,__LINE__,tmpbuf,WC_LISTVIEW);
2169 if ( strnicmp( tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW)+1 ) == 0 && lem->hdr.code == NM_CUSTOMDRAW )
2170 {
2171 dw_messagebox("NM_CUSTOMDRAW for WC_LISTVIEW(mp2) from _wndproc (WM_NOTIFY) - normal processing", DW_MB_OK|DW_MB_ERROR, "Hello");
2172 SetWindowLong( hWnd, DWL_MSGRESULT, (long)ProcessCustomDraw(mp2) );
2173 return TRUE;
2174 }
2175 }
2176 #endif
2177 } 2050 }
2178 break; 2051 break;
2179 case WM_HSCROLL: 2052 case WM_HSCROLL:
2180 case WM_VSCROLL: 2053 case WM_VSCROLL:
2181 { 2054 {
2809 return CallWindowProc(pOldProc, hWnd, msg, mp1, mp2); 2682 return CallWindowProc(pOldProc, hWnd, msg, mp1, mp2);
2810 } 2683 }
2811 return ret; 2684 return ret;
2812 } 2685 }
2813 2686
2687 /* Window procedure for container/listview */
2814 BOOL CALLBACK _containerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 2688 BOOL CALLBACK _containerwndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
2815 { 2689 {
2816 ContainerInfo *cinfo; 2690 ContainerInfo *cinfo;
2817 2691
2818 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA); 2692 cinfo = (ContainerInfo *)GetWindowLongPtr(hWnd, GWLP_USERDATA);
2822 case WM_COMMAND: 2696 case WM_COMMAND:
2823 case WM_NOTIFY: 2697 case WM_NOTIFY:
2824 case WM_MOUSEMOVE: 2698 case WM_MOUSEMOVE:
2825 _wndproc(hWnd, msg, mp1, mp2); 2699 _wndproc(hWnd, msg, mp1, mp2);
2826 break; 2700 break;
2701 case WM_PAINT:
2702 if(cinfo->cinfo.pOldProc && (cinfo->even != DW_RGB_TRANSPARENT || cinfo->odd != DW_RGB_TRANSPARENT))
2703 {
2704 RECT rectUpd, rectDestin, rect;
2705 POINT pt;
2706 int iItems, iTop, i;
2707 COLORREF c;
2708
2709 /* Load the default background color for the first pass */
2710 ListView_SetTextBkColor(hWnd, cinfo->cinfo.back != -1 ? cinfo->cinfo.back : ListView_GetBkColor(hWnd));
2711 /* get the rectangle to be updated */
2712 GetUpdateRect(hWnd, &rectUpd, FALSE);
2713 /* allow default processing first */
2714 CallWindowProc(cinfo->cinfo.pOldProc, hWnd, msg, 0, 0);
2715 /* set the row horizontal dimensions */
2716 SetRect(&rect, rectUpd.left, 0, rectUpd.right, 0);
2717 /* number of displayed rows */
2718 iItems = ListView_GetCountPerPage(hWnd);
2719 /* first visible row */
2720 iTop = ListView_GetTopIndex(hWnd);
2721
2722 ListView_GetItemPosition(hWnd, iTop, &pt);
2723 for(i=iTop; i<=(iTop+iItems)+1; i++)
2724 {
2725 /* set row vertical dimensions */
2726 rect.top = pt.y;
2727 ListView_GetItemPosition(hWnd, i, &pt);
2728 rect.bottom = pt.y;
2729 /* if row rectangle intersects update rectangle then it requires re-drawing */
2730 if(IntersectRect(&rectDestin, &rectUpd, &rect))
2731 {
2732 /* change text background colour accordingly */
2733 c = (i % 2) ? cinfo->even : cinfo->odd;
2734
2735 if(c != DW_RGB_TRANSPARENT)
2736 {
2737 ListView_SetTextBkColor(hWnd, c);
2738 /* invalidate the row rectangle then... */
2739 InvalidateRect(hWnd, &rect, FALSE);
2740 /* ...force default processing */
2741 CallWindowProc(cinfo->cinfo.pOldProc, hWnd, msg, 0, 0);
2742 }
2743 }
2744 }
2745 }
2746 break;
2827 case WM_LBUTTONDBLCLK: 2747 case WM_LBUTTONDBLCLK:
2828 case WM_CHAR: 2748 case WM_CHAR:
2829 { 2749 {
2830 LV_ITEM lvi; 2750 LV_ITEM lvi;
2831 int iItem; 2751 int iItem;
2922 } 2842 }
2923 } 2843 }
2924 break; 2844 break;
2925 } 2845 }
2926 2846
2927 if(!cinfo || !cinfo->pOldProc) 2847 if(!cinfo || !cinfo->cinfo.pOldProc)
2928 return DefWindowProc(hWnd, msg, mp1, mp2); 2848 return DefWindowProc(hWnd, msg, mp1, mp2);
2929 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); 2849 return CallWindowProc(cinfo->cinfo.pOldProc, hWnd, msg, mp1, mp2);
2930 } 2850 }
2931 2851
2932 BOOL CALLBACK _treewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2) 2852 BOOL CALLBACK _treewndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2)
2933 { 2853 {
2934 ContainerInfo *cinfo; 2854 ContainerInfo *cinfo;
2954 break; 2874 break;
2955 } 2875 }
2956 2876
2957 if(ret != TRUE) 2877 if(ret != TRUE)
2958 { 2878 {
2959 if(!cinfo || !cinfo->pOldProc) 2879 if(!cinfo || !cinfo->cinfo.pOldProc)
2960 return DefWindowProc(hWnd, msg, mp1, mp2); 2880 return DefWindowProc(hWnd, msg, mp1, mp2);
2961 return CallWindowProc(cinfo->pOldProc, hWnd, msg, mp1, mp2); 2881 return CallWindowProc(cinfo->cinfo.pOldProc, hWnd, msg, mp1, mp2);
2962 } 2882 }
2963 return ret; 2883 return ret;
2964 } 2884 }
2965 2885
2966 void _changebox(Box *thisbox, int percent, int type) 2886 void _changebox(Box *thisbox, int percent, int type)
4243 4163
4244 GetClassName(handle, tmpbuf, 99); 4164 GetClassName(handle, tmpbuf, 99);
4245 4165
4246 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0) 4166 if(strnicmp(tmpbuf, WC_LISTVIEW, strlen(WC_LISTVIEW))==0)
4247 { 4167 {
4248 fore = _internal_color(fore); 4168 cinfo->fore = fore = _internal_color(fore);
4249 back = _internal_color(back); 4169 cinfo->back = back = _internal_color(back);
4250 4170
4251 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore), 4171 ListView_SetTextColor(handle, RGB(DW_RED_VALUE(fore),
4252 DW_GREEN_VALUE(fore), 4172 DW_GREEN_VALUE(fore),
4253 DW_BLUE_VALUE(fore))); 4173 DW_BLUE_VALUE(fore)));
4254 ListView_SetTextBkColor(handle, RGB(DW_RED_VALUE(back), 4174 ListView_SetTextBkColor(handle, RGB(DW_RED_VALUE(back),
4992 { 4912 {
4993 DestroyWindow(tmp); 4913 DestroyWindow(tmp);
4994 return NULL; 4914 return NULL;
4995 } 4915 }
4996 4916
4997 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); 4917 cinfo->cinfo.pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc);
4998 cinfo->cinfo.fore = cinfo->cinfo.back = -1; 4918 cinfo->cinfo.fore = cinfo->cinfo.back = -1;
4919 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT;
4999 4920
5000 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 4921 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5001 dw_window_set_font(tmp, DefaultFont); 4922 dw_window_set_font(tmp, DefaultFont);
5002 /* If we are running XP or higher... */ 4923 /* If we are running XP or higher... */
5003 if(IS_XPPLUS) 4924 if(IS_XPPLUS)
5034 { 4955 {
5035 DestroyWindow(tmp); 4956 DestroyWindow(tmp);
5036 return NULL; 4957 return NULL;
5037 } 4958 }
5038 4959
5039 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); 4960 cinfo->cinfo.pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc);
5040 cinfo->cinfo.fore = cinfo->cinfo.back = -1; 4961 cinfo->cinfo.fore = cinfo->cinfo.back = -1;
4962 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT;
5041 4963
5042 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 4964 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5043 dw_window_set_font(tmp, DefaultFont); 4965 dw_window_set_font(tmp, DefaultFont);
5044 return tmp; 4966 return tmp;
5045 } 4967 }
5143 { 5065 {
5144 DestroyWindow(tmp); 5066 DestroyWindow(tmp);
5145 return NULL; 5067 return NULL;
5146 } 5068 }
5147 5069
5148 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc); 5070 cinfo->cinfo.pOldProc = (WNDPROC)SubclassWindow(tmp, _treewndproc);
5149 cinfo->cinfo.fore = cinfo->cinfo.back = -1; 5071 cinfo->cinfo.fore = cinfo->cinfo.back = -1;
5072 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT;
5150 5073
5151 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 5074 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5152 dw_window_set_font(tmp, DefaultFont); 5075 dw_window_set_font(tmp, DefaultFont);
5153 return tmp; 5076 return tmp;
5154 } 5077 }
5668 { 5591 {
5669 DestroyWindow(tmp); 5592 DestroyWindow(tmp);
5670 return NULL; 5593 return NULL;
5671 } 5594 }
5672 5595
5673 cinfo->cinfo.fore = -1; 5596 cinfo->cinfo.fore = cinfo->cinfo.back = -1;
5674 cinfo->cinfo.back = -1; 5597 cinfo->odd = cinfo->even = DW_RGB_TRANSPARENT;
5675 cinfo->pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc); 5598 cinfo->cinfo.pOldProc = (WNDPROC)SubclassWindow(tmp, _containerwndproc);
5676 5599
5677 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 5600 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
5678 dw_window_set_font(tmp, DefaultFont); 5601 dw_window_set_font(tmp, DefaultFont);
5679 return tmp; 5602 return tmp;
5680 } 5603 }
8028 * DW_RGB_TRANSPARENT will disable coloring rows. 7951 * DW_RGB_TRANSPARENT will disable coloring rows.
8029 * DW_CLR_DEFAULT will use the system default alternating row colors. 7952 * DW_CLR_DEFAULT will use the system default alternating row colors.
8030 */ 7953 */
8031 void API dw_container_set_row_bg(HWND handle, unsigned long oddcolor, unsigned long evencolor) 7954 void API dw_container_set_row_bg(HWND handle, unsigned long oddcolor, unsigned long evencolor)
8032 { 7955 {
7956 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
7957 COLORREF odd = _internal_color(oddcolor);
7958 COLORREF even = _internal_color(evencolor);
7959
7960 /* Drop out on error */
7961 if(!cinfo)
7962 return;
7963
7964 /* Create new brushes or remove if transparent */
7965 if(oddcolor != DW_RGB_TRANSPARENT)
7966 cinfo->odd = (oddcolor == DW_CLR_DEFAULT ? RGB(230, 230, 230) : odd);
7967 else
7968 cinfo->odd = oddcolor;
7969
7970 if(evencolor != DW_RGB_TRANSPARENT)
7971 cinfo->even = (evencolor == DW_CLR_DEFAULT ? DW_RGB_TRANSPARENT : even);
7972 else
7973 cinfo->even = evencolor;
8033 } 7974 }
8034 7975
8035 /* 7976 /*
8036 * Sets the width of a column in the container. 7977 * Sets the width of a column in the container.
8037 * Parameters: 7978 * Parameters: