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.

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