ReactOS 0.4.15-dev-8100-g1887773
init.c File Reference
#include <stdarg.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "gdi_private.h"
#include "mfdrv/metafiledrv.h"
#include "wine/debug.h"
Include dependency graph for init.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (metafile)
 
static BOOL MFDRV_CreateCompatibleDC (PHYSDEV orig, PHYSDEV *pdev)
 
static BOOL MFDRV_DeleteDC (PHYSDEV dev)
 
static INT MFDRV_ExtEscape (PHYSDEV dev, INT nEscape, INT cbInput, LPCVOID in_data, INT cbOutput, LPVOID out_data)
 
static UINT MFDRV_GetBoundsRect (PHYSDEV dev, RECT *rect, UINT flags)
 
static UINT MFDRV_SetBoundsRect (PHYSDEV dev, RECT *rect, UINT flags)
 
static INT MFDRV_GetDeviceCaps (PHYSDEV dev, INT cap)
 
static DCMFDRV_AllocMetaFile (void)
 
HDC WINAPI CreateMetaFileW (LPCWSTR filename)
 
HDC WINAPI CreateMetaFileA (LPCSTR filename)
 
static DCMFDRV_CloseMetaFile (HDC hdc)
 
HMETAFILE WINAPI CloseMetaFile (HDC hdc)
 
BOOL MFDRV_WriteRecord (PHYSDEV dev, METARECORD *mr, DWORD rlen)
 
BOOL MFDRV_MetaParam0 (PHYSDEV dev, short func)
 
BOOL MFDRV_MetaParam1 (PHYSDEV dev, short func, short param1)
 
BOOL MFDRV_MetaParam2 (PHYSDEV dev, short func, short param1, short param2)
 
BOOL MFDRV_MetaParam4 (PHYSDEV dev, short func, short param1, short param2, short param3, short param4)
 
BOOL MFDRV_MetaParam6 (PHYSDEV dev, short func, short param1, short param2, short param3, short param4, short param5, short param6)
 
BOOL MFDRV_MetaParam8 (PHYSDEV dev, short func, short param1, short param2, short param3, short param4, short param5, short param6, short param7, short param8)
 

Variables

static const struct gdi_dc_funcs MFDRV_Funcs
 

Function Documentation

◆ CloseMetaFile()

HMETAFILE WINAPI CloseMetaFile ( HDC  hdc)

Definition at line 452 of file init.c.

453{
454 HMETAFILE hmf;
455 METAFILEDRV_PDEVICE *physDev;
457 if (!dc) return 0;
458 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
459
460 /* Now allocate a global handle for the metafile */
461
462 hmf = MF_Create_HMETAFILE( physDev->mh );
463
464 physDev->mh = NULL; /* So it won't be deleted */
465 free_dc_ptr( dc );
466 return hmf;
467}
#define NULL
Definition: types.h:112
HMETAFILE MF_Create_HMETAFILE(METAHEADER *mh) DECLSPEC_HIDDEN
Definition: metafile.c:107
void free_dc_ptr(DC *dc) DECLSPEC_HIDDEN
static const WCHAR dc[]
HDC hdc
Definition: main.c:9
Definition: polytest.cpp:41
METAHEADER * mh
Definition: metafiledrv.h:36
static DC * MFDRV_CloseMetaFile(HDC hdc)
Definition: init.c:388

◆ CreateMetaFileA()

HDC WINAPI CreateMetaFileA ( LPCSTR  filename)

Definition at line 365 of file init.c.

366{
368 DWORD len;
369 HDC hReturnDC;
370
371 if (!filename) return CreateMetaFileW(NULL);
372
373 len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
374 filenameW = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
376
377 hReturnDC = CreateMetaFileW(filenameW);
378
380
381 return hReturnDC;
382}
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
const char * filename
Definition: ioapi.h:137
static const WCHAR filenameW[]
Definition: amstream.c:41
static HDC
Definition: imagelist.c:92
HDC WINAPI CreateMetaFileW(LPCWSTR filename)
Definition: init.c:319
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ CreateMetaFileW()

HDC WINAPI CreateMetaFileW ( LPCWSTR  filename)

Definition at line 319 of file init.c.

