Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
10 KiB

  1. //////////////////////////////////////////////////////////////////
  2. // File : ivmisc.cpp
  3. // Purpose : PadListView control's ICON View function.
  4. // : Name is ICON View but it does not use ICON
  5. //
  6. // Copyright(c) 1991-1997, Microsoft Corp. All rights reserved
  7. //
  8. //////////////////////////////////////////////////////////////////
  9. #ifndef WIN32_LEAN_AND_MEAN
  10. #define WIN32_LEAN_AND_MEAN
  11. #endif
  12. #include <windows.h>
  13. #include "plv_.h"
  14. #include "plv.h"
  15. #include "dbg.h"
  16. #include "rvmisc.h"
  17. #include "strutil.h"
  18. #include "exgdiw.h"
  19. #ifdef UNDER_CE // Windows CE specific
  20. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  21. #endif // UNDER_CE
  22. inline INT RECT_GetWidth(LPRECT lpRc)
  23. {
  24. return lpRc->right - lpRc->left;
  25. }
  26. inline INT RECT_GetHeight(LPRECT lpRc)
  27. {
  28. return lpRc->bottom - lpRc->top;
  29. }
  30. INT RV_GetItemWidth(HWND hwnd)
  31. {
  32. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  33. return lpPlv->nRepItemWidth;
  34. }
  35. INT RV_GetItemHeight(HWND hwnd)
  36. {
  37. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  38. return lpPlv->nRepItemHeight;
  39. }
  40. INT RV_GetXMargin(HWND hwnd)
  41. {
  42. return XMARGIN;
  43. Unref(hwnd);
  44. }
  45. INT RV_GetYMargin(HWND hwnd)
  46. {
  47. //return YMARGIN;
  48. return 0;
  49. Unref(hwnd);
  50. }
  51. INT RV_GetHeaderHeight(LPPLVDATA lpPlvData)
  52. {
  53. static RECT rc;
  54. if(!lpPlvData->hwndHeader) {
  55. return 0;
  56. }
  57. GetClientRect(lpPlvData->hwndHeader, &rc);
  58. return rc.bottom - rc.top;
  59. }
  60. INT RV_GetDispWidth(HWND hwnd)
  61. {
  62. return RV_GetWidth(hwnd) - RV_GetXMargin(hwnd)*2;
  63. }
  64. INT RV_GetDispHeight(HWND hwnd)
  65. {
  66. return RV_GetHeight(hwnd) - RV_GetYMargin(hwnd)*2;
  67. }
  68. INT RV_GetWidth(HWND hwnd)
  69. {
  70. static RECT rc;
  71. GetClientRect(hwnd, &rc);
  72. return RECT_GetWidth(&rc);
  73. }
  74. INT RV_GetHeight(HWND hwnd)
  75. {
  76. static RECT rc;
  77. GetClientRect(hwnd, &rc);
  78. return RECT_GetHeight(&rc);
  79. }
  80. INT RV_GetRow(HWND hwnd)
  81. {
  82. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  83. return (RV_GetDispHeight(hwnd) - RV_GetHeaderHeight(lpPlv))/lpPlv->nRepItemHeight;
  84. }
  85. INT RV_GetColumn(LPPLVDATA lpPlvData)
  86. {
  87. if(!lpPlvData) {
  88. //OutputDebugString("RV_GetColumn: lpPlvData NULL\n");
  89. return 0;
  90. }
  91. if(!lpPlvData->hwndHeader) {
  92. //OutputDebugString("RV_GetColumn: hwndHeader NULL\n");
  93. return 0;
  94. }
  95. return Header_GetItemCount(lpPlvData->hwndHeader);
  96. }
  97. INT RV_GetCol(HWND hwnd)
  98. {
  99. //LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  100. return 1;
  101. UNREFERENCED_PARAMETER(hwnd);
  102. }
  103. INT RV_GetRowColumn(HWND hwnd, INT *pRow, INT *pCol)
  104. {
  105. *pRow = RV_GetRow(hwnd);
  106. *pCol = RV_GetCol(hwnd);
  107. return 0;
  108. }
  109. INT RV_GetMaxLine(HWND hwnd)
  110. {
  111. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  112. return lpPlv->iItemCount;
  113. }
  114. //////////////////////////////////////////////////////////////////
  115. // Function : RV_IndexFromPoint
  116. // Type : INT
  117. // Purpose : Get item index from PadListView point
  118. // Args :
  119. // : LPPLVDATA lpPlvData
  120. // : POINT pt // position of pad listview client.
  121. // Return : return pt's item index. if -1 error.
  122. // DATE :
  123. //////////////////////////////////////////////////////////////////
  124. INT RV_GetInfoFromPoint(LPPLVDATA lpPlvData, POINT pt, LPPLVINFO lpPlvInfo)
  125. {
  126. INT nRow = RV_GetRow(lpPlvData->hwndSelf);
  127. // get header control item count;
  128. INT nCol = RV_GetColumn(lpPlvData);
  129. if(nCol <=0 ) {
  130. return 0;
  131. }
  132. INT i, j, k;
  133. INT x, y;
  134. static RECT rc, rcHead;
  135. //INT nItemWidth = RV_GetItemWidth(lpPlvData->hwndSelf);
  136. INT nItemHeight = RV_GetItemHeight(lpPlvData->hwndSelf);
  137. GetClientRect(lpPlvData->hwndHeader, &rcHead);
  138. GetClientRect(lpPlvData->hwndSelf, &rc);
  139. INT yOffsetHead = rcHead.bottom - rcHead.top;
  140. static RECT rcItem;
  141. for(i = 0, j = lpPlvData->iCurTopIndex;
  142. i < nRow && j < lpPlvData->iItemCount;
  143. i++, j++) {
  144. x = RV_GetXMargin(lpPlvData->hwndSelf);
  145. y = RV_GetYMargin(lpPlvData->hwndSelf) + nItemHeight*i;
  146. INT xOffset = 0;
  147. HD_ITEM hdItem;
  148. for(k = 0; k < nCol; k++) {
  149. hdItem.mask = HDI_WIDTH;
  150. hdItem.fmt = 0;
  151. Header_GetItem(lpPlvData->hwndHeader, k, &hdItem);
  152. rcItem.left = xOffset;
  153. rcItem.right = rcItem.left + hdItem.cxy;
  154. rcItem.top = rc.top + yOffsetHead + y;
  155. rcItem.bottom= rcItem.top + nItemHeight;
  156. if(PtInRect(&rcItem, pt)) {
  157. if(lpPlvInfo) {
  158. ZeroMemory(lpPlvInfo, sizeof(PLVINFO));
  159. lpPlvInfo->code = 0; // don't know at this time.
  160. lpPlvInfo->index = j;
  161. lpPlvInfo->pt = pt;
  162. lpPlvInfo->itemRect = rcItem;
  163. lpPlvInfo->colIndex = k;
  164. lpPlvInfo->colItemRect = rcItem;
  165. }
  166. return j;
  167. }
  168. xOffset += hdItem.cxy;
  169. }
  170. }
  171. return -1;
  172. }
  173. INT RV_DrawItem(LPPLVDATA lpPlvData,
  174. HDC hDC,
  175. HDC hDCForBmp,
  176. POINT pt,
  177. INT colIndex,
  178. LPRECT lpRect,
  179. LPPLVITEM lpPlvItem)
  180. {
  181. if(!lpPlvItem->lpwstr) {
  182. return 0;
  183. }
  184. //INT edgeFlag = PLV_EDGE_NONE;
  185. INT sunken = 0;
  186. if(lpPlvItem->fmt == PLVFMT_TEXT) {
  187. SIZE size;
  188. //Dbg(("Call GetTextExtentPoint32W()\n"));
  189. //Dbg(("Length %d\n", StrlenW(lpPlvItem->lpwstr)));
  190. if(!ExGetTextExtentPoint32W(hDC,
  191. lpPlvItem->lpwstr,
  192. StrlenW(lpPlvItem->lpwstr),
  193. &size)) {
  194. return 0;
  195. }
  196. if(colIndex == 0) {
  197. RECT rcItem = *lpRect;
  198. rcItem.left += 2;
  199. rcItem.right = rcItem.left + size.cx+4;
  200. if(lpPlvData->iCapture == CAPTURE_LBUTTON) {
  201. #if 0
  202. Dbg(("RV_Draw Captureing\n"));
  203. Dbg(("pt [%d][%d] cap pt[%d][%d]drawrect l[%d] t[%d] r[%d] b[%d]\n",
  204. pt.x,
  205. pt.y,
  206. lpPlvData->ptCapture.x,
  207. lpPlvData->ptCapture.y,
  208. rcItem.left,
  209. rcItem.top,
  210. rcItem.right,
  211. rcItem.bottom));
  212. #endif
  213. if(PtInRect(&rcItem, lpPlvData->ptCapture) && PtInRect(&rcItem, pt)) {
  214. sunken = 1;
  215. DrawEdge(hDC, &rcItem, EDGE_SUNKEN, BF_SOFT | BF_RECT);
  216. }
  217. }
  218. else {
  219. if(PtInRect(&rcItem, pt)) {
  220. sunken = 0; //-1;
  221. DrawEdge(hDC, &rcItem, EDGE_RAISED, BF_SOFT | BF_RECT);
  222. }
  223. }
  224. }
  225. //Dbg(("Call ExtTextOut()\n"));
  226. ExExtTextOutW(hDC,
  227. lpRect->left + sunken + (colIndex == 0 ? 4 : 0),
  228. lpRect->top + (lpRect->bottom - lpRect->top - size.cy)/2 + sunken,
  229. ETO_CLIPPED,
  230. lpRect,
  231. lpPlvItem->lpwstr,
  232. StrlenW(lpPlvItem->lpwstr),
  233. NULL);
  234. }
  235. else if(lpPlvItem->fmt == PLVFMT_BITMAP) {
  236. //Dbg(("Draw Bitmap\n"));
  237. if(lpPlvItem->hBitmap) {
  238. BITMAP bitMap;
  239. HBITMAP hBitmapOld;
  240. GetObject(lpPlvItem->hBitmap, sizeof(bitMap), &bitMap);
  241. hBitmapOld = (HBITMAP)SelectObject(hDCForBmp, lpPlvItem->hBitmap);
  242. INT yOffset = 0;
  243. if(bitMap.bmHeight < (lpRect->bottom - lpRect->top)) {
  244. yOffset = ((lpRect->bottom - lpRect->top) - bitMap.bmHeight)/ 2;
  245. }
  246. BitBlt(hDC,
  247. lpRect->left,
  248. lpRect->top+yOffset,
  249. lpRect->right - lpRect->left, lpRect->bottom - lpRect->top,
  250. #ifndef UNDER_CE // CE Specific ??
  251. hDCForBmp, 0, 0, SRCAND);
  252. #else // UNDER_CE
  253. hDCForBmp, 0, 0, SRCINVERT);
  254. #endif // UNDER_CE
  255. SelectObject(hDCForBmp, hBitmapOld);
  256. //----------------------------------------------------------------
  257. //000531:Satori #1461
  258. //Don't call DeleteObject() here, call it from RV_DrawItem()'s caller.
  259. //repview.cpp:RepView_Paint();
  260. //----------------------------------------------------------------
  261. //DeleteObject(lpPlvItem->hBitmap);
  262. }
  263. }
  264. return 0;
  265. }
  266. INT RV_GetCurScrollPos(HWND hwnd)
  267. {
  268. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  269. return lpPlv->nCurScrollPos;
  270. }
  271. INT RV_SetCurScrollPos(HWND hwnd, INT nPos)
  272. {
  273. static SCROLLINFO scrInfo;
  274. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  275. INT nRow = RV_GetRow(hwnd);
  276. //INT nCol = RV_GetCol(hwnd);
  277. INT nMax = RV_GetMaxLine(hwnd);
  278. lpPlv->nCurScrollPos = nPos;
  279. lpPlv->iCurTopIndex = nPos;
  280. scrInfo.cbSize = sizeof(scrInfo);
  281. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  282. scrInfo.nMin = 0;
  283. scrInfo.nMax = nMax-1;
  284. scrInfo.nPage = nRow;
  285. scrInfo.nPos = nPos;
  286. scrInfo.nTrackPos = 0;
  287. //In normal case,
  288. //if (scrInfo.nMax - scrInfo.nMin + 1) <= scrInfo.nPage,
  289. // scroll bar is hidden. to prevent it,
  290. // in this case, set proper page, and DISABLE scrollbar.
  291. // Now we can show scroll bar always
  292. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  293. scrInfo.nMin = 0;
  294. scrInfo.nMax = 1;
  295. scrInfo.nPage = 1;
  296. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  297. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  298. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  299. #else // UNDER_CE
  300. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  301. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  302. #endif // UNDER_CE
  303. }
  304. else {
  305. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  306. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  307. #endif // UNDER_CE
  308. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  309. }
  310. //970810 toshiak. send scrolled notify.
  311. static PLVINFO plvInfo;
  312. ZeroMemory(&plvInfo, sizeof(plvInfo));
  313. plvInfo.code = PLVN_VSCROLLED;
  314. SendMessage(GetParent(lpPlv->hwndSelf),
  315. lpPlv->uMsg,
  316. (WPARAM)0,
  317. (LPARAM)&plvInfo);
  318. return nPos;
  319. }
  320. //////////////////////////////////////////////////////////////////
  321. // Function : RV_SetScrollInfo
  322. // Type : INT
  323. // Purpose :
  324. // Args :
  325. // : HWND hwnd
  326. // : INT nMin
  327. // : INT nMax
  328. // : INT nPage
  329. // : INT nPos
  330. // Return :
  331. // DATE :
  332. //////////////////////////////////////////////////////////////////
  333. INT RV_SetScrollInfo(HWND hwnd, INT nMin, INT nMax, INT nPage, INT nPos)
  334. {
  335. static SCROLLINFO scrInfo;
  336. scrInfo.cbSize = sizeof(scrInfo);
  337. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  338. scrInfo.nMin = nMin;
  339. scrInfo.nMax = nMax-1;
  340. scrInfo.nPage = nPage;
  341. scrInfo.nPos = nPos;
  342. scrInfo.nTrackPos = 0;
  343. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  344. scrInfo.nMin = 0;
  345. scrInfo.nMax = 1;
  346. scrInfo.nPage = 1;
  347. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  348. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  349. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  350. #else // UNDER_CE
  351. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  352. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  353. #endif // UNDER_CE
  354. }
  355. else {
  356. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  357. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  358. #endif // UNDER_CE
  359. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  360. }
  361. return 0;
  362. }
  363. INT RV_GetScrollTrackPos(HWND hwnd)
  364. {
  365. static SCROLLINFO scrInfo;
  366. scrInfo.cbSize = sizeof(scrInfo);
  367. scrInfo.fMask = SIF_ALL;
  368. GetScrollInfo(hwnd, SB_VERT, &scrInfo);
  369. return scrInfo.nTrackPos;
  370. }