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.

1251 lines
34 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddsurface7obj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ddSurfaceObj.cpp : Implementation of CDirectApp and DLL registration.
  11. #include "stdafx.h"
  12. #include "stdio.h"
  13. #include "Direct.h"
  14. #include "dms.h"
  15. #include "dDraw7Obj.h"
  16. #include "ddClipperObj.h"
  17. #include "ddGammaControlObj.h"
  18. #include "ddColorControlObj.h"
  19. #include "ddSurface7Obj.h"
  20. #include "ddPaletteObj.h"
  21. #include "DDEnumSurfacesObj.h"
  22. C_dxj_DirectDrawSurface7Object::C_dxj_DirectDrawSurface7Object(){
  23. m__dxj_DirectDrawSurface7= NULL;
  24. parent = NULL;
  25. pinterface = NULL;
  26. nextobj = g_dxj_DirectDrawSurface7;
  27. creationid = ++g_creationcount;
  28. DPF1(1,"Constructor Creation Surface7 [%d] \n",g_creationcount);
  29. g_dxj_DirectDrawSurface7 = (void *)this;
  30. _dxj_DirectDrawSurface7Lock=NULL;
  31. m_bLocked=FALSE;
  32. m_drawStyle = 0; //solid lines are default for DDraw
  33. m_fillStyle = 1; //transparent fill is default since DDRaw has no selected Brush
  34. m_fFontTransparent = TRUE;
  35. m_fFillTransparent = TRUE;
  36. m_fFillSolid=TRUE;
  37. m_foreColor = 0; //black is the default color.
  38. m_fontBackColor=-1; //white is the default fill color
  39. m_drawWidth = 1;
  40. m_hPen = NULL;
  41. m_hBrush = NULL;
  42. m_hFont=NULL;
  43. m_pIFont=NULL;
  44. m_bLockedArray=FALSE;
  45. m_ppSA=NULL;
  46. setFillStyle(1); //transparent
  47. }
  48. DWORD C_dxj_DirectDrawSurface7Object::InternalAddRef(){
  49. DWORD i;
  50. i=CComObjectRoot::InternalAddRef();
  51. DPF2(1,"Surf7 [%d] AddRef %d \n",creationid,i);
  52. return i;
  53. }
  54. DWORD C_dxj_DirectDrawSurface7Object::InternalRelease(){
  55. DWORD i;
  56. i=CComObjectRoot::InternalRelease();
  57. DPF2(1,"Surf7 [%d] Release %d \n",creationid,i);
  58. return i;
  59. }
  60. C_dxj_DirectDrawSurface7Object::~C_dxj_DirectDrawSurface7Object()
  61. {
  62. C_dxj_DirectDrawSurface7Object *prev=NULL;
  63. for(C_dxj_DirectDrawSurface7Object *ptr=(C_dxj_DirectDrawSurface7Object *)g_dxj_DirectDrawSurface7; ptr; ptr=(C_dxj_DirectDrawSurface7Object *)ptr->nextobj)
  64. {
  65. if(ptr == this)
  66. {
  67. if(prev)
  68. prev->nextobj = ptr->nextobj;
  69. else
  70. g_dxj_DirectDrawSurface7 = (void*)ptr->nextobj;
  71. break;
  72. }
  73. prev = ptr;
  74. }
  75. if(m__dxj_DirectDrawSurface7){
  76. int count = IUNK(m__dxj_DirectDrawSurface7)->Release();
  77. DPF1(1,"DirectX IDirectDrawSurface7 Ref count [%d]",count);
  78. if(count==0) m__dxj_DirectDrawSurface7 = NULL;
  79. }
  80. if(parent) IUNK(parent)->Release();
  81. if (m_hFont) DeleteObject (m_hFont);
  82. if (m_hPen) DeleteObject (m_hPen);
  83. if (m_hBrush) DeleteObject (m_hBrush);
  84. if (m_pIFont) m_pIFont->Release();
  85. }
  86. GETSET_OBJECT(_dxj_DirectDrawSurface7);
  87. RETURN_NEW_ITEM_R(_dxj_DirectDrawSurface7, getPalette, GetPalette, _dxj_DirectDrawPalette)
  88. GET_DIRECT_R(_dxj_DirectDrawSurface7, isLost, IsLost, long)
  89. GET_DIRECT1_R(_dxj_DirectDrawSurface7, getBltStatus, GetBltStatus, long, long)
  90. GET_DIRECT1_R(_dxj_DirectDrawSurface7, getFlipStatus, GetFlipStatus, long, long)
  91. STDMETHODIMP C_dxj_DirectDrawSurface7Object::addAttachedSurface(I_dxj_DirectDrawSurface7 *s3)
  92. {
  93. HRESULT hr;
  94. IDirectDrawSurface7 *realsurf=NULL;
  95. if (s3) s3->InternalGetObject((IUnknown**)&realsurf);
  96. if (m__dxj_DirectDrawSurface7 == NULL) return E_FAIL;
  97. hr=m__dxj_DirectDrawSurface7->AddAttachedSurface(realsurf);
  98. return hr;
  99. }
  100. //PASS_THROUGH1_R(_dxj_DirectDrawSurface7, pageLock, PageLock, long)
  101. //PASS_THROUGH1_R(_dxj_DirectDrawSurface7, pageUnlock, PageUnlock,long)
  102. PASS_THROUGH_CAST_1_R(_dxj_DirectDrawSurface7,releaseDC,ReleaseDC,long,(HDC ))
  103. PASS_THROUGH_CAST_2_R(_dxj_DirectDrawSurface7,setColorKey,SetColorKey,long,(long),DDColorKey *,(LPDDCOLORKEY))
  104. PASS_THROUGH_CAST_2_R(_dxj_DirectDrawSurface7,getColorKey,GetColorKey,long,(long),DDColorKey *,(LPDDCOLORKEY))
  105. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getDC(long *hdc)
  106. {
  107. return m__dxj_DirectDrawSurface7->GetDC((HDC*)hdc);
  108. }
  109. STDMETHODIMP C_dxj_DirectDrawSurface7Object::lock( Rect *r, DDSurfaceDesc2 *desc, long flags, Handle hnd)
  110. {
  111. if (m_bLocked) return E_FAIL;
  112. HRESULT hr;
  113. CopyInDDSurfaceDesc2(&m_ddsd,desc);
  114. hr = m__dxj_DirectDrawSurface7->Lock(NULL,&m_ddsd,(DWORD)flags,(void*)hnd);
  115. if FAILED(hr) return hr;
  116. CopyOutDDSurfaceDesc2(desc,&m_ddsd);
  117. m_bLocked=TRUE;
  118. m_nPixelBytes=m_ddsd.ddpfPixelFormat.dwRGBBitCount/8;
  119. return hr;
  120. }
  121. STDMETHODIMP C_dxj_DirectDrawSurface7Object::unlock( Rect *r)
  122. {
  123. HRESULT hr;
  124. if (m_bLockedArray) {
  125. *m_ppSA=NULL;
  126. m_bLockedArray=FALSE;
  127. }
  128. hr = m__dxj_DirectDrawSurface7->Unlock(NULL);
  129. if FAILED(hr) return hr ;
  130. m_bLocked=FALSE;
  131. return hr;
  132. }
  133. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setLockedPixel( int x, int y, long col)
  134. {
  135. if (!m_bLocked) return E_FAIL;
  136. //__try {
  137. char *pByte= (char*)((char*)m_ddsd.lpSurface+x*m_nPixelBytes+y*m_ddsd.lPitch);
  138. if (m_nPixelBytes==2){
  139. *((WORD*)pByte)=(WORD)col;
  140. }
  141. else if (m_nPixelBytes==4){
  142. *((DWORD*)pByte)=(DWORD)col;
  143. }
  144. else if (m_nPixelBytes==1){
  145. *pByte=(Byte)col;
  146. }
  147. else if (m_nPixelBytes==3){
  148. *(pByte)= (char)(col & 0xFF);
  149. pByte++;
  150. *(pByte)= (char)((col & 0xFF00)>>8);
  151. pByte++;
  152. *(pByte)= (char)((col & 0xFF0000)>>16);
  153. }
  154. else{
  155. return E_FAIL;
  156. }
  157. //}
  158. //__except(1,1){
  159. // return E_INVALIDARG;
  160. //}
  161. return S_OK;
  162. }
  163. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getLockedPixel( int x, int y, long *col)
  164. {
  165. //__try {
  166. char *pByte= (char*)((char*)m_ddsd.lpSurface+x*m_nPixelBytes+y*m_ddsd.lPitch);
  167. if (m_nPixelBytes==2){
  168. *col=(long) *((WORD*)pByte);
  169. }
  170. else if (m_nPixelBytes==4){
  171. *col=(long) *((DWORD*)pByte);
  172. }
  173. else if (m_nPixelBytes==3){
  174. *col=(long) (*((DWORD*)pByte))& 0x00FFFFFF;
  175. }
  176. else if (m_nPixelBytes==1){
  177. *col=(long) *((long*)pByte);
  178. }
  179. else{
  180. return E_FAIL;
  181. }
  182. //}
  183. //__except(1,1){
  184. // return E_INVALIDARG;
  185. //}
  186. return S_OK;
  187. }
  188. /////////////////////////////////////////////////////////////////////////////
  189. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getClipper( I_dxj_DirectDrawClipper **val)
  190. {
  191. LPDIRECTDRAWCLIPPER ddc;
  192. HRESULT hr=DD_OK;
  193. if( (hr=m__dxj_DirectDrawSurface7->GetClipper( &ddc)) != DD_OK )
  194. return hr;
  195. INTERNAL_CREATE(_dxj_DirectDrawClipper, ddc, val);
  196. return S_OK;
  197. }
  198. /////////////////////////////////////////////////////////////////////////////
  199. // this is NOT the normal Blt, that is BltFx in our interface
  200. //
  201. STDMETHODIMP C_dxj_DirectDrawSurface7Object::blt( Rect *pDest, I_dxj_DirectDrawSurface7 *ddS, Rect *pSrc, long flags, long *status)
  202. {
  203. LPDIRECTDRAWSURFACE7 lpdds = NULL;
  204. LPRECT prcDest=(LPRECT)pDest;
  205. LPRECT prcSrc =(LPRECT)pSrc;
  206. if (!ddS ) return E_INVALIDARG;
  207. ddS->InternalGetObject((IUnknown **)(&lpdds));
  208. //allow user to pass uninitialed structure down to represent bitting to the whole surface
  209. if ((prcDest) && (!prcDest->left) && (!prcDest->right) && (!prcDest->bottom) && (!prcDest->top))
  210. prcDest=NULL;
  211. //allow user to pass uninitialed structure down to represent bitting from the whole surface
  212. if ((prcSrc) && (!prcSrc->left) && (!prcSrc->right) && (!prcSrc->bottom) && (!prcSrc->top))
  213. prcSrc=NULL;
  214. //__try {
  215. *status = m__dxj_DirectDrawSurface7->Blt(prcDest, lpdds, prcSrc, flags, NULL);
  216. //}
  217. //__except(1,1){
  218. // return E_INVALIDARG;
  219. //}
  220. return S_OK;
  221. }
  222. STDMETHODIMP C_dxj_DirectDrawSurface7Object::bltFx(Rect *pDest, I_dxj_DirectDrawSurface7 *ddS, Rect *pSrc, long flags, DDBltFx *bltfx, long *status )
  223. {
  224. LPRECT prcDest=(LPRECT)pDest;
  225. LPRECT prcSrc= (LPRECT)pSrc;
  226. LPDIRECTDRAWSURFACE7 lpdds = NULL;
  227. if ( !ddS ) return E_INVALIDARG;
  228. ddS->InternalGetObject((IUnknown **)(&lpdds));
  229. if(bltfx) bltfx->lSize = sizeof(DDBLTFX);
  230. //allow user to pass uninitialed structure down to represent bitting to the whole surface
  231. if ((prcDest) && (!prcDest->left) && (!prcDest->right) && (!prcDest->bottom) && (!prcDest->top))
  232. prcDest=NULL;
  233. //allow user to pass uninitialed structure down to represent bitting from the whole surface
  234. if ((prcSrc) && (!prcSrc->left) && (!prcSrc->right) && (!prcSrc->bottom) && (!prcSrc->top))
  235. prcSrc=NULL;
  236. //__try {
  237. *status = m__dxj_DirectDrawSurface7->Blt(prcDest, lpdds, prcSrc, flags, (struct _DDBLTFX *)bltfx);
  238. //}
  239. //__except(1,1){
  240. // return E_INVALIDARG;
  241. //}
  242. return S_OK;
  243. }
  244. /////////////////////////////////////////////////////////////////////////////
  245. STDMETHODIMP C_dxj_DirectDrawSurface7Object::bltColorFill( Rect *pDest, long fillvalue, long *status )
  246. {
  247. HWnd hWnd = NULL;
  248. DDBLTFX bltfx;
  249. memset(&bltfx,0,sizeof(DDBLTFX));
  250. bltfx.dwSize = sizeof(DDBLTFX);
  251. bltfx.dwFillColor = (DWORD)fillvalue;
  252. LPRECT prcDest=(LPRECT)pDest;
  253. //allow user to pass uninitialed structure down to represent bitting to the whole surface
  254. if ((prcDest) && (!prcDest->left) && (!prcDest->right) && (!prcDest->bottom) && (!prcDest->top))
  255. prcDest=NULL;
  256. //__try {
  257. *status = m__dxj_DirectDrawSurface7->Blt(prcDest, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &bltfx);
  258. //}
  259. //__except(1,1){
  260. // return E_INVALIDARG;
  261. //}
  262. return S_OK;
  263. }
  264. /////////////////////////////////////////////////////////////////////////////
  265. STDMETHODIMP C_dxj_DirectDrawSurface7Object::bltFast( long dx, long dy, I_dxj_DirectDrawSurface7 *dds, Rect *src, long trans, long *status)
  266. {
  267. if (!dds) return E_INVALIDARG;
  268. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE7,lpdds,dds)
  269. LPRECT prcSrc=(LPRECT)src;
  270. if (!src) return E_INVALIDARG;
  271. //allow user to pass uninitialed structure down to represent bitting from the whole surface
  272. if ((prcSrc) && (!prcSrc->left) && (!prcSrc->right) && (!prcSrc->bottom) && (!prcSrc->top))
  273. prcSrc=NULL;
  274. //__try {
  275. *status = m__dxj_DirectDrawSurface7->BltFast(dx, dy, lpdds, prcSrc, trans);
  276. //}
  277. //__except(1,1){
  278. // return E_INVALIDARG;
  279. //}
  280. return S_OK;
  281. }
  282. /////////////////////////////////////////////////////////////////////////////
  283. //
  284. STDMETHODIMP C_dxj_DirectDrawSurface7Object::deleteAttachedSurface( I_dxj_DirectDrawSurface7 *dds)
  285. {
  286. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE7, lpdds, dds)
  287. return m__dxj_DirectDrawSurface7->DeleteAttachedSurface(0, lpdds);
  288. }
  289. /////////////////////////////////////////////////////////////////////////////
  290. //
  291. STDMETHODIMP C_dxj_DirectDrawSurface7Object::flip( I_dxj_DirectDrawSurface7 *dds, long flags)
  292. {
  293. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE7,lpdds,dds)
  294. return m__dxj_DirectDrawSurface7->Flip(lpdds, flags);
  295. }
  296. /////////////////////////////////////////////////////////////////////////////
  297. //
  298. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getAttachedSurface( DDSCaps2 *caps, I_dxj_DirectDrawSurface7 **dds)
  299. {
  300. LPDIRECTDRAWSURFACE7 lpdds;
  301. HRESULT hr=DD_OK;
  302. if( (hr=m__dxj_DirectDrawSurface7->GetAttachedSurface( (DDSCAPS2*)caps, &lpdds)) != S_OK )
  303. return hr;
  304. INTERNAL_CREATE(_dxj_DirectDrawSurface7, lpdds, dds);
  305. return S_OK;
  306. }
  307. /////////////////////////////////////////////////////////////////////////////
  308. //
  309. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getCaps( DDSCaps2 *caps)
  310. {
  311. HRESULT hr=DD_OK;
  312. if( (hr=m__dxj_DirectDrawSurface7->GetCaps((DDSCAPS2*)caps)) != S_OK)
  313. return hr;
  314. return S_OK;
  315. }
  316. /////////////////////////////////////////////////////////////////////////////
  317. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getPixelFormat( DDPixelFormat *pf)
  318. {
  319. HRESULT hr=DD_OK;
  320. DDPIXELFORMAT ddpf;
  321. ddpf.dwSize = sizeof(DDPIXELFORMAT);
  322. if( (hr=m__dxj_DirectDrawSurface7->GetPixelFormat(&ddpf)) != S_OK)
  323. return hr;
  324. CopyOutDDPixelFormat(pf,&ddpf);
  325. return S_OK;
  326. }
  327. /////////////////////////////////////////////////////////////////////////////
  328. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getSurfaceDesc( DDSurfaceDesc2 *desc)
  329. {
  330. desc->lpSurface = NULL;
  331. HRESULT hr=DD_OK;
  332. DDSURFACEDESC2 ddsd;
  333. ddsd.dwSize=sizeof(DDSURFACEDESC2);
  334. ddsd.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT);
  335. ddsd.lpSurface=NULL;
  336. if( (hr=m__dxj_DirectDrawSurface7->GetSurfaceDesc( &ddsd )) != S_OK )
  337. return hr;
  338. CopyOutDDSurfaceDesc2(desc,&ddsd);
  339. return S_OK;
  340. }
  341. /////////////////////////////////////////////////////////////////////////////
  342. //
  343. STDMETHODIMP C_dxj_DirectDrawSurface7Object::restore()
  344. {
  345. return m__dxj_DirectDrawSurface7->Restore();
  346. }
  347. /////////////////////////////////////////////////////////////////////////////
  348. //
  349. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setPalette( I_dxj_DirectDrawPalette *ddp)
  350. {
  351. //
  352. // ignore the return value here. Will only work on 256 colours anyway!
  353. //
  354. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWPALETTE,lpddp,ddp)
  355. return m__dxj_DirectDrawSurface7->SetPalette(lpddp);
  356. }
  357. /////////////////////////////////////////////////////////////////////////////
  358. //
  359. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getDirectDraw( I_dxj_DirectDraw7 **val)
  360. {
  361. IUnknown *pUnk=NULL;
  362. LPDIRECTDRAW7 lpdd;
  363. HRESULT hr=DD_OK;
  364. if( (hr=m__dxj_DirectDrawSurface7->GetDDInterface((void **)&pUnk)) != S_OK)
  365. return hr;
  366. hr=pUnk->QueryInterface(IID_IDirectDraw7,(void**)&lpdd);
  367. if FAILED(hr) {
  368. if (pUnk) pUnk->Release();
  369. return hr;
  370. }
  371. INTERNAL_CREATE(_dxj_DirectDraw7, lpdd, val);
  372. return S_OK;
  373. }
  374. /////////////////////////////////////////////////////////////////////////////
  375. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setClipper(I_dxj_DirectDrawClipper *val)
  376. {
  377. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWCLIPPER, lpc, val);
  378. HRESULT hr=DD_OK;
  379. hr=m__dxj_DirectDrawSurface7->SetClipper( lpc);
  380. return hr;
  381. }
  382. /////////////////////////////////////////////////////////////////////////////
  383. STDMETHODIMP C_dxj_DirectDrawSurface7Object::changeUniquenessValue()
  384. {
  385. HRESULT hr=DD_OK;
  386. hr=m__dxj_DirectDrawSurface7->ChangeUniquenessValue();
  387. return hr;
  388. }
  389. /////////////////////////////////////////////////////////////////////////////
  390. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getUniquenessValue(long *ret)
  391. {
  392. HRESULT hr=DD_OK;
  393. hr=m__dxj_DirectDrawSurface7->GetUniquenessValue((DWORD*)ret);
  394. return hr;
  395. }
  396. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getDirectDrawGammaControl(I_dxj_DirectDrawGammaControl **val)
  397. {
  398. HRESULT hr;
  399. LPDIRECTDRAWGAMMACONTROL lpGamma=NULL;
  400. hr=m__dxj_DirectDrawSurface7->QueryInterface(IID_IDirectDrawGammaControl,(void **)&lpGamma);
  401. if FAILED(hr) return hr;
  402. INTERNAL_CREATE(_dxj_DirectDrawGammaControl,lpGamma,val);
  403. if (*val==NULL) return E_OUTOFMEMORY;
  404. return hr;
  405. }
  406. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getDirectDrawColorControl(I_dxj_DirectDrawColorControl **val)
  407. {
  408. HRESULT hr;
  409. LPDIRECTDRAWCOLORCONTROL lpCC=NULL;
  410. hr=m__dxj_DirectDrawSurface7->QueryInterface(IID_IDirectDrawColorControl,(void **)&lpCC);
  411. if FAILED(hr) return hr;
  412. INTERNAL_CREATE(_dxj_DirectDrawColorControl,lpCC,val);
  413. if (*val==NULL) return E_OUTOFMEMORY;
  414. return hr;
  415. }
  416. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setFont(
  417. /* [in] */ IFont __RPC_FAR *font)
  418. {
  419. HRESULT hr;
  420. if (!font) return E_INVALIDARG;
  421. if (m_pIFont) m_pIFont->Release();
  422. m_pIFont=NULL;
  423. hr=font->Clone(&m_pIFont);
  424. return hr;
  425. }
  426. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setFontTransparency(VARIANT_BOOL b)
  427. {
  428. m_fFontTransparent=(b!=VARIANT_FALSE);
  429. return S_OK;
  430. }
  431. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getFontTransparency(VARIANT_BOOL *b)
  432. {
  433. if (m_fFontTransparent)
  434. *b= VARIANT_TRUE;
  435. else
  436. *b= VARIANT_FALSE;
  437. return S_OK;
  438. }
  439. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setDrawWidth( long drawWidth)
  440. {
  441. HPEN hNewPen=NULL;
  442. if (drawWidth < 1) return E_INVALIDARG;
  443. m_drawWidth=drawWidth;
  444. hNewPen = CreatePen(m_drawStyle, m_drawWidth, m_foreColor);
  445. if (!hNewPen) return E_INVALIDARG;
  446. DeleteObject(m_hPen);
  447. m_hPen=hNewPen;
  448. return S_OK;
  449. }
  450. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getDrawWidth(long *val)
  451. {
  452. *val=m_drawWidth;
  453. return S_OK;
  454. }
  455. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setDrawStyle(long drawStyle)
  456. {
  457. HPEN hNewPen=NULL;
  458. m_drawStyle=drawStyle;
  459. hNewPen = CreatePen(m_drawStyle, m_drawWidth, m_foreColor);
  460. if (!hNewPen) return E_INVALIDARG;
  461. DeleteObject(m_hPen);
  462. m_hPen=hNewPen;
  463. return S_OK;
  464. }
  465. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getDrawStyle(long __RPC_FAR *val)
  466. {
  467. *val=m_drawStyle;
  468. return S_OK;
  469. }
  470. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setFillStyle(long fillStyle)
  471. {
  472. HBRUSH hNewBrush=NULL;
  473. BOOL fillTransparent =m_fFillTransparent;
  474. BOOL fillSolid=m_fFillSolid;
  475. long fillStyle2=fillStyle;
  476. m_fillStyle = fillStyle;
  477. m_fFillTransparent = FALSE;
  478. m_fFillSolid = FALSE;
  479. switch(fillStyle){
  480. case 6: //vbCross:
  481. m_fillStyleHS = HS_CROSS;
  482. break;
  483. case 7: //vbDiagonalCross:
  484. m_fillStyleHS = HS_DIAGCROSS;
  485. break;
  486. case 5: //vbxDownwardDiagonal:
  487. m_fillStyleHS = HS_BDIAGONAL;
  488. break;
  489. case 2: //vbHorizontalLine:
  490. m_fillStyleHS = HS_HORIZONTAL;
  491. break;
  492. case 4: //vbUpwardDiagonal:
  493. m_fillStyleHS = HS_FDIAGONAL;
  494. break;
  495. case 3: //vbVerticalLine:
  496. m_fillStyleHS = HS_VERTICAL;
  497. break;
  498. case 0: ///vbFSSolid:
  499. m_fFillSolid = TRUE;
  500. break;
  501. case 1: //vbFSTransparent:
  502. m_fFillTransparent = TRUE;
  503. m_fFillSolid = TRUE;
  504. break;
  505. default:
  506. m_fFillTransparent = fillTransparent;
  507. m_fFillSolid = fillSolid;
  508. m_fillStyle=fillStyle2;
  509. return E_INVALIDARG;
  510. }
  511. if (m_fFillTransparent) {
  512. LOGBRUSH logb;
  513. logb.lbStyle = BS_NULL;
  514. hNewBrush = CreateBrushIndirect(&logb);
  515. }
  516. else if (m_fFillSolid) {
  517. hNewBrush = CreateSolidBrush(m_fillColor);
  518. }
  519. else {
  520. hNewBrush = CreateHatchBrush(m_fillStyleHS, m_fillColor);
  521. }
  522. if (!hNewBrush) return E_FAIL;
  523. if (m_hBrush) DeleteObject(m_hBrush);
  524. m_hBrush=hNewBrush;
  525. return S_OK;
  526. }
  527. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getFillStyle(long *val)
  528. {
  529. *val=m_fillStyle;
  530. return S_OK;
  531. }
  532. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setFillColor(long c)
  533. {
  534. m_fillColor = c;
  535. HBRUSH hNewBrush;
  536. if (m_fFillSolid){
  537. hNewBrush= CreateSolidBrush(m_fillColor);
  538. }
  539. else {
  540. hNewBrush= CreateHatchBrush(m_fillStyleHS, m_fillColor);
  541. }
  542. if (!hNewBrush) return E_INVALIDARG;
  543. if (m_hBrush) DeleteObject(m_hBrush);
  544. m_hBrush=hNewBrush;
  545. return S_OK;
  546. }
  547. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getFillColor(long *val)
  548. {
  549. *val=m_fillColor;
  550. return S_OK;
  551. }
  552. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setForeColor( long color)
  553. {
  554. m_foreColor=color;
  555. HPEN hNewPen=NULL;
  556. hNewPen = CreatePen(m_drawStyle, m_drawWidth, m_foreColor);
  557. if (!hNewPen) return E_INVALIDARG;
  558. if (m_hPen) DeleteObject (m_hPen);
  559. m_hPen=hNewPen;
  560. return S_OK;
  561. }
  562. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getForeColor(long *val)
  563. {
  564. *val=m_foreColor;
  565. return S_OK;
  566. }
  567. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawLine(
  568. /* [in] */ long x1,
  569. /* [in] */ long y1,
  570. /* [in] */ long x2,
  571. /* [in] */ long y2)
  572. {
  573. HDC hdc;
  574. HBRUSH oldbrush;
  575. HPEN oldpen;
  576. POINT points[2];
  577. HRESULT hr;
  578. hr =m__dxj_DirectDrawSurface7->GetDC(&hdc);
  579. if FAILED(hr) return hr;
  580. points[0].x = x1;
  581. points[0].y = y1;
  582. points[1].x = x2;
  583. points[1].y = y2;
  584. //CONSIDER: doing this when dc is set
  585. if (m_hPen) oldpen = (HPEN)SelectObject(hdc,m_hPen);
  586. if (m_hBrush) oldbrush = (HBRUSH)SelectObject(hdc,m_hBrush);
  587. if (m_fFontTransparent){
  588. SetBkMode (hdc, TRANSPARENT);
  589. }
  590. else {
  591. SetBkMode (hdc, OPAQUE);
  592. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  593. }
  594. Polyline(hdc, points, 2);
  595. //why do this..
  596. //if (oldpen) SelectObject(hdc, oldpen);
  597. //if (oldbrush) SelectObject(hdc, oldbrush);
  598. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  599. return S_OK;
  600. }
  601. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawBox(
  602. /* [in] */ long x1,
  603. /* [in] */ long y1,
  604. /* [in] */ long x2,
  605. /* [in] */ long y2)
  606. {
  607. HDC hdc;
  608. HBRUSH oldbrush;
  609. HPEN oldpen;
  610. HRESULT hr;
  611. hr= m__dxj_DirectDrawSurface7->GetDC(&hdc);
  612. if FAILED(hr) return hr;
  613. //CONSIDER: doing this when dc is set
  614. if (m_hPen) oldpen = (HPEN)SelectObject(hdc,m_hPen);
  615. if (m_hBrush) oldbrush = (HBRUSH)SelectObject(hdc,m_hBrush);
  616. if (m_fFontTransparent){
  617. SetBkMode (hdc, TRANSPARENT);
  618. }
  619. else {
  620. SetBkMode (hdc, OPAQUE);
  621. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  622. }
  623. Rectangle(hdc, x1,y1,x2,y2);
  624. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  625. return S_OK;
  626. }
  627. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawRoundedBox(
  628. /* [in] */ long x1,
  629. /* [in] */ long y1,
  630. /* [in] */ long x2,
  631. /* [in] */ long y2,
  632. /* [in] */ long rw,
  633. /* [in] */ long rh)
  634. {
  635. HDC hdc;
  636. HBRUSH oldbrush;
  637. HPEN oldpen;
  638. HRESULT hr;
  639. hr= m__dxj_DirectDrawSurface7->GetDC(&hdc);
  640. if FAILED(hr) return hr;
  641. //CONSIDER: doing this when dc is set
  642. if (m_hPen) oldpen = (HPEN)SelectObject(hdc,m_hPen);
  643. if (m_hBrush) oldbrush = (HBRUSH)SelectObject(hdc,m_hBrush);
  644. if (m_fFontTransparent){
  645. SetBkMode (hdc, TRANSPARENT);
  646. }
  647. else {
  648. SetBkMode (hdc, OPAQUE);
  649. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  650. }
  651. RoundRect(hdc, x1,y1,x2,y2,rw,rh);
  652. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  653. return S_OK;
  654. }
  655. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawEllipse(
  656. /* [in] */ long x1,
  657. /* [in] */ long y1,
  658. /* [in] */ long x2,
  659. /* [in] */ long y2)
  660. {
  661. HDC hdc;
  662. HBRUSH oldbrush;
  663. HPEN oldpen;
  664. HRESULT hr;
  665. hr=m__dxj_DirectDrawSurface7->GetDC(&hdc);
  666. if FAILED(hr) return hr;
  667. //CONSIDER: doing this when dc is set
  668. if (m_hPen) oldpen = (HPEN)SelectObject(hdc,m_hPen);
  669. if (m_hBrush) oldbrush = (HBRUSH)SelectObject(hdc,m_hBrush);
  670. if (m_fFontTransparent){
  671. SetBkMode (hdc, TRANSPARENT);
  672. }
  673. else {
  674. SetBkMode (hdc, OPAQUE);
  675. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  676. }
  677. Ellipse(hdc, x1, y1, x2, y2);
  678. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  679. return S_OK;
  680. }
  681. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawCircle(
  682. /* [in] */ long x,
  683. /* [in] */ long y,
  684. /* [in] */ long r)
  685. {
  686. HDC hdc;
  687. HBRUSH oldbrush;
  688. HPEN oldpen;
  689. HRESULT hr;
  690. long x1,y1,x2,y2;
  691. hr= m__dxj_DirectDrawSurface7->GetDC(&hdc);
  692. if FAILED(hr) return hr;
  693. //CONSIDER: doing this when dc is set
  694. if (m_hPen) oldpen = (HPEN)SelectObject(hdc,m_hPen);
  695. if (m_hBrush) oldbrush = (HBRUSH)SelectObject(hdc,m_hBrush);
  696. if (m_fFontTransparent){
  697. SetBkMode (hdc, TRANSPARENT);
  698. }
  699. else {
  700. SetBkMode (hdc, OPAQUE);
  701. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  702. }
  703. x1 = x - r;
  704. x2 = x + r;
  705. y1 = y - r;
  706. y2 = y + r;
  707. Ellipse(hdc, x1, y1, x2, y2);
  708. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  709. return S_OK;
  710. }
  711. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::drawText(
  712. /* [in] */ long x,
  713. /* [in] */ long y,
  714. /* [in] */ BSTR str,
  715. /* [in] */ VARIANT_BOOL b)
  716. {
  717. HDC hdc=NULL;
  718. HRESULT hr;
  719. DWORD len=0;
  720. UINT txtA;
  721. if (!str) return E_INVALIDARG;
  722. len = ((DWORD*)str)[-1]/2;
  723. hr=m__dxj_DirectDrawSurface7->GetDC(&hdc);
  724. if FAILED(hr) return hr;
  725. if (m_fFontTransparent){
  726. SetBkMode (hdc, TRANSPARENT);
  727. }
  728. else {
  729. SetBkMode (hdc, OPAQUE);
  730. SetBkColor (hdc,(COLORREF)m_fontBackColor);
  731. }
  732. SetTextColor(hdc, m_foreColor);
  733. txtA=GetTextAlign(hdc);
  734. if (b!=VARIANT_FALSE){
  735. if (!(txtA & TA_UPDATECP)) SetTextAlign(hdc,txtA | TA_UPDATECP);
  736. }
  737. else {
  738. if (txtA & TA_UPDATECP) SetTextAlign(hdc,txtA-TA_UPDATECP);
  739. }
  740. if (m_pIFont) {
  741. HFONT hFont=NULL;
  742. m_pIFont->SetHdc(hdc);
  743. m_pIFont->get_hFont(&hFont);
  744. SelectObject (hdc, hFont);
  745. }
  746. ExtTextOutW(hdc, (int)x, (int)y, 0, 0, str, len, 0);
  747. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  748. return S_OK;
  749. }
  750. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::bltToDC(
  751. /* [in] */ long hdcDest,
  752. /* [in] */ Rect __RPC_FAR *srcRect,
  753. /* [in] */ Rect __RPC_FAR *destRect)
  754. {
  755. HRESULT hr;
  756. BOOL b;
  757. HDC hdc=NULL;
  758. if (!srcRect) return E_INVALIDARG;
  759. if (!destRect) return E_INVALIDARG;
  760. hr=m__dxj_DirectDrawSurface7->GetDC(&hdc);
  761. if FAILED(hr) return hr;
  762. int nWidthDest= destRect->right-destRect->left;
  763. int nHeightDest=destRect->bottom-destRect->top;
  764. int nWidthSrc= srcRect->right-srcRect->left;
  765. int nHeightSrc=srcRect->bottom-srcRect->top;
  766. if ((0==srcRect->top) && (0==srcRect->left ) && (0==srcRect->top) &&(0==srcRect->bottom ))
  767. {
  768. DDSURFACEDESC2 desc;
  769. desc.dwSize=sizeof(DDSURFACEDESC2);
  770. m__dxj_DirectDrawSurface7->GetSurfaceDesc(&desc);
  771. nWidthSrc=desc.dwWidth;
  772. nHeightSrc=desc.dwHeight;
  773. }
  774. b=StretchBlt((HDC)hdcDest,
  775. destRect->left,destRect->top,
  776. nWidthDest, nHeightDest,
  777. hdc,
  778. srcRect->left,srcRect->top,
  779. nWidthSrc, nHeightSrc, SRCCOPY);
  780. m__dxj_DirectDrawSurface7->ReleaseDC(hdc);
  781. //CONSIDER: are we being presumptious that if blt fails its due to arg probs?
  782. if (!b) return E_INVALIDARG;
  783. return S_OK;
  784. }
  785. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getAttachedSurfaceEnum(I_dxj_DirectDrawEnumSurfaces **val)
  786. {
  787. HRESULT hr;
  788. hr=C_dxj_DirectDrawEnumSurfacesObject::createAttachedEnum((I_dxj_DirectDrawSurface7 *)this,val);
  789. return hr;
  790. }
  791. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setPriority( long Priority)
  792. {
  793. return m__dxj_DirectDrawSurface7->SetPriority((DWORD)Priority);
  794. }
  795. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getPriority( long *Priority)
  796. {
  797. return m__dxj_DirectDrawSurface7->GetPriority((DWORD*)Priority);
  798. }
  799. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setLOD( long lod)
  800. {
  801. return m__dxj_DirectDrawSurface7->SetLOD((DWORD)lod);
  802. }
  803. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getLOD(long *lod)
  804. {
  805. return m__dxj_DirectDrawSurface7->GetLOD((DWORD*)lod);
  806. }
  807. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getLockedArray(SAFEARRAY **pArray)
  808. {
  809. if (!m_bLocked) return E_FAIL;
  810. if (!pArray) return E_INVALIDARG;
  811. if (*pArray) return E_INVALIDARG;
  812. m_ppSA=pArray;
  813. m_bLockedArray=TRUE;
  814. ZeroMemory(&m_saLockedArray,sizeof(SAFEARRAY));
  815. m_saLockedArray.cbElements =1;
  816. m_saLockedArray.cDims =2;
  817. m_saLockedArray.rgsabound[0].lLbound =0;
  818. m_saLockedArray.rgsabound[0].cElements =m_ddsd.dwHeight;
  819. m_saLockedArray.rgsabound[1].lLbound =0;
  820. m_saLockedArray.rgsabound[1].cElements =m_ddsd.lPitch;
  821. m_saLockedArray.pvData =m_ddsd.lpSurface;
  822. *pArray=&m_saLockedArray;
  823. return S_OK;
  824. }
  825. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::setFontBackColor(
  826. /* [in] */ long color)
  827. {
  828. m_fontBackColor=(DWORD)color;
  829. return S_OK;
  830. }
  831. HRESULT STDMETHODCALLTYPE C_dxj_DirectDrawSurface7Object::getFontBackColor(
  832. /* [in] */ long *color)
  833. {
  834. if (!color) return E_INVALIDARG;
  835. *color=(long)m_fontBackColor;
  836. return S_OK;
  837. }
  838. STDMETHODIMP C_dxj_DirectDrawSurface7Object::updateOverlayZOrder(long flags,I_dxj_DirectDrawSurface7 *dds)
  839. {
  840. HRESULT hr;
  841. DO_GETOBJECT_NOTNULL(LPDIRECTDRAWSURFACE7,lpdds,dds)
  842. hr= m__dxj_DirectDrawSurface7->UpdateOverlayZOrder((DWORD)flags,lpdds);
  843. return hr;
  844. }
  845. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getOverlayZOrdersEnum(long flags,I_dxj_DirectDrawEnumSurfaces **val)
  846. {
  847. HRESULT hr;
  848. hr=C_dxj_DirectDrawEnumSurfacesObject::createZEnum((I_dxj_DirectDrawSurface7*)this,flags,val);
  849. return hr;
  850. }
  851. STDMETHODIMP C_dxj_DirectDrawSurface7Object::getOverlayPosition( long *x, long *y)
  852. {
  853. return m__dxj_DirectDrawSurface7->GetOverlayPosition(x, y) ;
  854. }
  855. STDMETHODIMP C_dxj_DirectDrawSurface7Object::setOverlayPosition( long x, long y)
  856. {
  857. return m__dxj_DirectDrawSurface7->SetOverlayPosition(x, y) ;
  858. }
  859. STDMETHODIMP C_dxj_DirectDrawSurface7Object::updateOverlay( Rect *r, I_dxj_DirectDrawSurface7 *dds, Rect *d, long flags)
  860. {
  861. DO_GETOBJECT_NOTNULL( LPDIRECTDRAWSURFACE7, lpdds, dds)
  862. LPRECT pr1=NULL;
  863. LPRECT pr2=NULL;
  864. if (r) {
  865. pr1=(RECT*) r;
  866. if ((r->top==0)&&(r->bottom==0)&&(r->left==0)&&(r->right==0))
  867. pr1=NULL;
  868. }
  869. if (d) {
  870. pr2=(RECT*) d;
  871. if ((d->top==0)&&(d->bottom==0)&&(d->left==0)&&(d->right==0))
  872. pr2=NULL;
  873. }
  874. return m__dxj_DirectDrawSurface7->UpdateOverlay(pr1, lpdds, pr2, flags, NULL);
  875. }
  876. STDMETHODIMP C_dxj_DirectDrawSurface7Object::updateOverlayFx( Rect *r, I_dxj_DirectDrawSurface7 *dds, Rect *d, long flags, DDOVERLAYFX_CDESC *desc)
  877. {
  878. if (!desc) return E_INVALIDARG;
  879. DDOVERLAYFX *lpOverlayFx=(DDOVERLAYFX*)desc;
  880. lpOverlayFx->dwSize =sizeof(DDOVERLAYFX);
  881. DO_GETOBJECT_NOTNULL( LPDIRECTDRAWSURFACE7, lpdds, dds)
  882. LPRECT pr1=NULL;
  883. LPRECT pr2=NULL;
  884. if (r) {
  885. pr1=(RECT*) r;
  886. if ((r->top==0)&&(r->bottom==0)&&(r->left==0)&&(r->right==0))
  887. pr1=NULL;
  888. }
  889. if (d) {
  890. pr2=(RECT*) d;
  891. if ((d->top==0)&&(d->bottom==0)&&(d->left==0)&&(d->right==0))
  892. pr2=NULL;
  893. }
  894. return m__dxj_DirectDrawSurface7->UpdateOverlay(pr1, lpdds, pr2, flags, lpOverlayFx);
  895. }