summaryrefslogtreecommitdiff
path: root/cd/src/gdiplus/cdwnativep.cpp
blob: fffd044e81f9a5b21725da53854eb40dd1cd6b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** \file
 * \brief Windows GDI+ Native Window Driver
 *
 * See Copyright Notice in cd.h
 */

#include "cdwinp.h"
#include "cdnative.h"
#include <stdlib.h>
#include <stdio.h>


static int cdactivate(cdCtxCanvas* ctxcanvas)
{
  if (ctxcanvas->hWnd)
  {
    RECT rect;
    GetClientRect(ctxcanvas->hWnd, &rect);
    int w = rect.right - rect.left;
    int h = rect.bottom - rect.top;
    int bpp = cdGetScreenColorPlanes();

    if(ctxcanvas->canvas->w != w ||
      ctxcanvas->canvas->h != h ||
      ctxcanvas->canvas->bpp != bpp)
    {
      ctxcanvas->canvas->w = w;
      ctxcanvas->canvas->h = h;
      ctxcanvas->canvas->bpp = bpp;

      delete ctxcanvas->graphics;
      ctxcanvas->graphics = new Graphics(ctxcanvas->hWnd);

      cdwpUpdateCanvas(ctxcanvas);
    }
  }
  
  return CD_OK;
}

static void cdkillcanvas(cdCtxCanvas* ctxcanvas)
{
  cdwpKillCanvas(ctxcanvas);

  if (ctxcanvas->release_dc)
    ReleaseDC(ctxcanvas->hWnd, ctxcanvas->hDC);

  delete ctxcanvas;
}

static void cdcreatecanvas(cdCanvas* canvas, void *data)
{
  HWND hWnd = NULL;
  HDC hDC = NULL;
  Graphics* graphics;
  int release_dc = 0;
  
  if (!data)
  {
    hDC = GetDC(NULL);
    release_dc = 1;
    
    canvas->w = GetDeviceCaps(hDC, HORZRES);
    canvas->h = GetDeviceCaps(hDC, VERTRES);

    graphics = new Graphics(hDC);
  }
  else if (IsWindow((HWND)data)) 
  {
    hWnd = (HWND)data;
    release_dc = 0;

    RECT rect;
    GetClientRect(hWnd, &rect);
    canvas->w = rect.right - rect.left;
    canvas->h = rect.bottom - rect.top;

    graphics = new Graphics(hWnd);
  }
  else  /* can be a HDC or a string */
  {
    DWORD objtype = GetObjectType((HGDIOBJ)data);
    if (objtype == OBJ_DC || objtype == OBJ_MEMDC || 
        objtype == OBJ_ENHMETADC || objtype == OBJ_METADC)   
    {
      hDC = (HDC)data;
      canvas->w = GetDeviceCaps(hDC, HORZRES);
      canvas->h = GetDeviceCaps(hDC, VERTRES);
    }
    else
    {
      hDC = NULL;
      canvas->w = 0;
      canvas->h = 0;
      sscanf((char*)data,"%p %dx%d", &hDC, &canvas->w, &canvas->h); 

      if (!hDC || !canvas->w || !canvas->h)
        return;
    }

    graphics = new Graphics(hDC);
    release_dc = 0;
  }

  canvas->bpp = cdGetScreenColorPlanes();

  /* Inicializa driver WIN32 */
  cdCtxCanvas* ctxcanvas = cdwpCreateCanvas(canvas, graphics, CDW_WIN);
  ctxcanvas->hWnd = hWnd;
  ctxcanvas->hDC = hDC;
  ctxcanvas->release_dc = release_dc;
}

static void cdinittable(cdCanvas* canvas)
{
  cdwpInitTable(canvas);

  canvas->cxKillCanvas = cdkillcanvas;
  canvas->cxActivate = cdactivate;
}

static cdContext cdNativeContext =
{
  CD_CAP_ALL & ~(CD_CAP_FLUSH | CD_CAP_PLAY | CD_CAP_YAXIS | 
                 CD_CAP_FPRIMTIVES  ),
  1,
  cdcreatecanvas,
  cdinittable,
  NULL,              
  NULL,
};

extern "C" {
cdContext* cdContextNativeWindowPlus(void)
{
  return &cdNativeContext;
}
}