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.

198 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: ddclipperobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // ddClipperObj.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 "ddClipperObj.h"
  16. typedef HRESULT (__stdcall *DDCREATECLIPPER)( DWORD dwFlags, LPDIRECTDRAWCLIPPER FAR *lplpDDClipper, IUnknown FAR *pUnkOuter );
  17. C_dxj_DirectDrawClipperObject::C_dxj_DirectDrawClipperObject(){
  18. m__dxj_DirectDrawClipper= NULL;
  19. parent = NULL;
  20. pinterface = NULL;
  21. nextobj = g_dxj_DirectDrawClipper;
  22. creationid = ++g_creationcount;
  23. DPF1(1,"Clipper Creation Id [%d] \n",g_creationcount);
  24. g_dxj_DirectDrawClipper = (void *)this;
  25. }
  26. C_dxj_DirectDrawClipperObject::~C_dxj_DirectDrawClipperObject()
  27. {
  28. C_dxj_DirectDrawClipperObject *prev=NULL;
  29. for(C_dxj_DirectDrawClipperObject *ptr=(C_dxj_DirectDrawClipperObject *)g_dxj_DirectDrawClipper; ptr; ptr=(C_dxj_DirectDrawClipperObject *)ptr->nextobj)
  30. {
  31. if(ptr == this)
  32. {
  33. if(prev)
  34. prev->nextobj = ptr->nextobj;
  35. else
  36. g_dxj_DirectDrawClipper = (void*)ptr->nextobj;
  37. break;
  38. }
  39. prev = ptr;
  40. }
  41. if(m__dxj_DirectDrawClipper){
  42. int count = IUNK(m__dxj_DirectDrawClipper)->Release();
  43. DPF1(1,"Clipper Real Ref count [%d] \n",count);
  44. if(count==0) m__dxj_DirectDrawClipper = NULL;
  45. }
  46. if(parent) IUNK(parent)->Release();
  47. }
  48. DWORD C_dxj_DirectDrawClipperObject::InternalAddRef(){
  49. DWORD i;
  50. i=CComObjectRoot::InternalAddRef();
  51. DPF2(1,"Clipper [%d] AddRef %d \n",creationid,i);
  52. return i;
  53. }
  54. DWORD C_dxj_DirectDrawClipperObject::InternalRelease(){
  55. DWORD i;
  56. i=CComObjectRoot::InternalRelease();
  57. DPF2(1,"Clipper [%d] Release %d \n",creationid,i);
  58. return i;
  59. }
  60. GETSET_OBJECT(_dxj_DirectDrawClipper);
  61. PASS_THROUGH1_R(_dxj_DirectDrawClipper, isClipListChanged, IsClipListChanged, int *);
  62. /////////////////////////////////////////////////////////////////////////////
  63. STDMETHODIMP C_dxj_DirectDrawClipperObject::getClipListSize(int *count)
  64. {
  65. HRESULT retval;
  66. unsigned long buffsize;
  67. //a NULL RGNDATA pointer returns size!!!
  68. retval = m__dxj_DirectDrawClipper->GetClipList((LPRECT)NULL, (LPRGNDATA)NULL, &buffsize);
  69. // return size as number of longs in the rect array
  70. if ( retval != DD_OK )
  71. *count = 0; // this case probably means no cliplist is avaible
  72. else
  73. *count = (buffsize - sizeof(RGNDATAHEADER))/sizeof(LONG);
  74. return retval;
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. STDMETHODIMP C_dxj_DirectDrawClipperObject::getClipList( SAFEARRAY **list)
  78. {
  79. HRESULT retval;
  80. LPRGNDATA tmprgn=NULL;
  81. DWORD buffsize;
  82. // allocate a private copy of the cliplist
  83. retval = m__dxj_DirectDrawClipper->GetClipList((LPRECT)NULL, (LPRGNDATA)NULL, &buffsize);
  84. if FAILED(retval) return retval;
  85. tmprgn = (LPRGNDATA)malloc(buffsize);
  86. if ( !tmprgn ) return E_OUTOFMEMORY;
  87. ZeroMemory(tmprgn,buffsize);
  88. tmprgn->rdh.dwSize = sizeof(RGNDATAHEADER);
  89. tmprgn->rdh.iType = RDH_RECTANGLES;
  90. tmprgn->rdh.nCount;
  91. // get the actual clip list
  92. retval = m__dxj_DirectDrawClipper->GetClipList(NULL,tmprgn,&buffsize);
  93. if ( retval != DD_OK ) return retval;
  94. __try{
  95. memcpy ( (((SAFEARRAY*)*list))->pvData,tmprgn->Buffer,tmprgn->rdh.nRgnSize);
  96. }
  97. __except(1,1){
  98. if (tmprgn) free(tmprgn);
  99. return E_FAIL;
  100. }
  101. free(tmprgn);
  102. return retval;
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. STDMETHODIMP C_dxj_DirectDrawClipperObject::setClipList( long count, SAFEARRAY **list)
  106. {
  107. HRESULT retval;
  108. LPRGNDATA tmprgn;
  109. // allocate a private copy of the cliplist
  110. tmprgn = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+(count*sizeof(RECT)));
  111. if ( !tmprgn ) return E_OUTOFMEMORY;
  112. ZeroMemory(tmprgn,sizeof(RGNDATAHEADER)+(count*sizeof(RECT)));
  113. tmprgn->rdh.dwSize = sizeof(RGNDATAHEADER);
  114. tmprgn->rdh.iType = RDH_RECTANGLES;
  115. tmprgn->rdh.nCount = count;
  116. tmprgn->rdh.nRgnSize = count*sizeof(RECT);
  117. __try{
  118. memcpy ( tmprgn->Buffer,(((SAFEARRAY*)*list))->pvData,tmprgn->rdh.nRgnSize);
  119. }
  120. __except(1,1){
  121. if (tmprgn) free(tmprgn);
  122. return E_FAIL;
  123. }
  124. retval = m__dxj_DirectDrawClipper->SetClipList(tmprgn,0);
  125. free(tmprgn);
  126. return retval;
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. STDMETHODIMP C_dxj_DirectDrawClipperObject::getHWnd( HWnd *hwn)
  130. {
  131. if (!hwn) return E_FAIL;
  132. return m__dxj_DirectDrawClipper->GetHWnd( (HWND*)hwn );
  133. }
  134. /////////////////////////////////////////////////////////////////////////////
  135. STDMETHODIMP C_dxj_DirectDrawClipperObject::setHWnd( HWnd hwn)
  136. {
  137. return m__dxj_DirectDrawClipper->SetHWnd(0, (HWND)hwn);
  138. }