comboskin.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #include "main.h"
  2. #include "comboskin.h"
  3. static int RectInRect(RECT *rect1, RECT *rect2)
  4. {
  5. // this has a bias towards true
  6. // this could probably be optimized a lot
  7. return ((rect1->top >= rect2->top && rect1->top <= rect2->bottom) ||
  8. (rect1->bottom >= rect2->top && rect1->bottom <= rect2->bottom) ||
  9. (rect2->top >= rect1->top && rect2->top <= rect1->bottom) ||
  10. (rect2->bottom >= rect1->top && rect2->bottom <= rect1->bottom)) // vertical intersect
  11. &&
  12. ((rect1->left >= rect2->left && rect1->left <= rect2->right) ||
  13. (rect1->right >= rect2->left && rect1->right <= rect2->right) ||
  14. (rect2->left >= rect1->left && rect2->left <= rect1->right) ||
  15. (rect2->right >= rect1->left && rect2->right <= rect1->right)) // horiz intersect
  16. ;
  17. }
  18. static INT_PTR CALLBACK wndproc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  19. {
  20. ComboSkin *cs=(ComboSkin *)(LONG_PTR)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  21. if (uMsg == WM_PAINT)
  22. {
  23. RECT r;
  24. GetClientRect(hwndDlg,&r);
  25. RECT ur;
  26. GetUpdateRect(hwndDlg,&ur,FALSE);
  27. if(RectInRect(&r,&ur)) //hmmm not sure about testing this, should probably use a backbuffer or something
  28. {
  29. //Fill with bg color
  30. HDC hdc=GetDC(hwndDlg);
  31. HBRUSH b=CreateSolidBrush(WADlg_getColor(WADLG_WNDBG));
  32. HBRUSH b2=CreateSolidBrush(WADlg_getColor(WADLG_HILITE)); //sunken
  33. //top line
  34. {
  35. RECT a={0,0,r.right-r.left,3};
  36. FillRect(hdc,&a,b);
  37. ValidateRect(hwndDlg,&a);
  38. }
  39. //bottom lines
  40. {
  41. RECT a={0,r.bottom-2,r.right-r.left,r.bottom};
  42. FillRect(hdc,&a,b);
  43. ValidateRect(hwndDlg,&a);
  44. }
  45. {
  46. //sunken part
  47. RECT a={0,r.bottom-3,r.right-r.left,r.bottom-2};
  48. FillRect(hdc,&a,b2);
  49. ValidateRect(hwndDlg,&a);
  50. }
  51. //left
  52. {
  53. RECT a={0,0,2,r.bottom-r.top};
  54. FillRect(hdc,&a,b);
  55. ValidateRect(hwndDlg,&a);
  56. }
  57. //right
  58. {
  59. RECT a={r.right-2,0,r.right,r.bottom-r.top};
  60. FillRect(hdc,&a,b);
  61. ValidateRect(hwndDlg,&a);
  62. }
  63. //paint the arrow
  64. HBITMAP bmp=WADlg_getBitmap();
  65. HDC hdcbmp = CreateCompatibleDC(hdc);
  66. SelectObject(hdcbmp,bmp);
  67. int pushed=0;
  68. if(GetAsyncKeyState(MK_LBUTTON) & 0x8000)
  69. {
  70. //check if in arrow down area
  71. POINT cursor;
  72. GetCursorPos(&cursor);
  73. ScreenToClient(hwndDlg,&cursor);
  74. if(cursor.x >= r.right-20 && cursor.x <= r.right)
  75. {
  76. pushed=1;
  77. }
  78. }
  79. int startx=14;
  80. int starty=31;
  81. if(pushed) startx+=28;
  82. int left=r.right-18;
  83. int top=r.top+4;
  84. StretchBlt(hdc,left,top,14,14,hdcbmp,startx,starty,14,14,SRCCOPY);
  85. DeleteDC(hdcbmp);
  86. RECT a={left,top,left+14,top+14};
  87. ValidateRect(hwndDlg,&a);
  88. //paint arrow borders
  89. {
  90. HBRUSH b=CreateSolidBrush(WADlg_getColor(WADLG_ITEMBG));
  91. RECT a={left,3,left+14,4};
  92. FillRect(hdc,&a,b);
  93. ValidateRect(hwndDlg,&a);
  94. RECT c={left,17,left+14,18};
  95. FillRect(hdc,&c,b);
  96. ValidateRect(hwndDlg,&c);
  97. RECT d={left+14,3,left+15,18};
  98. FillRect(hdc,&d,b);
  99. ValidateRect(hwndDlg,&d);
  100. RECT e={left+15,3,left+16,19};
  101. FillRect(hdc,&e,b2);
  102. ValidateRect(hwndDlg,&e);
  103. DeleteObject(b);
  104. }
  105. DeleteObject(b);
  106. DeleteObject(b2);
  107. ReleaseDC(hwndDlg,hdc);
  108. }
  109. }
  110. if(uMsg == WM_WINDOWPOSCHANGING)
  111. {
  112. //move it up 1 pixel so it's correctly centered
  113. WINDOWPOS *wp=(WINDOWPOS *)lParam;
  114. wp->y--;
  115. }
  116. if(uMsg == WM_KILLFOCUS || uMsg == WM_LBUTTONUP)
  117. {
  118. InvalidateRect(hwndDlg,NULL,TRUE);
  119. }
  120. return CallWindowProc(cs->m_old_wndproc,hwndDlg,uMsg,wParam,lParam);
  121. }
  122. ComboSkin::ComboSkin(HWND hwnd)
  123. {
  124. m_hwnd=hwnd;
  125. SetWindowLongPtr(m_hwnd,GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
  126. m_old_wndproc=(WNDPROC)(LONG_PTR)SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)wndproc);
  127. }
  128. ComboSkin::~ComboSkin()
  129. {
  130. SetWindowLongPtr(m_hwnd,GWLP_WNDPROC, (LONGX86)(LONG_PTR)m_old_wndproc);
  131. }