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.

293 lines
7.5 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 "ivmisc.h"
  17. #ifdef UNDER_CE // Windows CE specific
  18. #include "stub_ce.h" // Windows CE stub for unsupported APIs
  19. #endif // UNDER_CE
  20. inline INT RECT_GetWidth(LPRECT lpRc)
  21. {
  22. return lpRc->right - lpRc->left;
  23. }
  24. inline INT RECT_GetHeight(LPRECT lpRc)
  25. {
  26. return lpRc->bottom - lpRc->top;
  27. }
  28. INT IV_GetItemWidth(HWND hwnd)
  29. {
  30. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  31. return lpPlv->nItemWidth;
  32. }
  33. INT IV_GetItemHeight(HWND hwnd)
  34. {
  35. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  36. return lpPlv->nItemHeight;
  37. }
  38. INT IV_GetXMargin(HWND hwnd)
  39. {
  40. //return XMARGIN;
  41. return 0;
  42. Unref(hwnd);
  43. }
  44. INT IV_GetYMargin(HWND hwnd)
  45. {
  46. //return YMARGIN;
  47. return 0;
  48. Unref(hwnd);
  49. }
  50. INT IV_GetDispWidth(HWND hwnd)
  51. {
  52. return IV_GetWidth(hwnd) - IV_GetXMargin(hwnd)*2;
  53. }
  54. INT IV_GetDispHeight(HWND hwnd)
  55. {
  56. return IV_GetHeight(hwnd) - IV_GetYMargin(hwnd)*2;
  57. }
  58. INT IV_GetWidth(HWND hwnd)
  59. {
  60. RECT rc;
  61. GetClientRect(hwnd, &rc);
  62. return RECT_GetWidth(&rc);
  63. }
  64. INT IV_GetHeight(HWND hwnd)
  65. {
  66. RECT rc;
  67. GetClientRect(hwnd, &rc);
  68. return RECT_GetHeight(&rc);
  69. }
  70. INT IV_GetRow(HWND hwnd)
  71. {
  72. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  73. return IV_GetDispHeight(hwnd)/lpPlv->nItemHeight;
  74. }
  75. INT IV_GetCol(HWND hwnd)
  76. {
  77. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  78. return IV_GetDispWidth(hwnd) / lpPlv->nItemWidth;
  79. }
  80. INT IV_GetRowColumn(HWND hwnd, INT *pRow, INT *pCol)
  81. {
  82. *pRow = IV_GetRow(hwnd);
  83. *pCol = IV_GetCol(hwnd);
  84. return 0;
  85. }
  86. //////////////////////////////////////////////////////////////////
  87. // Function : IV_GetMaxLine
  88. // Type : INT
  89. // Purpose :
  90. // Args :
  91. // : HWND hwnd
  92. // Return :
  93. // DATE :
  94. //////////////////////////////////////////////////////////////////
  95. INT IV_GetMaxLine(HWND hwnd)
  96. {
  97. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  98. INT nCol = IV_GetCol(hwnd);
  99. if(nCol <= 0) {
  100. return 0;
  101. }
  102. if(lpPlv->iItemCount > 0) {
  103. return (lpPlv->iItemCount - 1)/nCol + 1;
  104. }
  105. else {
  106. return 0;
  107. }
  108. }
  109. //////////////////////////////////////////////////////////////////
  110. // Function : IV_IndexFromPoint
  111. // Type : INT
  112. // Purpose : Get item index from PadListView point
  113. // Args :
  114. // : LPPLVDATA lpPlvData
  115. // : POINT pt // position of pad listview client.
  116. // Return : return pt's item index. if -1 error.
  117. // DATE :
  118. //////////////////////////////////////////////////////////////////
  119. INT IV_GetInfoFromPoint(LPPLVDATA lpPlvData, POINT pt, LPPLVINFO lpPlvInfo)
  120. {
  121. INT nRow = IV_GetRow(lpPlvData->hwndSelf);
  122. INT nCol = IV_GetCol(lpPlvData->hwndSelf);
  123. if(nCol <= 0) {
  124. return -1;
  125. }
  126. INT nMetricsCount;
  127. nMetricsCount = (nRow+1) * nCol;
  128. INT i, j;
  129. INT x, y;
  130. RECT rcChar, rc;
  131. INT nItemWidth = IV_GetItemWidth(lpPlvData->hwndSelf);
  132. INT nItemHeight = IV_GetItemHeight(lpPlvData->hwndSelf);
  133. GetClientRect(lpPlvData->hwndSelf, &rc);
  134. for(i = 0, j = lpPlvData->iCurIconTopIndex;
  135. i < nMetricsCount && j < lpPlvData->iItemCount;
  136. i++, j++) {
  137. x = IV_GetXMargin(lpPlvData->hwndSelf) + nItemWidth * (i % nCol);
  138. y = IV_GetYMargin(lpPlvData->hwndSelf) + nItemHeight * (i / nCol);
  139. rcChar.left = rc.left + x;
  140. rcChar.top = rc.top + y;
  141. rcChar.right = rcChar.left + nItemWidth;
  142. rcChar.bottom= rcChar.top + nItemHeight;
  143. if(PtInRect(&rcChar, pt)) {
  144. if(lpPlvInfo) {
  145. ZeroMemory(lpPlvInfo, sizeof(PLVINFO));
  146. lpPlvInfo->code = 0; // don't know at this time.
  147. lpPlvInfo->index = j;
  148. lpPlvInfo->pt = pt;
  149. lpPlvInfo->itemRect = rcChar;
  150. }
  151. return j;
  152. }
  153. }
  154. return -1;
  155. }
  156. //////////////////////////////////////////////////////////////////
  157. // Function : IV_GetCurScrollPos
  158. // Type : INT
  159. // Purpose :
  160. // Args :
  161. // : HWND hwnd
  162. // Return :
  163. // DATE : 970707 to use icon original pos (nCurIconScrollPos)
  164. //////////////////////////////////////////////////////////////////
  165. INT IV_GetCurScrollPos(HWND hwnd)
  166. {
  167. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  168. return lpPlv->nCurIconScrollPos;
  169. }
  170. INT IV_SetCurScrollPos(HWND hwnd, INT nPos)
  171. {
  172. static SCROLLINFO scrInfo;
  173. LPPLVDATA lpPlv = GetPlvDataFromHWND(hwnd);
  174. INT nRow = IV_GetRow(hwnd);
  175. INT nCol = IV_GetCol(hwnd);
  176. INT nMax = IV_GetMaxLine(hwnd);
  177. Dbg(("nPos[%d] nRow[%d] nCol[%d] nMax[%d]\n", nPos, nRow, nCol, nMax));
  178. lpPlv->nCurIconScrollPos = nPos;
  179. //----------------------------------------------------------------
  180. //important:
  181. //calc new cur top index
  182. //----------------------------------------------------------------
  183. lpPlv->iCurIconTopIndex = nCol * nPos; //changed 970707
  184. scrInfo.cbSize = sizeof(scrInfo);
  185. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  186. scrInfo.nMin = 0;
  187. scrInfo.nMax = nMax-1;
  188. scrInfo.nPage = nRow;
  189. scrInfo.nPos = nPos;
  190. scrInfo.nTrackPos = 0;
  191. //In normal case,
  192. //if (scrInfo.nMax - scrInfo.nMin + 1) <= scrInfo.nPage,
  193. // scroll bar is hidden. to prevent it,
  194. // in this case, set proper page, and DISABLE scrollbar.
  195. // Now we can show scroll bar always
  196. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  197. scrInfo.nMin = 0;
  198. scrInfo.nMax = 1;
  199. scrInfo.nPage = 1;
  200. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  201. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  202. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  203. #else // UNDER_CE
  204. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  205. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  206. #endif // UNDER_CE
  207. }
  208. else {
  209. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  210. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  211. #endif // UNDER_CE
  212. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  213. }
  214. //970810 toshiak. send scrolled notify.
  215. static PLVINFO plvInfo;
  216. ZeroMemory(&plvInfo, sizeof(plvInfo));
  217. plvInfo.code = PLVN_VSCROLLED;
  218. SendMessage(GetParent(lpPlv->hwndSelf),
  219. lpPlv->uMsg,
  220. (WPARAM)0,
  221. (LPARAM)&plvInfo);
  222. return nPos;
  223. }
  224. INT IV_SetScrollInfo(HWND hwnd, INT nMin, INT nMax, INT nPage, INT nPos)
  225. {
  226. static SCROLLINFO scrInfo;
  227. scrInfo.cbSize = sizeof(scrInfo);
  228. scrInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
  229. scrInfo.nMin = nMin;
  230. scrInfo.nMax = nMax-1;
  231. scrInfo.nPage = nPage;
  232. scrInfo.nPos = nPos;
  233. scrInfo.nTrackPos = 0;
  234. if((scrInfo.nMax - scrInfo.nMin +1) <= (INT)scrInfo.nPage) {
  235. scrInfo.nMin = 0;
  236. scrInfo.nMax = 1;
  237. scrInfo.nPage = 1;
  238. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  239. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  240. EnableScrollBar(hwnd, SB_VERT, ESB_DISABLE_BOTH);
  241. #else // UNDER_CE
  242. scrInfo.fMask |= SIF_DISABLENOSCROLL;
  243. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  244. #endif // UNDER_CE
  245. }
  246. else {
  247. #ifndef UNDER_CE // Windows CE does not support EnableScrollBar
  248. EnableScrollBar(hwnd, SB_VERT, ESB_ENABLE_BOTH);
  249. #endif // UNDER_CE
  250. SetScrollInfo(hwnd, SB_VERT, &scrInfo, TRUE);
  251. }
  252. return 0;
  253. }
  254. INT IV_GetScrollTrackPos(HWND hwnd)
  255. {
  256. static SCROLLINFO scrInfo;
  257. scrInfo.cbSize = sizeof(scrInfo);
  258. scrInfo.fMask = SIF_ALL;
  259. GetScrollInfo(hwnd, SB_VERT, &scrInfo);
  260. return scrInfo.nTrackPos;
  261. }