320{
321 HDC ret;
322 DC *dc;
323 METAFILEDRV_PDEVICE *physDev;
325 DWORD bytes_written;
326
327 TRACE("%s\n", debugstr_w(filename) );
328
329 if (!(dc = MFDRV_AllocMetaFile())) return 0;
330 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
331
332 if (filename) /* disk based metafile */
333 {
334 physDev->mh->mtType = METAFILE_DISK;
337 free_dc_ptr( dc );
338 return 0;
339 }
340 if (!WriteFile( hFile, physDev->mh, sizeof(*physDev->mh),
341 &bytes_written, NULL )) {
342 free_dc_ptr( dc );
344 return 0;
345 }
346 physDev->hFile = hFile;
347
348 /* Grow METAHEADER to include filename */
349 physDev->mh = MF_CreateMetaHeaderDisk(physDev->mh, filename, TRUE);
350 }
351 else /* memory based metafile */
352 physDev->mh->mtType = METAFILE_MEMORY;
353
354 TRACE("returning %p\n", physDev->dev.hdc);
355 ret = physDev->dev.hdc;
357 return ret;
358}
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define METAFILE_MEMORY
Definition: gdi32p.h:76
#define METAFILE_DISK
Definition: gdi32p.h:77
METAHEADER * MF_CreateMetaHeaderDisk(METAHEADER *mr, LPCVOID filename, BOOL unicode) DECLSPEC_HIDDEN
Definition: metafile.c:271
void release_dc_ptr(DC *dc) DECLSPEC_HIDDEN
#define debugstr_w
Definition: kernel32.h:32
if(dx< 0)
Definition: linetemp.h:194
#define CREATE_ALWAYS
Definition: disk.h:72
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90
#define TRACE(s)
Definition: solgame.cpp:4
struct gdi_physdev dev
Definition: metafiledrv.h:35
WORD mtType
Definition: wingdi.h:2310
int ret
static DC * MFDRV_AllocMetaFile(void)
Definition: init.c:238

Referenced by CreateMetaFileA().

◆ MFDRV_AllocMetaFile()

static DC * MFDRV_AllocMetaFile ( void  )
static

Definition at line 238 of file init.c.

239{
240 DC *dc;
241 METAFILEDRV_PDEVICE *physDev;
242
243 if (!(dc = alloc_dc_ptr( OBJ_METADC ))) return NULL;
244
245 physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
246 if (!physDev)
247 {
248 free_dc_ptr( dc );
249 return NULL;
250 }
251 if (!(physDev->mh = HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev->mh) )))
252 {
253 HeapFree( GetProcessHeap(), 0, physDev );
254 free_dc_ptr( dc );
255 return NULL;
256 }
257
258 push_dc_driver( &dc->physDev, &physDev->dev, &MFDRV_Funcs );
259
260 physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
261 physDev->handles_size = HANDLE_LIST_INC;
262 physDev->cur_handles = 0;
263
264 physDev->hFile = 0;
265
266 physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD);
267 physDev->mh->mtVersion = 0x0300;
268 physDev->mh->mtSize = physDev->mh->mtHeaderSize;
269 physDev->mh->mtNoObjects = 0;
270 physDev->mh->mtMaxRecord = 0;
271 physDev->mh->mtNoParameters = 0;
272
273 SetVirtualResolution( physDev->dev.hdc, 0, 0, 0, 0);
274
275 return dc;
276}
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned short WORD
Definition: ntddk_ex.h:93
#define HANDLE_LIST_INC
Definition: gdi32p.h:74
BOOL WINAPI SetVirtualResolution(HDC hdc, DWORD horz_res, DWORD vert_res, DWORD horz_size, DWORD vert_size)
Definition: rosglue.c:278
DC * alloc_dc_ptr(WORD magic) DECLSPEC_HIDDEN
Definition: rosglue.c:106
#define OBJ_METADC
Definition: objidl.idl:1412
WORD mtNoParameters
Definition: wingdi.h:2316
WORD mtHeaderSize
Definition: wingdi.h:2311
DWORD mtMaxRecord
Definition: wingdi.h:2315
DWORD mtSize
Definition: wingdi.h:2313
WORD mtNoObjects
Definition: wingdi.h:2314
WORD mtVersion
Definition: wingdi.h:2312
static const struct gdi_dc_funcs MFDRV_Funcs
Definition: init.c:100
struct tagMETAHEADER METAHEADER

