listskin.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "main.h"
  2. #include "listskin.h"
  3. #include "scrollwnd.h"
  4. #include "../nu/CCVersion.h"
  5. #ifndef LVS_EX_DOUBLEBUFFER //this will work XP only
  6. #define LVS_EX_DOUBLEBUFFER 0x00010000
  7. #endif
  8. COLORREF Blender(COLORREF fg, COLORREF bg){
  9. return RGB((GetRValue(fg)+GetRValue(bg))/2,(GetGValue(fg)+GetGValue(bg))/2,(GetBValue(fg)+GetBValue(bg))/2);
  10. }
  11. //listview's wndproc
  12. static INT_PTR CALLBACK wndproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  13. {
  14. ListSkin *ls=(ListSkin *)(LONG_PTR)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  15. INT_PTR r=handleListViewHeaderMsgs(hwndDlg,
  16. ls->m_headerwnd,
  17. ls->m_listwnd,
  18. uMsg,
  19. wParam,
  20. lParam,
  21. ls->sortShow,
  22. ls->sortAscending,
  23. ls->sortIndex);
  24. if(r) return r;
  25. if (uMsg == WM_ENABLE)
  26. {
  27. // custom handling of this allows us to handle disabled listview controls correctly
  28. // so we don't have the part skinned / part OS colouring which happened before
  29. InvalidateRect(hwndDlg,0,1);
  30. ls->m_enabled = wParam;
  31. return 1;
  32. }
  33. if (uMsg == WM_ERASEBKGND)
  34. {
  35. //fg> removes the header's region from the erasebackground's hdc clipping region
  36. // so that they do not flicker when scrolling the list with the horizontal scrollbar
  37. // in transparency mode
  38. HDC dc = (HDC)wParam;
  39. RECT r;
  40. RECT hr;
  41. GetClientRect(hwndDlg, &r);
  42. GetClientRect(ListView_GetHeader(hwndDlg), &hr);
  43. RECT lr;
  44. SubtractRect(&lr, &r, &hr);
  45. HRGN rgn = CreateRectRgnIndirect(&lr);
  46. int rt = GetClipRgn(dc, rgn);
  47. if (rt == 0) {
  48. SelectClipRgn(dc, rgn);
  49. } else if (rt > 0) {
  50. HRGN trg = CreateRectRgnIndirect(&lr);
  51. HRGN res = CreateRectRgn(0,0,0,0);
  52. IntersectRgn(res, rgn, trg);
  53. SelectClipRgn(dc, res);
  54. DeleteRgn(res);
  55. DeleteRgn(trg);
  56. }
  57. DeleteRgn(rgn);
  58. }
  59. if (uMsg == WM_KEYUP && wParam == VK_RETURN)
  60. {
  61. NMHDR nmh=
  62. {
  63. ls->m_listwnd,
  64. GetDlgCtrlID(ls->m_listwnd),
  65. NM_RETURN,
  66. };
  67. SendMessage(ls->m_hwnd,WM_NOTIFY,0,(LPARAM)&nmh);
  68. return 0;
  69. }
  70. return CallWindowProc(ls->m_old_wndproc,hwndDlg,uMsg,wParam,lParam);
  71. }
  72. //dialog's wndproc
  73. static INT_PTR CALLBACK mainwndproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  74. {
  75. ListSkin *ls=(ListSkin *)(LONG_PTR)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  76. if(uMsg==WM_USER+0x411) return 0;//ls->m_changing_item_sel;
  77. if(uMsg==WM_NOTIFY)
  78. {
  79. LPNMCUSTOMDRAW lpnmcd = (NMCUSTOMDRAW *)lParam;
  80. //HWND listwnd=ls->m_listwnd;
  81. HWND listwnd=lpnmcd->hdr.hwndFrom;
  82. if(lpnmcd->hdr.code == NM_CUSTOMDRAW && lpnmcd->hdr.hwndFrom == listwnd)
  83. {
  84. LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
  85. NMCUSTOMDRAW &nmcd = lplvcd->nmcd;
  86. //static bool bHighlighted = false;
  87. switch(lplvcd->nmcd.dwDrawStage)
  88. {
  89. case CDDS_PREPAINT :
  90. return CDRF_NOTIFYITEMDRAW;
  91. // Modify item text and or background
  92. case CDDS_ITEMPREPAINT:
  93. {
  94. int iRow = (int)nmcd.dwItemSpec;
  95. bool bHighlighted = (ListView_GetItemState(listwnd, iRow, LVIS_SELECTED) != 0);
  96. if (bHighlighted)
  97. {
  98. if(GetFocus()==listwnd && ls->m_enabled)
  99. {
  100. lplvcd->clrText = WADlg_getColor(WADLG_SELBAR_FGCOLOR);
  101. lplvcd->clrTextBk = WADlg_getColor(WADLG_SELBAR_BGCOLOR);
  102. } else {
  103. lplvcd->clrText = (!ls->m_enabled?Blender(WADlg_getColor(WADLG_INACT_SELBAR_FGCOLOR),WADlg_getColor(WADLG_WNDBG)):WADlg_getColor(WADLG_INACT_SELBAR_FGCOLOR));
  104. if(ls->m_enabled)
  105. lplvcd->clrTextBk = WADlg_getColor(WADLG_INACT_SELBAR_BGCOLOR);
  106. else
  107. lplvcd->clrTextBk = WADlg_getColor(WADLG_ITEMBG);
  108. }
  109. }
  110. else
  111. {
  112. if(!ls->m_enabled)
  113. {
  114. lplvcd->clrText = Blender(WADlg_getColor(WADLG_INACT_SELBAR_FGCOLOR),WADlg_getColor(WADLG_WNDBG));
  115. lplvcd->clrTextBk = WADlg_getColor(WADLG_ITEMBG);
  116. }
  117. }
  118. // Turn off listview highlight otherwise it uses the system colors!
  119. //ls->m_changing_item_sel=1;
  120. //ListView_SetItemState(listwnd, iRow, 0, LVIS_SELECTED);
  121. lplvcd->nmcd.uItemState &= ~CDIS_SELECTED;
  122. return CDRF_DODEFAULT | CDRF_NOTIFYPOSTPAINT;
  123. }
  124. // Modify sub item text and/or background
  125. case CDDS_ITEMPOSTPAINT:
  126. {
  127. //if(bHighlighted)
  128. //{
  129. // int iRow = (int)nmcd.dwItemSpec;
  130. // Turn listview control's highlighting back on now that we have
  131. // drawn the row in the colors we want.
  132. //LockWindowUpdate(listwnd);
  133. // lplvcd->nmcd.uItemState |= CDIS_SELECTED;
  134. // ListView_SetItemState(listwnd, iRow, 0xff, LVIS_SELECTED);
  135. //ls->m_changing_item_sel=0;
  136. //LockWindowUpdate(NULL);
  137. //CT> now validate the window so it doesn't flicker
  138. //RECT r;
  139. //ListView_GetItemRect(listwnd,iRow,&r,LVIR_BOUNDS);
  140. //ValidateRect(listwnd,&r);
  141. //}
  142. }
  143. default:
  144. return CDRF_DODEFAULT;
  145. }
  146. }
  147. }
  148. return CallWindowProc(ls->m_old_mainwndproc,hwndDlg,uMsg,wParam,lParam);
  149. }
  150. //list header's wndproc
  151. static INT_PTR CALLBACK header_wndproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  152. {
  153. ListSkin *ls=(ListSkin *)(LONG_PTR)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  154. INT_PTR a=handleListViewHeaderPaintMsgs(ls->m_headerwnd,uMsg,wParam,lParam);
  155. if(a) return a;
  156. return CallWindowProc(ls->m_old_header_wndproc,hwndDlg,uMsg,wParam,lParam);
  157. }
  158. ListSkin::ListSkin(HWND hwnd)
  159. {
  160. m_hwnd=GetParent(hwnd);
  161. m_listwnd=hwnd;
  162. sortShow = FALSE;
  163. sortAscending = TRUE;
  164. sortIndex = 0;
  165. if (comctlVersion >= PACKVERSION(6,0))
  166. ListView_SetExtendedListViewStyleEx(m_listwnd, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
  167. m_headerwnd=ListView_GetHeader(hwnd);
  168. SetWindowLongPtr(hwnd,GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
  169. m_old_wndproc=(WNDPROC)(LONG_PTR)SetWindowLongPtr(hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)wndproc);
  170. SetWindowLongPtr(m_headerwnd,GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
  171. m_old_header_wndproc=(WNDPROC)(LONG_PTR)SetWindowLongPtr(m_headerwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)header_wndproc);
  172. m_scrollwnd=new ScrollWnd(hwnd, SCROLLBAR_LISTVIEW);
  173. m_old_mainwndproc=NULL;
  174. m_enabled = IsWindowEnabled(hwnd);
  175. //m_changing_item_sel=0;
  176. if(!GetWindowLongPtr(m_hwnd,GWLP_USERDATA))
  177. {
  178. SetWindowLongPtr(m_hwnd,GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
  179. m_old_mainwndproc=(WNDPROC)(LONG_PTR)SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)mainwndproc);
  180. }
  181. }
  182. ListSkin::~ListSkin()
  183. {
  184. delete m_scrollwnd;
  185. m_scrollwnd=0;
  186. SetWindowLongPtr(m_listwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)m_old_wndproc);
  187. SetWindowLongPtr(m_headerwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)m_old_header_wndproc);
  188. if(m_old_mainwndproc) SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)m_old_mainwndproc);
  189. }
  190. void ListSkin::updateScrollWnd()
  191. {
  192. m_scrollwnd->update();
  193. }
  194. void ListSkin::disableHorzScroll()
  195. {
  196. m_scrollwnd->disableHorzScroll();
  197. }