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.

361 lines
9.9 KiB

  1. // srvritem.cpp : implementation of the CPBSrvrItem class
  2. //
  3. #include "stdafx.h"
  4. #include "pbrush.h"
  5. #include "pbrusdoc.h"
  6. #include "pbrusfrm.h"
  7. #include "pbrusvw.h"
  8. #include "srvritem.h"
  9. #include "bmobject.h"
  10. #include "docking.h"
  11. #include "minifwnd.h"
  12. #include "imgwnd.h"
  13. #include "imgsuprt.h"
  14. #include "imgcolor.h"
  15. #include "tracker.h"
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static CHAR BASED_CODE THIS_FILE[] = __FILE__;
  19. #endif
  20. IMPLEMENT_DYNAMIC(CPBSrvrItem, COleServerItem)
  21. #include "memtrace.h"
  22. /***************************************************************************/
  23. // CPBSrvrItem implementation
  24. CPBSrvrItem::CPBSrvrItem( CPBDoc* pContainerDoc, CBitmapObj* pBM )
  25. : COleServerItem( pContainerDoc, TRUE )
  26. {
  27. if (pBM)
  28. {
  29. m_pBitmapObj = pBM;
  30. }
  31. else
  32. {
  33. pBM = pContainerDoc->m_pBitmapObj;
  34. m_pBitmapObj = NULL;
  35. }
  36. if (pBM && pBM->m_pImg)
  37. {
  38. COleDataSource* oleDataSrc = GetDataSource();
  39. // support CF_DIB format
  40. oleDataSrc->DelayRenderFileData( CF_DIB );
  41. oleDataSrc->DelayRenderData( CF_BITMAP );
  42. if (pBM->m_pImg->m_pPalette != NULL)
  43. {
  44. oleDataSrc->DelayRenderData( CF_PALETTE );
  45. }
  46. }
  47. }
  48. /***************************************************************************/
  49. CPBSrvrItem::~CPBSrvrItem()
  50. {
  51. // TODO: add cleanup code here
  52. if (m_pBitmapObj)
  53. {
  54. delete m_pBitmapObj;
  55. }
  56. }
  57. /***************************************************************************/
  58. void CPBSrvrItem::Serialize(CArchive& ar)
  59. {
  60. // CPBSrvrItem::Serialize will be called by the framework if
  61. // the item is copied to the clipboard. This can happen automatically
  62. // through the OLE callback OnGetClipboardData. A good default for
  63. // the embedded item is simply to delegate to the document's Serialize
  64. // function. If you support links, then you will want to serialize
  65. // just a portion of the document.
  66. // IsLinkedItem always returns TRUE even though we don't support links,
  67. // so I am just removing the check
  68. // if (! IsLinkedItem())
  69. {
  70. CPBDoc* pDoc = GetDocument();
  71. ASSERT_VALID(pDoc);
  72. CBitmapObj* pBMCur = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObj;
  73. CBitmapObj* pBMNew = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObjNew;
  74. pDoc->SerializeBitmap( ar, pBMCur, pBMNew, TRUE );
  75. }
  76. }
  77. /***************************************************************************/
  78. BOOL CPBSrvrItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
  79. {
  80. // Most applications, like this one, only handle drawing the content
  81. // aspect of the item. If you wish to support other aspects, such
  82. // as DVASPECT_THUMBNAIL (by overriding OnDrawEx), then this
  83. // implementation of OnGetExtent should be modified to handle the
  84. // additional aspect(s).
  85. if (dwDrawAspect != DVASPECT_CONTENT)
  86. return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
  87. // CPBSrvrItem::OnGetExtent is called to get the extent in
  88. // HIMETRIC units of the entire item. The default implementation
  89. // here simply returns a hard-coded number of units.
  90. CPBDoc* pDoc = GetDocument();
  91. ASSERT_VALID( pDoc );
  92. CBitmapObj* pBM = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObj;
  93. if (pBM != NULL
  94. && pBM->m_pImg != NULL)
  95. {
  96. //
  97. // What was the padding for?
  98. //
  99. rSize.cx = pBM->m_pImg->cxWidth ;// + GetSystemMetrics( SM_CXBORDER ) + CTracker::HANDLE_SIZE * 2;
  100. rSize.cy = pBM->m_pImg->cyHeight;// + GetSystemMetrics( SM_CYBORDER ) + CTracker::HANDLE_SIZE * 2;
  101. CDC* pDC = CDC::FromHandle( pBM->m_pImg->hDC );
  102. if (pDC != NULL)
  103. {
  104. pDC->DPtoHIMETRIC( &rSize );
  105. }
  106. else /* punt */
  107. {
  108. rSize.cx = (int)(((long)rSize.cx * 10000L) / (long)theApp.ScreenDeviceInfo.ixPelsPerDM);
  109. rSize.cy = (int)(((long)rSize.cy * 10000L) / (long)theApp.ScreenDeviceInfo.iyPelsPerDM);
  110. }
  111. }
  112. else
  113. rSize = CSize( 3000, 3000 );
  114. return TRUE;
  115. }
  116. /***************************************************************************/
  117. BOOL CPBSrvrItem::OnSetExtent( DVASPECT nDrawAspect, const CSize& size )
  118. {
  119. TRACE( TEXT("MSPaint OnSetExtent %d %d\n"), size.cx, size.cy );
  120. return COleServerItem::OnSetExtent( nDrawAspect, size );
  121. }
  122. /***************************************************************************/
  123. void CPBSrvrItem::OnOpen()
  124. {
  125. CPBDoc* pDoc = (CPBDoc*)GetDocument();
  126. if (theApp.m_bLinked)
  127. {
  128. theApp.m_bHidden = FALSE;
  129. if (g_pDragBrushWnd != NULL)
  130. HideBrush();
  131. g_pDragBrushWnd = NULL;
  132. g_pMouseImgWnd = NULL;
  133. fDraggingBrush = FALSE;
  134. POSITION pos = pDoc->GetFirstViewPosition();
  135. CPBView* pView = (CPBView*)(pDoc->GetNextView( pos ));
  136. if (pView != NULL)
  137. {
  138. pView->SetTools();
  139. }
  140. }
  141. COleServerItem::OnOpen();
  142. }
  143. /***************************************************************************/
  144. void CPBSrvrItem::OnShow()
  145. {
  146. theApp.m_bHidden = FALSE;
  147. COleServerItem::OnShow();
  148. }
  149. /***************************************************************************/
  150. void CPBSrvrItem::OnHide()
  151. {
  152. theApp.m_bHidden = TRUE;
  153. g_pMouseImgWnd = NULL;
  154. if (g_pDragBrushWnd != NULL)
  155. HideBrush();
  156. COleServerItem::OnHide();
  157. }
  158. /***************************************************************************/
  159. BOOL CPBSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
  160. {
  161. CPBDoc* pDoc = GetDocument();
  162. ASSERT_VALID(pDoc);
  163. CBitmapObj* pBM = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObj;
  164. if (pBM != NULL)
  165. {
  166. CDC* pDCBitmap = CDC::FromHandle( pBM->m_pImg->hDC );
  167. if (pDCBitmap != NULL)
  168. {
  169. CSize size( pBM->m_pImg->cxWidth,
  170. pBM->m_pImg->cyHeight );
  171. size.cy = -size.cy;
  172. pDC->SetMapMode ( MM_ANISOTROPIC );
  173. pDC->SetWindowExt( size );
  174. pDC->SetWindowOrg( 0, 0 );
  175. CPalette* ppalOld = NULL;
  176. if (pBM->m_pImg->m_pPalette != NULL)
  177. {
  178. ppalOld = pDC->SelectPalette( pBM->m_pImg->m_pPalette, FALSE ); // Background ??
  179. pDC->RealizePalette();
  180. }
  181. pDC->StretchBlt( 0, 0, size.cx, size.cy, pDCBitmap,
  182. 0, 0, pBM->m_pImg->cxWidth,
  183. pBM->m_pImg->cyHeight, SRCCOPY );
  184. if (pBM->m_pImg->m_pPalette != NULL)
  185. pDC->SelectPalette( ppalOld, FALSE ); // Background ??
  186. }
  187. }
  188. return TRUE;
  189. }
  190. /***************************************************************************/
  191. COleDataSource* CPBSrvrItem::OnGetClipboardData( BOOL bIncludeLink,
  192. CPoint* pptOffset,
  193. CSize *pSize )
  194. {
  195. ASSERT_VALID( this );
  196. COleDataSource* pDataSource = new COleDataSource;
  197. TRY
  198. {
  199. GetClipboardData( pDataSource, bIncludeLink, pptOffset, pSize );
  200. }
  201. CATCH_ALL( e )
  202. {
  203. delete pDataSource;
  204. THROW_LAST();
  205. }
  206. END_CATCH_ALL
  207. ASSERT_VALID( pDataSource );
  208. return pDataSource;
  209. }
  210. /***************************************************************************/
  211. BOOL CPBSrvrItem::OnRenderGlobalData( LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal )
  212. {
  213. ASSERT( lpFormatEtc != NULL );
  214. BOOL bResult = FALSE;
  215. CPBDoc* pDoc = GetDocument();
  216. ASSERT_VALID( pDoc );
  217. CBitmapObj* pBM = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObj;
  218. if ((lpFormatEtc->cfFormat == CF_BITMAP
  219. || lpFormatEtc->cfFormat == CF_PALETTE)
  220. && pBM != NULL)
  221. {
  222. if (lpFormatEtc->cfFormat == CF_BITMAP)
  223. {
  224. }
  225. else // CF_PALETTE
  226. {
  227. }
  228. }
  229. else
  230. bResult = COleServerItem::OnRenderGlobalData( lpFormatEtc, phGlobal );
  231. return bResult;
  232. }
  233. /***************************************************************************/
  234. BOOL CPBSrvrItem::OnRenderFileData( LPFORMATETC lpFormatEtc, CFile* pFile )
  235. {
  236. ASSERT( lpFormatEtc != NULL );
  237. BOOL bResult = FALSE;
  238. CPBDoc* pDoc = GetDocument();
  239. ASSERT_VALID( pDoc );
  240. CBitmapObj* pBM = m_pBitmapObj ? m_pBitmapObj : pDoc->m_pBitmapObj;
  241. if (lpFormatEtc->cfFormat == CF_DIB && pBM != NULL)
  242. {
  243. TRY
  244. {
  245. // save as dib
  246. pBM->SaveResource( FALSE );
  247. pBM->WriteResource( pFile, CBitmapObj::rtDIB );
  248. bResult = TRUE;
  249. }
  250. CATCH( CFileException, ex )
  251. {
  252. theApp.SetFileError( IDS_ERROR_SAVE, ex->m_cause );
  253. return FALSE;
  254. }
  255. END_CATCH
  256. }
  257. else
  258. bResult = COleServerItem::OnRenderFileData( lpFormatEtc, pFile );
  259. return bResult;
  260. }
  261. /***************************************************************************/
  262. // CPBSrvrItem diagnostics
  263. #ifdef _DEBUG
  264. void CPBSrvrItem::AssertValid() const
  265. {
  266. COleServerItem::AssertValid();
  267. }
  268. /***************************************************************************/
  269. void CPBSrvrItem::Dump(CDumpContext& dc) const
  270. {
  271. COleServerItem::Dump(dc);
  272. }
  273. #endif
  274. /***************************************************************************/