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.

1084 lines
30 KiB

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