Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenenhmfile.c
Go to the documentation of this file.
00001 #include "precomp.h" 00002 00003 #define NDEBUG 00004 #include <debug.h> 00005 00006 00007 00008 /* 00009 * @unimplemented 00010 */ 00011 HENHMETAFILE 00012 WINAPI 00013 CloseEnhMetaFile( 00014 HDC hdc) 00015 { 00016 UNIMPLEMENTED; 00017 return 0; 00018 } 00019 00020 00021 #if 0 // Remove once new EnhMetaFile support is implemented. 00022 HDC 00023 WINAPI 00024 CreateEnhMetaFileW( 00025 HDC hDC, /* [in] optional reference DC */ 00026 LPCWSTR filename, /* [in] optional filename for disk metafiles */ 00027 const RECT* rect, /* [in] optional bounding rectangle */ 00028 LPCWSTR description /* [in] optional description */ 00029 ) 00030 { 00031 HDC mDC; 00032 PDC_ATTR Dc_Attr; 00033 PLDC pLDC; 00034 HANDLE hFile; 00035 PENHMETAFILE EmfDC; 00036 DWORD size = 0, length = 0; 00037 00038 mDC = NtGdiCreateMetafileDC( hDC ); // Basically changes the handle from 1xxxx to 46xxxx. 00039 // If hDC == NULL, works just like createdc in win32k. 00040 00041 if ( !GdiGetHandleUserData((HGDIOBJ) mDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) 00042 { 00043 SetLastError (ERROR_INVALID_PARAMETER); 00044 return NULL; // need to delete the handle? 00045 } 00046 00047 pLDC = LocalAlloc(LMEM_ZEROINIT, sizeof(LDC)); 00048 00049 Dc_Attr->pvLDC = pLDC; 00050 pLDC->hDC = mDC; 00051 pLDC->iType = LDC_EMFDC 00052 00053 00054 if (description) 00055 { 00056 /* App name\0Title\0\0 */ 00057 length = lstrlenW(description); 00058 length += lstrlenW(description + length + 1); 00059 length += 3; 00060 length *= 2; 00061 } 00062 00063 size = sizeof(ENHMETAFILE) + (length + 3) / 4 * 4; 00064 00065 //Allocate ENHMETAFILE structure 00066 EmfDC = LocalAlloc(LMEM_ZEROINIT, sizeof(ENHMETAFILE)); 00067 pLDC->pvEmfDC = EmfDC; 00068 00069 EmfDC->handles_size = HANDLE_LIST_INC; 00070 EmfDC->cur_handles = 1; 00071 00072 EmfDC->horzres = GetDeviceCaps(mDC, HORZRES); 00073 EmfDC->vertres = GetDeviceCaps(mDC, VERTRES); 00074 EmfDC->logpixelsx = GetDeviceCaps(mDC, LOGPIXELSX); 00075 EmfDC->logpixelsy = GetDeviceCaps(mDC, LOGPIXELSY); 00076 EmfDC->horzsize = GetDeviceCaps(mDC, HORZSIZE); 00077 EmfDC->vertsize = GetDeviceCaps(mDC, VERTSIZE); 00078 EmfDC->bitspixel = GetDeviceCaps(mDC, BITSPIXEL); 00079 EmfDC->textcaps = GetDeviceCaps(mDC, TEXTCAPS); 00080 EmfDC->rastercaps = GetDeviceCaps(mDC, RASTERCAPS); 00081 EmfDC->technology = GetDeviceCaps(mDC, TECHNOLOGY); 00082 EmfDC->planes = GetDeviceCaps(mDC, PLANES); 00083 00084 EmfDC->emf = LocalAlloc(LMEM_ZEROINIT, size); 00085 00086 EmfDC->emf->iType = EMR_HEADER; 00087 EmfDC->emf->nSize = size; 00088 00089 EmfDC->emf->rclBounds.left = EmfDC->emf->rclBounds.top = 0; 00090 EmfDC->emf->rclBounds.right = EmfDC->emf->rclBounds.bottom = -1; 00091 00092 if(rect) 00093 { 00094 EmfDC->emf->rclFrame.left = rect->left; 00095 EmfDC->emf->rclFrame.top = rect->top; 00096 EmfDC->emf->rclFrame.right = rect->right; 00097 EmfDC->emf->rclFrame.bottom = rect->bottom; 00098 } 00099 else 00100 { 00101 /* Set this to {0,0 - -1,-1} and update it at the end */ 00102 EmfDC->emf->rclFrame.left = EmfDC->emf->rclFrame.top = 0; 00103 EmfDC->emf->rclFrame.right = EmfDC->emf->rclFrame.bottom = -1; 00104 } 00105 00106 EmfDC->emf->dSignature = ENHMETA_SIGNATURE; 00107 EmfDC->emf->nVersion = 0x10000; 00108 EmfDC->emf->nBytes = pLDC->pvEmfDC->nSize; 00109 EmfDC->emf->nRecords = 1; 00110 EmfDC->emf->nHandles = 1; 00111 00112 EmfDC->emf->sReserved = 0; /* According to docs, this is reserved and must be 0 */ 00113 EmfDC->emf->nDescription = length / 2; 00114 00115 EmfDC->emf->offDescription = length ? sizeof(ENHMETAHEADER) : 0; 00116 00117 EmfDC->emf->nPalEntries = 0; /* I guess this should start at 0 */ 00118 00119 /* Size in pixels */ 00120 EmfDC->emf->szlDevice.cx = EmfDC->horzres; 00121 EmfDC->emf->szlDevice.cy = EmfDC->vertres; 00122 00123 /* Size in millimeters */ 00124 EmfDC->emf->szlMillimeters.cx = EmfDC->horzsize; 00125 EmfDC->emf->szlMillimeters.cy = EmfDC->vertsize; 00126 00127 /* Size in micrometers */ 00128 EmfDC->emf->szlMicrometers.cx = EmfDC->horzsize * 1000; 00129 EmfDC->emf->szlMicrometers.cy = EmfDC->vertsize * 1000; 00130 00131 RtlCopyMemory((char *)EmfDC->emf + sizeof(ENHMETAHEADER), description, length); 00132 00133 if (filename) /* disk based metafile */ 00134 { 00135 if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0, 00136 NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) 00137 { 00138 EMFDRV_DeleteDC( EmfDC ); 00139 return NULL; 00140 } 00141 if (!WriteFile( hFile, (LPSTR)EmfDC->emf, size, NULL, NULL )) 00142 { 00143 EMFDRV_DeleteDC( EmfDC ); 00144 return NULL; 00145 } 00146 EmfDC.hFile = hFile; 00147 EmfDC.iType = METAFILE_DISK; 00148 } 00149 else 00150 EmfDC.iType = METAFILE_MEMORY; 00151 00152 return mDC; 00153 } 00154 #endif 00155 00156 00157 /* 00158 * @unimplemented 00159 */ 00160 HENHMETAFILE 00161 WINAPI 00162 CopyEnhMetaFileA( 00163 HENHMETAFILE hemfSrc, 00164 LPCSTR lpszFile) 00165 { 00166 NTSTATUS Status; 00167 LPWSTR lpszFileW; 00168 HENHMETAFILE rc = 0; 00169 00170 Status = HEAP_strdupA2W ( &lpszFileW, lpszFile ); 00171 if (!NT_SUCCESS (Status)) 00172 SetLastError (RtlNtStatusToDosError(Status)); 00173 else 00174 { 00175 rc = NULL; 00176 00177 HEAP_free ( lpszFileW ); 00178 } 00179 return rc; 00180 } 00181 00182 00183 /* 00184 * @unimplemented 00185 */ 00186 HDC 00187 WINAPI 00188 CreateEnhMetaFileA( 00189 HDC hdcRef, 00190 LPCSTR lpFileName, 00191 CONST RECT *lpRect, 00192 LPCSTR lpDescription) 00193 { 00194 NTSTATUS Status; 00195 LPWSTR lpFileNameW, lpDescriptionW; 00196 HDC rc = 0; 00197 00198 lpFileNameW = NULL; 00199 if (lpFileName != NULL) 00200 { 00201 Status = HEAP_strdupA2W ( &lpFileNameW, lpFileName ); 00202 if (!NT_SUCCESS (Status)) 00203 SetLastError (RtlNtStatusToDosError(Status)); 00204 00205 return rc; 00206 } 00207 00208 lpDescriptionW = NULL; 00209 if (lpDescription != NULL) 00210 { 00211 Status = HEAP_strdupA2W ( &lpDescriptionW, lpDescription ); 00212 if (!NT_SUCCESS (Status)) 00213 SetLastError (RtlNtStatusToDosError(Status)); 00214 00215 return rc; 00216 } 00217 00218 rc = NULL; 00219 00220 if (lpDescriptionW != NULL) 00221 HEAP_free ( lpDescriptionW ); 00222 00223 if (lpFileNameW != NULL) 00224 HEAP_free ( lpFileNameW ); 00225 00226 return rc; 00227 } 00228 00229 #if 0 00230 /* Previous implementation in win32k */ 00231 HDC 00232 WINAPI 00233 NtGdiCreateEnhMetaFile(HDC hDCRef, 00234 LPCWSTR File, 00235 CONST LPRECT Rect, 00236 LPCWSTR Description) 00237 { 00238 PDC Dc; 00239 HDC ret = NULL; 00240 DWORD length = 0; 00241 HDC tempHDC; 00242 DWORD MemSize; 00243 DWORD dwDesiredAccess; 00244 00245 tempHDC = hDCRef; 00246 if (hDCRef == NULL) 00247 { 00248 /* FIXME ?? 00249 * Shall we create hdc NtGdiHdcCompatible hdc ?? 00250 */ 00251 UNICODE_STRING DriverName; 00252 RtlInitUnicodeString(&DriverName, L"DISPLAY"); 00253 //IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE); 00254 tempHDC = NtGdiOpenDCW( &DriverName, 00255 NULL, 00256 NULL, 00257 0, // DCW 0 and ICW 1. 00258 NULL, 00259 (PVOID) NULL, 00260 (PVOID) NULL ); 00261 } 00262 00263 GDIOBJ_SetOwnership(GdiHandleTable, tempHDC, PsGetCurrentProcess()); 00264 DC_SetOwnership(tempHDC, PsGetCurrentProcess()); 00265 00266 Dc = DC_LockDc(tempHDC); 00267 if (Dc == NULL) 00268 { 00269 if (hDCRef == NULL) 00270 { 00271 NtGdiDeleteObjectApp(tempHDC); 00272 } 00273 SetLastWin32Error(ERROR_INVALID_HANDLE); 00274 return NULL; 00275 } 00276 00277 if(Description) 00278 { 00279 length = wcslen(Description); 00280 length += wcslen(Description + length + 1); 00281 length += 3; 00282 length *= 2; 00283 } 00284 00285 MemSize = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4; 00286 00287 if (!(Dc->emh = EngAllocMem(FL_ZERO_MEMORY, MemSize, 0))) 00288 { 00289 DC_UnlockDc(Dc); 00290 if (hDCRef == NULL) 00291 { 00292 NtGdiDeleteObjectApp(tempHDC); 00293 } 00294 SetLastWin32Error(ERROR_INVALID_HANDLE); 00295 return NULL; 00296 } 00297 00298 Dc->emh->iType = EMR_HEADER; 00299 Dc->emh->nSize = MemSize; 00300 00301 Dc->emh->rclBounds.left = Dc->emh->rclBounds.top = 0; 00302 Dc->emh->rclBounds.right = Dc->emh->rclBounds.bottom = -1; 00303 00304 if(Rect) 00305 { 00306 Dc->emh->rclFrame.left = Rect->left; 00307 Dc->emh->rclFrame.top = Rect->top; 00308 Dc->emh->rclFrame.right = Rect->right; 00309 Dc->emh->rclFrame.bottom = Rect->bottom; 00310 } 00311 else 00312 { 00313 /* Set this to {0,0 - -1,-1} and update it at the end */ 00314 Dc->emh->rclFrame.left = Dc->emh->rclFrame.top = 0; 00315 Dc->emh->rclFrame.right = Dc->emh->rclFrame.bottom = -1; 00316 } 00317 00318 Dc->emh->dSignature = ENHMETA_SIGNATURE; 00319 Dc->emh->nVersion = 0x10000; 00320 Dc->emh->nBytes = Dc->emh->nSize; 00321 Dc->emh->nRecords = 1; 00322 Dc->emh->nHandles = 1; 00323 00324 Dc->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */ 00325 Dc->emh->nDescription = length / 2; 00326 00327 Dc->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0; 00328 00329 Dc->emh->nPalEntries = 0; /* I guess this should start at 0 */ 00330 00331 /* Size in pixels */ 00332 Dc->emh->szlDevice.cx = NtGdiGetDeviceCaps(tempHDC, HORZRES); 00333 Dc->emh->szlDevice.cy = NtGdiGetDeviceCaps(tempHDC, VERTRES); 00334 00335 /* Size in millimeters */ 00336 Dc->emh->szlMillimeters.cx = NtGdiGetDeviceCaps(tempHDC, HORZSIZE); 00337 Dc->emh->szlMillimeters.cy = NtGdiGetDeviceCaps(tempHDC, VERTSIZE); 00338 00339 /* Size in micrometers */ 00340 Dc->emh->szlMicrometers.cx = Dc->emh->szlMillimeters.cx * 1000; 00341 Dc->emh->szlMicrometers.cy = Dc->emh->szlMillimeters.cy * 1000; 00342 00343 if(Description) 00344 { 00345 memcpy((char *)Dc->emh + sizeof(ENHMETAHEADER), Description, length); 00346 } 00347 00348 ret = tempHDC; 00349 if (File) 00350 { 00351 OBJECT_ATTRIBUTES ObjectAttributes; 00352 IO_STATUS_BLOCK IoStatusBlock; 00353 IO_STATUS_BLOCK Iosb; 00354 UNICODE_STRING NtPathU; 00355 NTSTATUS Status; 00356 ULONG FileAttributes = (FILE_ATTRIBUTE_VALID_FLAGS & ~FILE_ATTRIBUTE_DIRECTORY); 00357 00358 DPRINT1("Trying Create EnhMetaFile\n"); 00359 00360 /* disk based metafile */ 00361 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ | SYNCHRONIZE | FILE_READ_ATTRIBUTES; 00362 00363 if (!RtlDosPathNameToNtPathName_U (File, &NtPathU, NULL, NULL)) 00364 { 00365 DC_UnlockDc(Dc); 00366 if (hDCRef == NULL) 00367 { 00368 NtGdiDeleteObjectApp(tempHDC); 00369 } 00370 DPRINT1("Can not Create EnhMetaFile\n"); 00371 SetLastWin32Error(ERROR_PATH_NOT_FOUND); 00372 return NULL; 00373 } 00374 00375 InitializeObjectAttributes(&ObjectAttributes, &NtPathU, 0, NULL, NULL); 00376 00377 Status = NtCreateFile (&Dc->hFile, dwDesiredAccess, &ObjectAttributes, &IoStatusBlock, 00378 NULL, FileAttributes, 0, FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE, 00379 NULL, 0); 00380 00381 RtlFreeHeap(RtlGetProcessHeap(), 0, NtPathU.Buffer); 00382 00383 if (!NT_SUCCESS(Status)) 00384 { 00385 Dc->hFile = NULL; 00386 DC_UnlockDc(Dc); 00387 if (hDCRef == NULL) 00388 { 00389 NtGdiDeleteObjectApp(tempHDC); 00390 } 00391 DPRINT1("Create EnhMetaFile fail\n"); 00392 SetLastWin32Error(ERROR_INVALID_HANDLE); 00393 return NULL; 00394 } 00395 00396 SetLastWin32Error(IoStatusBlock.Information == FILE_OVERWRITTEN ? ERROR_ALREADY_EXISTS : 0); 00397 00398 Status = NtWriteFile(Dc->hFile, NULL, NULL, NULL, &Iosb, (PVOID)&Dc->emh, Dc->emh->nSize, NULL, NULL); 00399 if (Status == STATUS_PENDING) 00400 { 00401 Status = NtWaitForSingleObject(Dc->hFile,FALSE,NULL); 00402 if (NT_SUCCESS(Status)) 00403 { 00404 Status = Iosb.Status; 00405 } 00406 } 00407 00408 if (NT_SUCCESS(Status)) 00409 { 00410 ret = tempHDC; 00411 DC_UnlockDc(Dc); 00412 } 00413 else 00414 { 00415 Dc->hFile = NULL; 00416 DPRINT1("Write to EnhMetaFile fail\n"); 00417 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE); 00418 ret = NULL; 00419 DC_UnlockDc(Dc); 00420 if (hDCRef == NULL) 00421 { 00422 NtGdiDeleteObjectApp(tempHDC); 00423 } 00424 } 00425 } 00426 else 00427 { 00428 DC_UnlockDc(Dc); 00429 } 00430 00431 return ret; 00432 } 00433 #endif 00434 00435 00436 00437 /* 00438 * @unimplemented 00439 */ 00440 HENHMETAFILE 00441 WINAPI 00442 GetEnhMetaFileA( 00443 LPCSTR lpszMetaFile) 00444 { 00445 NTSTATUS Status; 00446 LPWSTR lpszMetaFileW; 00447 HENHMETAFILE rc = 0; 00448 00449 Status = HEAP_strdupA2W ( &lpszMetaFileW, lpszMetaFile ); 00450 if (!NT_SUCCESS (Status)) 00451 SetLastError (RtlNtStatusToDosError(Status)); 00452 else 00453 { 00454 rc = NULL; 00455 00456 HEAP_free ( lpszMetaFileW ); 00457 } 00458 00459 return rc; 00460 } 00461 00462 00463 /* 00464 * @unimplemented 00465 */ 00466 UINT 00467 WINAPI 00468 GetEnhMetaFileDescriptionA( 00469 HENHMETAFILE hemf, 00470 UINT cchBuffer, 00471 LPSTR lpszDescription) 00472 { 00473 NTSTATUS Status; 00474 LPWSTR lpszDescriptionW; 00475 00476 if ( lpszDescription && cchBuffer ) 00477 { 00478 lpszDescriptionW = (LPWSTR)HEAP_alloc ( cchBuffer*sizeof(WCHAR) ); 00479 if ( !lpszDescriptionW ) 00480 { 00481 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY)); 00482 return 0; 00483 } 00484 } 00485 else 00486 lpszDescriptionW = NULL; 00487 00488 if ( lpszDescription && cchBuffer ) 00489 { 00490 Status = RtlUnicodeToMultiByteN ( lpszDescription, 00491 cchBuffer, 00492 NULL, 00493 lpszDescriptionW, 00494 cchBuffer ); 00495 HEAP_free ( lpszDescriptionW ); 00496 if ( !NT_SUCCESS(Status) ) 00497 { 00498 SetLastError (RtlNtStatusToDosError(Status)); 00499 return 0; 00500 } 00501 } 00502 00503 return 0; 00504 } 00505 00506 00507 00508 /* Unimplemented functions */ 00509 00510 HENHMETAFILE 00511 WINAPI 00512 CopyEnhMetaFileW( 00513 HENHMETAFILE hemfSrc, 00514 LPCWSTR lpszFile) 00515 { 00516 UNIMPLEMENTED; 00517 return 0; 00518 } 00519 00520 00521 HENHMETAFILE 00522 WINAPI 00523 GetEnhMetaFileW( 00524 LPCWSTR lpszMetaFile) 00525 { 00526 UNIMPLEMENTED; 00527 return 0; 00528 } 00529 00530 00531 UINT 00532 WINAPI 00533 GetEnhMetaFileDescriptionW( 00534 HENHMETAFILE hemf, 00535 UINT cchBuffer, 00536 LPWSTR lpszDescription) 00537 { 00538 UNIMPLEMENTED; 00539 return 0; 00540 } 00541 00542 00543 HDC 00544 WINAPI 00545 CreateEnhMetaFileW( 00546 HDC hdcRef, 00547 LPCWSTR lpFileName, 00548 LPCRECT lpRect, 00549 LPCWSTR lpDescription) 00550 { 00551 UNIMPLEMENTED; 00552 return 0; 00553 } Generated on Sun May 27 2012 04:38:23 for ReactOS by
1.7.6.1
|