Referenced by CreateMetaFileW().

◆ MFDRV_CloseMetaFile()

static DC * MFDRV_CloseMetaFile ( HDC  hdc)
static

Definition at line 388 of file init.c.

389{
390 DC *dc;
391 METAFILEDRV_PDEVICE *physDev;
392 DWORD bytes_written;
393
394 TRACE("(%p)\n", hdc );
395
396 if (!(dc = get_dc_ptr( hdc ))) return NULL;
397 if (GetObjectType( hdc ) != OBJ_METADC)
398 {
400 return NULL;
401 }
402 if (dc->refcount != 1)
403 {
404 FIXME( "not deleting busy DC %p refcount %u\n", hdc, dc->refcount );
406 return NULL;
407 }
408 physDev = (METAFILEDRV_PDEVICE *)dc->physDev;
409
410 /* Construct the end of metafile record - this is documented
411 * in SDK Knowledgebase Q99334.
412 */
413
414 if (!MFDRV_MetaParam0(dc->physDev, META_EOF))
415 {
416 free_dc_ptr( dc );
417 return 0;
418 }
419
420 if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
421 {
422 if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) {
423 free_dc_ptr( dc );
424 return 0;
425 }
426
427 physDev->mh->mtType = METAFILE_MEMORY; /* This is what windows does */
428 if (!WriteFile(physDev->hFile, physDev->mh, sizeof(*physDev->mh),
429 &bytes_written, NULL)) {
430 free_dc_ptr( dc );
431 return 0;
432 }
433 CloseHandle(physDev->hFile);
434 physDev->mh->mtType = METAFILE_DISK;
435 }
436
437 return dc;
438}
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define FIXME(fmt,...)
Definition: debug.h:114
#define FILE_BEGIN
Definition: compat.h:761
#define SetFilePointer
Definition: compat.h:743
DC * get_dc_ptr(HDC hdc) DECLSPEC_HIDDEN
Definition: rosglue.c:147
#define META_EOF
Definition: gdi_private.h:71
BOOL MFDRV_MetaParam0(PHYSDEV dev, short func)
Definition: init.c:518

Referenced by CloseMetaFile().

◆ MFDRV_CreateCompatibleDC()

static BOOL MFDRV_CreateCompatibleDC ( PHYSDEV  orig,
PHYSDEV pdev 
)
static

Definition at line 282 of file init.c.

283{
284 /* not supported on metafile DCs */
285 return FALSE;
286}
#define FALSE
Definition: types.h:117

◆ MFDRV_DeleteDC()

static BOOL MFDRV_DeleteDC ( PHYSDEV  dev)
static

Definition at line 292 of file init.c.

293{
295 DWORD index;
296
297 HeapFree( GetProcessHeap(), 0, physDev->mh );
298 for(index = 0; index < physDev->handles_size; index++)
299 if(physDev->handles[index])
300 GDI_hdc_not_using_object(physDev->handles[index], dev->hdc);
301 HeapFree( GetProcessHeap(), 0, physDev->handles );
302 HeapFree( GetProcessHeap(), 0, physDev );
303 return TRUE;
304}
#define index(s, c)
Definition: various.h:29
void GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc) DECLSPEC_HIDDEN
Definition: rosglue.c:182
GLuint index
Definition: glext.h:6031

◆ MFDRV_ExtEscape()

static INT MFDRV_ExtEscape ( PHYSDEV  dev,
INT  nEscape,
INT  cbInput,
LPCVOID  in_data,
INT  cbOutput,
LPVOID  out_data 
)
static

Definition at line 40 of file init.c.

42{
43 METARECORD *mr;
44 DWORD len;
45 INT ret;
46
47 if (cbOutput) return 0; /* escapes that require output cannot work in metafiles */
48
49 len = sizeof(*mr) + sizeof(WORD) + ((cbInput + 1) & ~1);
51 mr->rdSize = len / 2;
52 mr->rdFunction = META_ESCAPE;
53 mr->rdParm[0] = nEscape;
54 mr->rdParm[1] = cbInput;
55 memcpy(&(mr->rdParm[2]), in_data, cbInput);
57 HeapFree(GetProcessHeap(), 0, mr);
58 return ret;
59}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
int32_t INT
Definition: typedefs.h:58
BOOL MFDRV_WriteRecord(PHYSDEV dev, METARECORD *mr, DWORD rlen)
Definition: init.c:475
#define META_ESCAPE
Definition: wingdi.h:248

