Source code of Windows XP (NT5)
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.

287 lines
5.8 KiB

  1. /*++
  2. Copyright (C) 1993-1999 Microsoft Corporation
  3. Module Name:
  4. ipolylin.cpp
  5. Abstract:
  6. Implementation of the IPolyline10 interface exposed on the
  7. CPolyline object.
  8. --*/
  9. #include "polyline.h"
  10. #include "unkhlpr.h"
  11. /*
  12. * CImpIPolyline interface implementation
  13. */
  14. IMPLEMENT_CONTAINED_INTERFACE(CPolyline, CImpIPolyline)
  15. /*
  16. * CImpIPolyline::Init
  17. *
  18. * Purpose:
  19. * Instantiates a polyline window within a given parent. The
  20. * parent may be a main application window, could be an MDI child
  21. * window. We really do not care.
  22. *
  23. * Parameters:
  24. * hWndParent HWND of the parent of this window
  25. * pRect LPRECT that this window should occupy
  26. * dwStyle DWORD containing the window's style flags
  27. * uID UINT ID to associate with this window
  28. *
  29. * Return Value:
  30. * HRESULT NOERROR if successful, otherwise E_OUTOFMEMORY
  31. */
  32. STDMETHODIMP CImpIPolyline::Init(HWND hWndParent, LPRECT /* pRect */
  33. , DWORD /* dwStyle */, UINT /* uID */)
  34. {
  35. SCODE sc;
  36. BOOL stat;
  37. stat = m_pObj->m_pCtrl->Init(hWndParent);
  38. sc = (stat == TRUE) ? S_OK : E_OUTOFMEMORY;
  39. return ResultFromScode(sc);
  40. }
  41. /*
  42. * CImpIPolyline::New
  43. *
  44. * Purpose:
  45. * Cleans out and reinitializes the data to defaults.
  46. *
  47. * Parameters:
  48. * None
  49. *
  50. * Return Value:
  51. * HRESULT NOERROR always
  52. */
  53. STDMETHODIMP CImpIPolyline::New(void)
  54. {
  55. RECT rc;
  56. HWND hWnd;
  57. hWnd = m_pObj->m_pCtrl->Window();
  58. //Our rectangle is the size of our window's client area.
  59. if (hWnd)
  60. {
  61. GetClientRect(hWnd, &rc);
  62. //RECTTORECTS(rc, ppl->rc);
  63. }
  64. else
  65. {
  66. SetRect(&rc, 0, 0, 300, 200); //Something reasonable
  67. //RECTTORECTS(rc, ppl->rc);
  68. }
  69. //This is now conditional since we may not yet have a window.
  70. if (hWnd)
  71. {
  72. InvalidateRect(hWnd, NULL, TRUE);
  73. UpdateWindow(hWnd);
  74. m_pObj->m_fDirty=TRUE;
  75. }
  76. m_pObj->SendAdvise(OBJECTCODE_DATACHANGED);
  77. return NOERROR;
  78. }
  79. /*
  80. * CImpIPolyline::Undo
  81. *
  82. * Purpose:
  83. * Reverses previous actions in a Polyline.
  84. *
  85. * Parameters:
  86. * None
  87. *
  88. * Return Value:
  89. * HRESULT S_OK if we can Undo more, S_FALSE otherwise.
  90. */
  91. STDMETHODIMP CImpIPolyline::Undo(void)
  92. {
  93. return ResultFromScode(S_FALSE);
  94. }
  95. /*
  96. * CImpIPolyline::Window
  97. *
  98. * Purpose:
  99. * Returns the window handle associated with this polyline.
  100. *
  101. * Parameters:
  102. * phWnd HWND * in which to return the window handle.
  103. *
  104. * Return Value:
  105. * HRESULT NOERROR always.
  106. */
  107. STDMETHODIMP CImpIPolyline::Window(HWND *phWnd)
  108. {
  109. *phWnd = m_pObj->m_pCtrl->Window();
  110. return NOERROR;
  111. }
  112. /*
  113. * CImpIPolyline::RectGet
  114. *
  115. * Purpose:
  116. * Returns the rectangle of the Polyline in parent coordinates.
  117. *
  118. * Parameters:
  119. * pRect LPRECT in which to return the rectangle.
  120. *
  121. * Return Value:
  122. * HRESULT NOERROR always
  123. */
  124. STDMETHODIMP CImpIPolyline::RectGet(LPRECT pRect)
  125. {
  126. // RECT rc;
  127. // POINT pt;
  128. // I know this seems wrong, but it works.
  129. // Always return the last extent that the container gave us.
  130. // Then it will set our window to the correct size.
  131. *pRect = m_pObj->m_RectExt; // Return extent rect
  132. return NOERROR;
  133. /***********
  134. if (NULL==m_pObj->m_hWnd)
  135. {
  136. }
  137. //Retrieve the size of our rectangle in parent coordinates.
  138. GetWindowRect(m_pObj->m_hWnd, &rc);
  139. pt.x=rc.left;
  140. pt.y=rc.top;
  141. ScreenToClient(GetParent(m_pObj->m_hWnd), &pt);
  142. SetRect(pRect, pt.x, pt.y, pt.x+(rc.right-rc.left)
  143. , pt.y+(rc.bottom-rc.top));
  144. return NOERROR;
  145. **********/
  146. }
  147. /*
  148. * CImpIPolyline::SizeGet
  149. *
  150. * Purpose:
  151. * Retrieves the size of the Polyline in parent coordinates.
  152. *
  153. * Parameters:
  154. * pRect LPRECT in which to return the size. The right
  155. * and bottom fields will contain the dimensions.
  156. *
  157. * Return Value:
  158. * HRESULT NOERROR always
  159. */
  160. STDMETHODIMP CImpIPolyline::SizeGet(LPRECT pRect)
  161. {
  162. RectGet(pRect);
  163. return NOERROR;
  164. }
  165. /*
  166. * CImpIPolyline::RectSet
  167. *
  168. * Purpose:
  169. * Sets a new rectangle for the Polyline which sizes to fit.
  170. *
  171. * Parameters:
  172. * pRect LPRECT containing the new rectangle.
  173. * fNotify BOOL indicating if we're to notify anyone of
  174. * the change.
  175. *
  176. * Return Value:
  177. * HRESULT NOERROR always
  178. */
  179. STDMETHODIMP CImpIPolyline::RectSet(LPRECT pRect, BOOL fNotify)
  180. {
  181. UINT cx, cy;
  182. RECT rc;
  183. HWND hWnd;
  184. //Scale the points from our current size to the new size
  185. cx = pRect->right - pRect->left;
  186. cy = pRect->bottom - pRect->top;
  187. SetRect(&rc, 0, 0, cx, cy);
  188. hWnd = m_pObj->m_pCtrl->Window();
  189. if ( NULL != hWnd ) {
  190. SetWindowPos(hWnd, NULL, pRect->left, pRect->top, cx, cy, SWP_NOZORDER);
  191. InvalidateRect(hWnd, NULL, TRUE);
  192. }
  193. if (fNotify)
  194. m_pObj->m_fDirty = TRUE;
  195. return NOERROR;
  196. }
  197. /*
  198. * CImpIPolyline::SizeSet
  199. *
  200. * Purpose:
  201. * Sets a new size for the Polyline which sizes to fit.
  202. *
  203. * Parameters:
  204. * pRect LPRECT containing the new rectangle.
  205. * fNotify BOOL indicating if we're to notify anyone of
  206. * the change.
  207. *
  208. * Return Value:
  209. * HRESULT NOERROR always
  210. */
  211. STDMETHODIMP CImpIPolyline::SizeSet(LPRECT pRect, BOOL fNotify)
  212. {
  213. UINT cx, cy;
  214. HWND hWnd;
  215. //Scale the points from our current size to the new size
  216. cx=pRect->right-pRect->left;
  217. cy=pRect->bottom-pRect->top;
  218. hWnd = m_pObj->m_pCtrl->Window();
  219. if ( NULL != hWnd ) {
  220. SetWindowPos(hWnd, NULL, 0, 0, (UINT)cx, (UINT)cy, SWP_NOMOVE | SWP_NOZORDER);
  221. InvalidateRect(hWnd, NULL, TRUE);
  222. }
  223. if (fNotify)
  224. m_pObj->m_fDirty=TRUE;
  225. return NOERROR;
  226. }