◆ MFDRV_GetBoundsRect()

static UINT MFDRV_GetBoundsRect ( PHYSDEV  dev,
RECT rect,
UINT  flags 
)
static

Definition at line 65 of file init.c.

66{
67 return 0;
68}

◆ MFDRV_GetDeviceCaps()

static INT MFDRV_GetDeviceCaps ( PHYSDEV  dev,
INT  cap 
)
static

Definition at line 85 of file init.c.

86{
87 switch(cap)
88 {
89 case TECHNOLOGY:
90 return DT_METAFILE;
91 case TEXTCAPS:
92 return 0;
93 default:
94 TRACE(" unsupported capability %d, will return 0\n", cap );
95 }
96 return 0;
97}
GLenum cap
Definition: glext.h:9639
#define TEXTCAPS
Definition: wingdi.h:806
#define DT_METAFILE
Definition: wingdi.h:712
#define TECHNOLOGY
Definition: wingdi.h:706

◆ MFDRV_MetaParam0()

BOOL MFDRV_MetaParam0 ( PHYSDEV  dev,
short  func 
)

Definition at line 518 of file init.c.

519{
520 char buffer[8];
521 METARECORD *mr = (METARECORD *)&buffer;
522
523 mr->rdSize = 3;
524 mr->rdFunction = func;
525 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
526}
GLenum func
Definition: glext.h:6028
GLuint buffer
Definition: glext.h:5915
DWORD rdSize
Definition: wingdi.h:2345
WORD rdFunction
Definition: wingdi.h:2346

Referenced by MFDRV_CloseMetaFile(), and MFDRV_SaveDC().

◆ MFDRV_MetaParam1()

BOOL MFDRV_MetaParam1 ( PHYSDEV  dev,
short  func,
short  param1 
)

Definition at line 532 of file init.c.

533{
534 char buffer[8];
535 METARECORD *mr = (METARECORD *)&buffer;
536 WORD *params = mr->rdParm;
537
538 mr->rdSize = 4;
539 mr->rdFunction = func;
540 params[0] = param1;
541 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
542}
GLenum const GLfloat * params
Definition: glext.h:5645
WORD rdParm[1]
Definition: wingdi.h:2347

Referenced by MFDRV_ExtSelectClipRgn(), MFDRV_InvertRgn(), MFDRV_PaintRgn(), MFDRV_RestoreDC(), MFDRV_SetBkMode(), MFDRV_SetMapMode(), MFDRV_SetPolyFillMode(), MFDRV_SetRelAbs(), MFDRV_SetROP2(), MFDRV_SetStretchBltMode(), and MFDRV_SetTextCharacterExtra().

◆ MFDRV_MetaParam2()

◆ MFDRV_MetaParam4()

BOOL MFDRV_MetaParam4 ( PHYSDEV  dev,
short  func,
short  param1,
short  param2,
short  param3,
short  param4 
)

Definition at line 566 of file init.c.

568{
569 char buffer[14];
570 METARECORD *mr = (METARECORD *)&buffer;
571 WORD *params = mr->rdParm;
572
573 mr->rdSize = 7;
574 mr->rdFunction = func;
575 params[0] = param4;
576 params[1] = param3;
577 params[2] = param2;
578 params[3] = param1;
579 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
580}

Referenced by MFDRV_Ellipse(), MFDRV_ExcludeClipRect(), MFDRV_ExtFloodFill(), MFDRV_FrameRgn(), MFDRV_IntersectClipRect(), MFDRV_Rectangle(), MFDRV_ScaleViewportExtEx(), MFDRV_ScaleWindowExtEx(), and MFDRV_SetPixel().

◆ MFDRV_MetaParam6()

BOOL MFDRV_MetaParam6 ( PHYSDEV  dev,
short  func,
short  param1,
short  param2,
short  param3,
short  param4,
short  param5,
short  param6 
)

Definition at line 587 of file init.c.

589{
590 char buffer[18];
591 METARECORD *mr = (METARECORD *)&buffer;
592 WORD *params = mr->rdParm;
593
594 mr->rdSize = 9;
595 mr->rdFunction = func;
596 params[0] = param6;
597 params[1] = param5;
598 params[2] = param4;
599 params[3] = param3;
600 params[4] = param2;
601 params[5] = param1;
602 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
603}

Referenced by MFDRV_PatBlt(), and MFDRV_RoundRect().

◆ MFDRV_MetaParam8()

BOOL MFDRV_MetaParam8 ( PHYSDEV  dev,
short  func,
short  param1,
short  param2,
short  param3,
short  param4,
short  param5,
short  param6,
short  param7,
short  param8 
)

Definition at line 609 of file init.c.

612{
613 char buffer[22];
614 METARECORD *mr = (METARECORD *)&buffer;
615 WORD *params = mr->rdParm;
616
617 mr->rdSize = 11;
618 mr->rdFunction = func;
619 params[0] = param8;
620 params[1] = param7;
621 params[2] = param6;
622 params[3] = param5;
623 params[4] = param4;
624 params[5] = param3;
625 params[6] = param2;
626 params[7] = param1;
627 return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
628}

Referenced by MFDRV_Arc(), MFDRV_Chord(), and MFDRV_Pie().

◆ MFDRV_SetBoundsRect()

static UINT MFDRV_SetBoundsRect ( PHYSDEV  dev,
RECT rect,
UINT  flags 
)
static

Definition at line 74 of file init.c.

75{
76 return 0;
77}

◆ MFDRV_WriteRecord()

BOOL MFDRV_WriteRecord ( PHYSDEV  dev,
METARECORD mr,
DWORD  rlen 
)

Definition at line 475 of file init.c.

476{
477 DWORD len, size;
478 METAHEADER *mh;
480
481 switch(physDev->mh->mtType)
482 {
483 case METAFILE_MEMORY:
484 len = physDev->mh->mtSize * 2 + rlen;
485 /* reallocate memory if needed */
486 size = HeapSize( GetProcessHeap(), 0, physDev->mh );
487 if (len > size)
488 {
489 /*expand size*/
490 size += size / 2 + rlen;
491 mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, size);
492 if (!mh) return FALSE;
493 physDev->mh = mh;
494 TRACE("Reallocated metafile: new size is %d\n",size);
495 }
496 memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
497 break;
498 case METAFILE_DISK:
499 TRACE("Writing record to disk\n");
500 if (!WriteFile(physDev->hFile, mr, rlen, NULL, NULL))
501 return FALSE;
502 break;
503 default:
504 ERR("Unknown metafile type %d\n", physDev->mh->mtType );
505 return FALSE;
506 }
507
508 physDev->mh->mtSize += rlen / 2;
509 physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2);
510 return TRUE;
511}
#define ERR(fmt,...)
Definition: debug.h:113
#define HeapReAlloc
Definition: compat.h:734
GLsizeiptr size
Definition: glext.h:5919
#define max(a, b)
Definition: svc.c:63
SIZE_T WINAPI HeapSize(HANDLE, DWORD, LPCVOID)

Referenced by MFDRV_CreateBrushIndirect(), MFDRV_CreateFontIndirect(), MFDRV_CreatePalette(), MFDRV_CreatePenIndirect(), MFDRV_CreateRegion(), MFDRV_DeleteObject(), MFDRV_ExtEscape(), MFDRV_MetaExtTextOut(), MFDRV_MetaParam0(), MFDRV_MetaParam1(), MFDRV_MetaParam2(), MFDRV_MetaParam4(), MFDRV_MetaParam6(), MFDRV_MetaParam8(), MFDRV_MetaPoly(), MFDRV_PolyPolygon(), MFDRV_RealizePalette(), MFDRV_SelectObject(), MFDRV_SetDIBitsToDevice(), MFDRV_StretchBlt(), and MFDRV_StretchDIBits().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( metafile  )

Variable Documentation

◆ MFDRV_Funcs

const struct gdi_dc_funcs MFDRV_Funcs
static

Definition at line 100 of file init.c.

Referenced by MFDRV_AllocMetaFile().