OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [mwin/] [wingdi.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
3
 *
4
 * Win32 API upper level graphics drawing routines
5
 */
6
#include "windows.h"
7
#include "wintern.h"
8
#include "device.h"
9
#include <stdlib.h>
10
#include <string.h>
11
 
12
#define MAXSYSCOLORS    29      /* # of COLOR_* system colors*/
13
#define MAXSTOCKOBJECTS 18      /* # of stock objects*/
14
 
15
#if ERASEMOVE
16
BOOL mwERASEMOVE = TRUE;        /* default XORMOVE repaint algorithm*/
17
#else
18
BOOL mwERASEMOVE = FALSE;       /* default ERASEMOVE repaint algorithm*/
19
#endif
20
 
21
/* cast a pointer to an integer*/
22
#if DOS_TURBOC
23
#define PTRTOINT        unsigned long
24
#else
25
#define PTRTOINT        unsigned int
26
#endif
27
 
28
static HDC      cliphdc;        /* current window cliprects*/
29
 
30
/* default bitmap for new DCs*/
31
static MWBITMAPOBJ default_bitmap = {
32
        {OBJ_BITMAP, TRUE}, 1, 1, 1, 1, 1, 1
33
};
34
 
35
static BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions,
36
                CONST RECT *lprc, LPCVOID lpszString, UINT cbCount,
37
                CONST INT *lpDx, int flags);
38
static int  MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect,
39
                UINT uFormat, int flags);
40
 
41
HDC WINAPI
42
GetDCEx(HWND hwnd,HRGN hrgnClip,DWORD flags)
43
{
44
        HDC     hdc;
45
 
46
        if(!hwnd)               /* handle NULL hwnd => desktop*/
47
                hwnd = rootwp;
48
 
49
        /* handle private DC's*/
50
        if(hwnd->owndc && !(flags & DCX_WINDOW))
51
                return hwnd->owndc;
52
 
53
        /* add caching?*/
54
        hdc = GdItemNew(struct hdc);
55
        if(!hdc)
56
                return NULL;
57
 
58
        hdc->psd = &scrdev;
59
        hdc->hwnd = hwnd;
60
        if(flags & DCX_DEFAULTCLIP) {
61
                flags &= ~DCX_DEFAULTCLIP;
62
                if(hwnd->style & WS_CLIPSIBLINGS)
63
                        flags |= DCX_CLIPSIBLINGS;
64
                if(hwnd->style & WS_CLIPCHILDREN)
65
                        flags |= DCX_CLIPCHILDREN;
66
        }
67
        hdc->flags = flags;
68
        hdc->bkmode = OPAQUE;
69
        hdc->textalign = TA_LEFT | TA_TOP | TA_NOUPDATECP;
70
        hdc->bkcolor = RGB(255, 255, 255);      /* WHITE*/
71
        hdc->textcolor = RGB(0, 0, 0);             /* BLACK*/
72
        hdc->brush = (MWBRUSHOBJ *)GetStockObject(WHITE_BRUSH);
73
        hdc->pen = (MWPENOBJ *)GetStockObject(BLACK_PEN);
74
        hdc->font = (MWFONTOBJ *)GetStockObject(SYSTEM_FONT);
75
#if UPDATEREGIONS
76
        if(hrgnClip) {
77
                /* make a copy of passed region*/
78
                hdc->region = (MWRGNOBJ *)CreateRectRgn(0, 0, 0, 0);
79
                CombineRgn((HRGN)hdc->region, hrgnClip, NULL, RGN_COPY);
80
        }
81
#endif
82
 
83
        /* make default bitmap compatible with scrdev
84
         * otherwise problems occur later because selecting
85
         * in the default bitmap overwrite planes and bpp
86
         * in a memory dc, and thus it becomes incompatible
87
         * with scrdev.
88
         */
89
        default_bitmap.planes = scrdev.planes;
90
        default_bitmap.bpp = scrdev.bpp;
91
        hdc->bitmap = &default_bitmap;
92
 
93
        hdc->drawmode = R2_COPYPEN;
94
        hdc->pt.x = 0;
95
        hdc->pt.y = 0;
96
 
97
        /* assign private DC if CS_OWNDC and not WindowDC*/
98
        if((hwnd->pClass->style & CS_OWNDC) && !(flags & DCX_WINDOW)) {
99
                /* must exclude update region due to BeginPaint GetDCEx call*/
100
                hdc->flags |= DCX_EXCLUDEUPDATE;
101
                hwnd->owndc = hdc;
102
        }
103
 
104
        return hdc;
105
}
106
 
107
HDC WINAPI
108
GetDC(HWND hwnd)
109
{
110
        /*
111
         * Exclude update regions when drawing with GetDC.
112
         * This is required because some programs use GetDC
113
         * when painting outside of BeginPaint/EndPaint, and
114
         * the update region is empty then.
115
         */
116
        return GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
117
}
118
 
119
HDC WINAPI
120
GetWindowDC(HWND hwnd)
121
{
122
        /*
123
         * Exclude update region for now, since we
124
         * don't keep track of non-client update regions yet
125
         */
126
        return GetDCEx(hwnd, NULL,DCX_WINDOW|DCX_DEFAULTCLIP|DCX_EXCLUDEUPDATE);
127
}
128
 
129
/* free a DC allocated from GetDC*/
130
int WINAPI
131
ReleaseDC(HWND hwnd, HDC hdc)
132
{
133
        /* don't delete a memory dc on release*/
134
        if(!hdc || (hdc->psd->flags&PSF_MEMORY))
135
                return 0;
136
 
137
        if(hdc == cliphdc)
138
                cliphdc = NULL;
139
 
140
        /* handle private DC's*/
141
        if(hdc->hwnd->owndc && !(hdc->flags & DCX_WINDOW))
142
                return 1;
143
 
144
        DeleteObject((HBRUSH)hdc->brush);
145
        DeleteObject((HPEN)hdc->pen);
146
#if 0 /* don't delete font resources on ReleaseDC... use DeleteObject instead*/
147
        DeleteObject((HFONT)hdc->font);
148
#endif
149
        DeleteObject((HRGN)hdc->region);
150
        /*
151
         * We can only select a bitmap in a memory DC,
152
         * so bitmaps aren't released except through DeleteDC.
153
         */
154
        DeleteObject((HBITMAP)hdc->bitmap);
155
        GdItemFree(hdc);
156
        return 1;
157
}
158
 
159
/* free a dc allocated from CreateCompatibleDC*/
160
BOOL WINAPI
161
DeleteDC(HDC hdc)
162
{
163
        /* don't delete a normal dc, only memory dc's*/
164
        if(!hdc || !(hdc->psd->flags&PSF_MEMORY))
165
                return 0;
166
 
167
        /* free allocated memory screen device*/
168
        hdc->psd->FreeMemGC(hdc->psd);
169
 
170
        /* make it look like a GetDC dc, and free it*/
171
        hdc->psd = &scrdev;
172
        return ReleaseDC(NULL, hdc);
173
}
174
 
175
void
176
MwPaintNCArea(HWND hwnd)
177
{
178
        SendMessage(hwnd, WM_NCPAINT, 0, 0L);
179
 
180
        /* for now, we always paint NC scrollbar areas*/
181
        MwPaintNCScrollbars(hwnd, NULL);
182
}
183
 
184
HDC WINAPI
185
BeginPaint(HWND hwnd, LPPAINTSTRUCT lpPaint)
186
{
187
        HDC     hdc;
188
 
189
        /* first update non-client area*/
190
        if(mwforceNCpaint || hwnd->paintNC != mwpaintNC) {
191
                MwPaintNCArea(hwnd);
192
                hwnd->paintNC = mwpaintNC;
193
        }
194
 
195
        /* If ERASEMOVE:
196
         * Don't allow windows to repaint while user is moving
197
         * a window.  Instead, just erase backgrounds
198
         * and indicate delayed painting required, which
199
         * will occur after user completes window move.
200
         */
201
        if(mwERASEMOVE && dragwp) {
202
                hdc = NULL;
203
                lpPaint->fErase = !DefWindowProc(hwnd, WM_ERASEBKGND, 0, 0L);
204
                hwnd->gotPaintMsg = PAINT_DELAYPAINT;
205
        } else {
206
                HideCaret(hwnd);
207
 
208
                /* FIXME: mdemo requires update excluded or draw errors occur*/
209
                hdc = GetDCEx(hwnd, NULL, DCX_DEFAULTCLIP
210
                                |DCX_EXCLUDEUPDATE);    /* FIXME - bug*/
211
 
212
                /* erase client background*/
213
                lpPaint->fErase = !SendMessage(hwnd, WM_ERASEBKGND, (WPARAM)hdc,
214
                        0L);
215
        }
216
        lpPaint->hdc = hdc;
217
 
218
        GetUpdateRect(hwnd, &lpPaint->rcPaint, FALSE);
219
        return hdc;
220
}
221
 
222
BOOL WINAPI
223
EndPaint(HWND hwnd, CONST PAINTSTRUCT *lpPaint)
224
{
225
        ReleaseDC(hwnd, lpPaint->hdc);
226
#if UPDATEREGIONS
227
        /* don't clear update region until done dragging*/
228
        if(mwERASEMOVE && !dragwp)
229
                GdSetRectRegion(hwnd->update, 0, 0, 0, 0);
230
#endif
231
        ShowCaret(hwnd);
232
        return TRUE;
233
}
234
 
235
COLORREF WINAPI
236
SetTextColor(HDC hdc, COLORREF crColor)
237
{
238
        COLORREF        oldtextcolor;
239
 
240
        if (!hdc)
241
                return CLR_INVALID;
242
        oldtextcolor = hdc->textcolor;
243
        hdc->textcolor = (MWCOLORVAL)crColor;
244
        return oldtextcolor;
245
}
246
 
247
COLORREF WINAPI
248
SetBkColor(HDC hdc, COLORREF crColor)
249
{
250
        COLORREF        oldbkcolor;
251
 
252
        if (!hdc)
253
                return CLR_INVALID;
254
        oldbkcolor = hdc->bkcolor;
255
        hdc->bkcolor = crColor;
256
        return oldbkcolor;
257
}
258
 
259
int WINAPI
260
SetBkMode(HDC hdc, int iBkMode)
261
{
262
        int     oldbkmode;
263
 
264
        if(!hdc)
265
                return 0;
266
        oldbkmode = hdc->bkmode;
267
        hdc->bkmode = iBkMode;
268
        return oldbkmode;
269
}
270
 
271
UINT WINAPI
272
SetTextAlign(HDC hdc, UINT fMode)
273
{
274
        UINT    oldfMode;
275
 
276
        if(!hdc)
277
                return GDI_ERROR;
278
        oldfMode = hdc->textalign;
279
        hdc->textalign = fMode;
280
        return oldfMode;
281
}
282
 
283
/* FIXME: releasing a DC does NOT change back the drawing mode!*/
284
int WINAPI
285
SetROP2(HDC hdc, int fnDrawMode)
286
{
287
        int     newmode, oldmode;
288
 
289
        if(!hdc || (fnDrawMode <= 0 || fnDrawMode > R2_LAST))
290
                return 0;
291
 
292
        oldmode = hdc->drawmode;
293
        newmode = fnDrawMode - 1;       /* map to MWMODE_xxx*/
294
        hdc->drawmode = newmode;
295
        GdSetMode(newmode);
296
        return oldmode;
297
}
298
 
299
/*
300
 * Setup clip region from device context's associated window or bitmap.
301
 * Memory DC's are always associated with the desktop window, and are
302
 * always visible.  Return the DC's hwnd if window is visible.
303
 */
304
HWND
305
MwPrepareDC(HDC hdc)
306
{
307
        HWND    hwnd;
308
 
309
        if(!hdc || !hdc->hwnd)
310
                return NULL;
311
 
312
        hwnd = hdc->hwnd;
313
        if (hwnd->unmapcount)
314
                return NULL;
315
 
316
        /*
317
         * If the window is not the currently clipped one, then
318
         * make it the current one and define its clip rectangles.
319
         */
320
        if(hdc != cliphdc) {
321
                /* clip memory dc's to the bitmap size*/
322
                if(hdc->psd->flags&PSF_MEMORY) {
323
#if DYNAMICREGIONS
324
                        GdSetClipRegion(hdc->psd,
325
                                GdAllocRectRegion(0, 0, hdc->psd->xvirtres,
326
                                        hdc->psd->yvirtres));
327
#else
328
                        static MWCLIPRECT crc = {0, 0, 0, 0};
329
 
330
                        crc.width = hdc->psd->xvirtres;
331
                        crc.height = hdc->psd->yvirtres;
332
                        GdSetClipRects(hdc->psd, 1, &crc);
333
#endif
334
                } else MwSetClipWindow(hdc);
335
                cliphdc = hdc;
336
        }
337
 
338
        return hwnd;
339
}
340
 
341
/* return RGB value at specified coordinates*/
342
COLORREF WINAPI
343
GetPixel(HDC hdc, int x, int y)
344
{
345
        HWND            hwnd;
346
        POINT           pt;
347
        MWPIXELVAL      pixel;
348
        MWPALENTRY      rgb;
349
 
350
        hwnd = MwPrepareDC(hdc);
351
        if(!hwnd)
352
                return CLR_INVALID;
353
        pt.x = x;
354
        pt.y = y;
355
        if(MwIsClientDC(hdc))
356
                ClientToScreen(hwnd, &pt);
357
 
358
        /* read pixel value*/
359
        GdReadArea(hdc->psd, pt.x, pt.y, 1, 1, &pixel);
360
 
361
        switch(hdc->psd->pixtype) {
362
        case MWPF_TRUECOLOR0888:
363
        case MWPF_TRUECOLOR888:
364
                /* create RGB colorval from 8/8/8 pixel*/
365
                return PIXEL888TOCOLORVAL(pixel);
366
 
367
        case MWPF_TRUECOLOR565:
368
                /* create RGB colorval from 5/6/5 pixel*/
369
                return PIXEL565TOCOLORVAL(pixel);
370
 
371
        case MWPF_TRUECOLOR555:
372
                /* create RGB colorval from 5/5/5 pixel*/
373
                return PIXEL555TOCOLORVAL(pixel);
374
 
375
        case MWPF_TRUECOLOR332:
376
                /* create RGB colorval from 3/3/2 pixel*/
377
                return PIXEL332TOCOLORVAL(pixel);
378
 
379
        case MWPF_PALETTE:
380
                if(GdGetPalette(hdc->psd, pixel, 1, &rgb))
381
                        return RGB(rgb.r, rgb.g, rgb.b);
382
        }
383
        return CLR_INVALID;
384
}
385
 
386
COLORREF WINAPI
387
SetPixel(HDC hdc, int x, int y, COLORREF crColor)
388
{
389
        HWND            hwnd;
390
        POINT           pt;
391
 
392
        hwnd = MwPrepareDC(hdc);
393
        if(!hwnd)
394
                return 0;        /* doesn't return previous color*/
395
        pt.x = x;
396
        pt.y = y;
397
        if(MwIsClientDC(hdc))
398
                ClientToScreen(hwnd, &pt);
399
 
400
        /* draw point in passed color*/
401
        GdSetForeground(GdFindColor(crColor));
402
        GdPoint(hdc->psd, pt.x, pt.y);
403
        return 0;                /* doesn't return previous color*/
404
}
405
 
406
BOOL WINAPI
407
MoveToEx(HDC hdc, int x, int y, LPPOINT lpPoint)
408
{
409
        if(!hdc)
410
                return FALSE;
411
        if(lpPoint)
412
                *lpPoint = hdc->pt;
413
        hdc->pt.x = x;
414
        hdc->pt.y = y;
415
        return TRUE;
416
}
417
 
418
BOOL WINAPI
419
LineTo(HDC hdc, int x, int y)
420
{
421
        HWND            hwnd;
422
        POINT           beg, end;
423
 
424
        hwnd = MwPrepareDC(hdc);
425
        if(!hwnd)
426
                return FALSE;
427
 
428
        beg.x = hdc->pt.x;
429
        beg.y = hdc->pt.y;
430
        end.x = x;
431
        end.y = y;
432
        if(MwIsClientDC(hdc)) {
433
                ClientToScreen(hwnd, &beg);
434
                ClientToScreen(hwnd, &end);
435
        }
436
 
437
        /* draw line in current pen color*/
438
        if(hdc->pen->style != PS_NULL) {
439
                GdSetForeground(GdFindColor(hdc->pen->color));
440
                /* don't draw last point*/
441
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
442
        }
443
        hdc->pt.x = x;
444
        hdc->pt.y = y;
445
        return TRUE;
446
}
447
 
448
/* draw line segments by connecting passed points*/
449
BOOL WINAPI
450
Polyline(HDC hdc, CONST POINT *lppt, int cPoints)
451
{
452
        HWND            hwnd;
453
        POINT           beg, end;
454
 
455
        if(cPoints <= 1)
456
                return FALSE;
457
 
458
        hwnd = MwPrepareDC(hdc);
459
        if(!hwnd)
460
                return FALSE;
461
 
462
        if(hdc->pen->style == PS_NULL)
463
                return TRUE;
464
 
465
        /* draw line in current pen color*/
466
        GdSetForeground(GdFindColor(hdc->pen->color));
467
 
468
        beg = *lppt++;
469
        if(MwIsClientDC(hdc))
470
                ClientToScreen(hwnd, &beg);
471
        while(--cPoints > 0) {
472
                end = *lppt++;
473
                if(MwIsClientDC(hdc))
474
                        ClientToScreen(hwnd, &end);
475
 
476
                /* don't draw last point*/
477
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
478
 
479
                beg = end;
480
        }
481
        return TRUE;
482
}
483
 
484
BOOL WINAPI
485
Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
486
{
487
        HWND    hwnd;
488
        RECT    rc;
489
 
490
        hwnd = MwPrepareDC(hdc);
491
        if(!hwnd)
492
                return FALSE;
493
 
494
        SetRect(&rc, nLeft, nTop, nRight, nBottom);
495
        if(MwIsClientDC(hdc))
496
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
497
 
498
        /* draw rectangle in current pen color*/
499
        if(hdc->pen->style != PS_NULL) {
500
                GdSetForeground(GdFindColor(hdc->pen->color));
501
                GdRect(hdc->psd, rc.left, rc.top,
502
                        rc.right - rc.left, rc.bottom - rc.top);
503
        }
504
 
505
        /* fill rectangle in current brush color*/
506
        if(hdc->brush->style != BS_NULL) {
507
                InflateRect(&rc, -1, -1);
508
                GdSetForeground(GdFindColor(hdc->brush->color));
509
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
510
                        rc.bottom - rc.top);
511
        }
512
 
513
        return TRUE;
514
}
515
 
516
BOOL WINAPI
517
Ellipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
518
{
519
        HWND    hwnd;
520
        int     rx, ry;
521
        RECT    rc;
522
 
523
        hwnd = MwPrepareDC(hdc);
524
        if(!hwnd)
525
                return FALSE;
526
 
527
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
528
        if(MwIsClientDC(hdc))
529
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
530
 
531
        rx = (rc.right - rc.left)/2 - 1;
532
        ry = (rc.bottom - rc.top)/2 - 1;
533
        rc.left += rx;
534
        rc.top += ry;
535
 
536
        /* fill ellipse in current brush color*/
537
        if(hdc->brush->style != BS_NULL) {
538
                InflateRect(&rc, -1, -1);
539
                GdSetForeground(GdFindColor(hdc->brush->color));
540
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE);
541
        }
542
 
543
        /* draw ellipse outline in current pen color*/
544
        if(hdc->pen->style != PS_NULL) {
545
                GdSetForeground(GdFindColor(hdc->pen->color));
546
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE);
547
        }
548
 
549
        return TRUE;
550
}
551
 
552
static void
553
dopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
554
        int ax, int ay, int bx, int by, int type)
555
{
556
        HWND    hwnd;
557
        int     rx, ry;
558
        RECT    rc, rc2;
559
 
560
        hwnd = MwPrepareDC(hdc);
561
        if(!hwnd)
562
                return;
563
 
564
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
565
        SetRect(&rc2, ax, ay, bx, by);
566
        if(MwIsClientDC(hdc)) {
567
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
568
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2);
569
        }
570
 
571
        rx = (rc.right - rc.left)/2 - 1;
572
        ry = (rc.bottom - rc.top)/2 - 1;
573
        rc.left += rx;
574
        rc.top += ry;
575
 
576
        /* fill ellipse in current brush color*/
577
        if(hdc->brush->style != BS_NULL && type == MWPIE) {
578
                GdSetForeground(GdFindColor(hdc->brush->color));
579
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
580
                        rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE);
581
        }
582
 
583
        /* draw ellipse outline in current pen color*/
584
        if(hdc->pen->style != PS_NULL) {
585
                GdSetForeground(GdFindColor(hdc->pen->color));
586
                if(type == MWPIE)
587
                        type = MWARC;   /* MWARCOUTLINE?*/
588
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
589
                        rc2.left, rc2.top, rc2.right, rc2.bottom, type);
590
        }
591
}
592
 
593
BOOL WINAPI
594
Arc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
595
        int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc)
596
{
597
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
598
                nXStartArc, nYStartArc, nXEndArc, nYEndArc, MWARC);
599
        return TRUE;
600
}
601
 
602
BOOL WINAPI
603
Pie(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
604
        int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2)
605
{
606
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
607
                nXRadial1, nYRadial1, nXRadial2, nYRadial2, MWPIE);
608
        return TRUE;
609
}
610
 
611
BOOL WINAPI
612
Polygon(HDC hdc, CONST POINT *lpPoints, int nCount)
613
{
614
        HWND    hwnd;
615
        int     i;
616
        LPPOINT pp, ppAlloc = NULL;
617
 
618
        hwnd = MwPrepareDC(hdc);
619
        if(!hwnd)
620
                return FALSE;
621
 
622
        if(MwIsClientDC(hdc)) {
623
                /* convert points to client coords*/
624
                ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT));
625
                if(!ppAlloc)
626
                        return FALSE;
627
                memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT));
628
                pp = ppAlloc;
629
                for(i=0; i<nCount; ++i)
630
                        ClientToScreen(hwnd, pp++);
631
                pp = ppAlloc;
632
        } else pp = (LPPOINT)lpPoints;
633
 
634
        /* fill polygon in current brush color*/
635
        if(hdc->brush->style != BS_NULL) {
636
                GdSetForeground(GdFindColor(hdc->brush->color));
637
                GdFillPoly(hdc->psd, nCount, pp);
638
        }
639
 
640
        /* draw polygon outline in current pen color*/
641
        if(hdc->pen->style != PS_NULL) {
642
                GdSetForeground(GdFindColor(hdc->pen->color));
643
                GdPoly(hdc->psd, nCount, pp);
644
        }
645
 
646
        if(ppAlloc)
647
                free(ppAlloc);
648
        return TRUE;
649
}
650
 
651
/* draw nCount polygons*/
652
BOOL WINAPI
653
PolyPolygon(HDC hdc, CONST POINT *lpPoints, LPINT lpPolyCounts, int nCount)
654
{
655
        while(--nCount >= 0) {
656
                if (!Polygon(hdc, lpPoints, *lpPolyCounts))
657
                        return FALSE;
658
                lpPoints += *lpPolyCounts++;
659
        }
660
        return TRUE;
661
}
662
 
663
int WINAPI
664
FillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr)
665
{
666
        HWND            hwnd;
667
        RECT            rc;
668
        MWBRUSHOBJ *    obr = (MWBRUSHOBJ *)hbr;
669
        COLORREF        crFill;
670
 
671
        hwnd = MwPrepareDC(hdc);
672
        if(!hwnd || !obr)
673
                return FALSE;
674
 
675
        if(!lprc) {
676
                if(MwIsClientDC(hdc))
677
                        GetClientRect(hwnd, &rc);
678
                else
679
                        GetWindowRect(hwnd, &rc);
680
                lprc = &rc;
681
        } else
682
                rc = *lprc;
683
        if(MwIsClientDC(hdc))
684
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
685
 
686
        /* handle COLOR_xxx + 1 passed as HBRUSH*/
687
        if((PTRTOINT)obr <= MAXSYSCOLORS)
688
                crFill = GetSysColor((int)obr-1);
689
        else {
690
                /* get color from passed HBRUSH*/
691
                if(obr->style == BS_NULL)
692
                        return TRUE;
693
                crFill = obr->color;
694
        }
695
 
696
        /* fill rectangle in passed brush color*/
697
        GdSetForeground(GdFindColor(crFill));
698
        GdFillRect(hdc->psd, rc.left, rc.top,
699
                rc.right - rc.left, rc.bottom - rc.top);
700
        return TRUE;
701
}
702
 
703
/* ascii*/
704
BOOL WINAPI
705
TextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString)
706
{
707
        /* kaffe port wants MWTF_UTF8 here...*/
708
        return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL,
709
                MWTF_ASCII);
710
}
711
 
712
/* ascii*/
713
BOOL WINAPI
714
ExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
715
        LPCSTR lpszString, UINT cbCount, CONST INT *lpDx)
716
{
717
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
718
                cbCount, lpDx, MWTF_ASCII);
719
}
720
 
721
/* unicode*/
722
BOOL WINAPI
723
ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
724
        LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx)
725
{
726
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
727
                cbCount, lpDx, MWTF_UC16);
728
}
729
 
730
/* internal version of ExtTextOut, passed flags for text data type*/
731
static BOOL
732
MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
733
        LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags)
734
{
735
        HWND    hwnd;
736
        POINT   pt;
737
        RECT    rc;
738
 
739
        hwnd = MwPrepareDC(hdc);
740
        if(!hwnd)
741
                return FALSE;
742
 
743
        pt.x = x;
744
        pt.y = y;
745
        if(MwIsClientDC(hdc))
746
                ClientToScreen(hwnd, &pt);
747
 
748
        /* optionally fill passed rectangle*/
749
        if(lprc && (fuOptions&ETO_OPAQUE)) {
750
                rc = *lprc;
751
                if(MwIsClientDC(hdc))
752
                        MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
753
 
754
                /* fill rectangle with current background color*/
755
                GdSetForeground(GdFindColor(hdc->bkcolor));
756
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
757
                        rc.bottom - rc.top);
758
                GdSetUseBackground(FALSE);
759
        } else {
760
                /* use current background mode for text background draw*/
761
                GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE);
762
                /* always set background color in case GdArea is
763
                 * used to draw, which compares gr_foreground != gr_background
764
                 * if gr_usebg is false...
765
                 */
766
                /*if(hdc->bkmode == OPAQUE)*/
767
                        GdSetBackground(GdFindColor(hdc->bkcolor));
768
        }
769
 
770
        /* nyi: lpDx*/
771
 
772
        /* draw text in current text foreground and background color*/
773
        GdSetForeground(GdFindColor(hdc->textcolor));
774
        GdSetFont(hdc->font->pfont);
775
 
776
        /* this whole text alignment thing needs rewriting*/
777
        if((hdc->textalign & TA_BASELINE) == TA_BASELINE) {
778
                 /* this is not right... changed for kaffe port
779
                flags |= MWTF_TOP;
780
                 */
781
                flags |= MWTF_BASELINE;
782
        } else if(hdc->textalign & TA_BOTTOM) {
783
                MWCOORD ph, pw, pb;
784
 
785
                if(lprc)
786
                        pt.y += lprc->bottom - lprc->top;
787
                else {
788
                        GdGetTextSize(hdc->font->pfont, lpszString, cbCount,
789
                                &pw, &ph, &pb, flags);
790
                        pt.y += ph;
791
                }
792
                flags |= MWTF_BOTTOM;
793
        } else
794
                flags |= MWTF_TOP;
795
        GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags);
796
 
797
        return TRUE;
798
}
799
 
800
/* ascii*/
801
int WINAPI
802
DrawTextA(HDC hdc, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
803
{
804
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_ASCII);
805
}
806
 
807
/* unicode*/
808
int WINAPI
809
DrawTextW(HDC hdc, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
810
{
811
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_UC16);
812
}
813
 
814
/* note: many DT_x aren't implemented in this function*/
815
/* internal version of DrawText, passed flags for text data type*/
816
static int
817
MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat,
818
        int flags)
819
{
820
        MWCOORD x, y, width, height, baseline;
821
 
822
        if(nCount == -1)
823
                nCount = strlen(lpString);
824
 
825
        if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) {
826
                if(!hdc)
827
                        return 0;
828
                GdGetTextSize(hdc->font->pfont, lpString, nCount,
829
                        &width, &height, &baseline, MWTF_ASCII);
830
        }
831
        x = lpRect->left;
832
        y = lpRect->top;
833
 
834
        if(uFormat & DT_CALCRECT) {
835
                lpRect->right = x + width;
836
                lpRect->bottom = y + height;
837
                return height;
838
        }
839
 
840
        if(uFormat & DT_CENTER)
841
                x = (lpRect->left + lpRect->right - width) / 2;
842
        else if(uFormat & DT_RIGHT)
843
                x += lpRect->right - width;
844
 
845
        /* draw text at DT_TOP using current fg, bg and bkmode*/
846
        MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags);
847
        return height;
848
}
849
 
850
/* Microwindows only*/
851
BOOL WINAPI
852
DrawDIB(HDC hdc,int x,int y,PMWIMAGEHDR pimage)
853
{
854
        HWND            hwnd;
855
        POINT           pt;
856
 
857
        hwnd = MwPrepareDC(hdc);
858
        if(!hwnd || !pimage)
859
                return FALSE;
860
        pt.x = x;
861
        pt.y = y;
862
        if(MwIsClientDC(hdc))
863
                ClientToScreen(hwnd, &pt);
864
 
865
        GdDrawImage(hdc->psd, pt.x, pt.y, pimage);
866
        return TRUE;
867
}
868
 
869
/* define color scheme: A (tan), B (winstd) or C (old)*/
870
#if ELKS
871
#define B
872
#else
873
#define A
874
#endif
875
 
876
#define A_RGB(r,g,b)
877
#define B_RGB(r,g,b)
878
#define C_RGB(r,g,b)
879
 
880
#ifdef A
881
#undef  A_RGB
882
#define A_RGB(r,g,b)    RGB(r,g,b),
883
#endif
884
#ifdef B
885
#undef  B_RGB
886
#define B_RGB(r,g,b)    RGB(r,g,b),
887
#endif
888
#ifdef C
889
#undef  C_RGB
890
#define C_RGB(r,g,b)    RGB(r,g,b),
891
#endif
892
 
893
static COLORREF sysColors[MAXSYSCOLORS] = {
894
        RGB(192, 192, 192),     /* COLOR_SCROLLBAR          0*/
895
        RGB(  0, 128, 128),     /* COLOR_BACKGROUND          */
896
        A_RGB(128,   0,   0)      /* COLOR_ACTIVECAPTION       */
897
        B_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
898
        C_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
899
        A_RGB(162, 141, 104)    /* COLOR_INACTIVECAPTION     */
900
        B_RGB(128, 128, 128)    /* COLOR_INACTIVECAPTION     */
901
        C_RGB(  0,  64, 128)     /* COLOR_INACTIVECAPTION     */
902
        RGB(192, 192, 192),     /* COLOR_MENU                */
903
        RGB(255, 255, 255),     /* COLOR_WINDOW             5*/
904
        RGB(  0,   0,   0),     /* COLOR_WINDOWFRAME         */
905
        RGB(  0,   0,   0),     /* COLOR_MENUTEXT            */
906
        RGB(  0,   0,   0),     /* COLOR_WINDOWTEXT          */
907
        RGB(255, 255, 255),     /* COLOR_CAPTIONTEXT         */
908
        RGB(192, 192, 192),     /* COLOR_ACTIVEBORDER      10*/
909
        RGB(192, 192, 192),     /* COLOR_INACTIVEBORDER      */
910
        RGB(128, 128, 128),     /* COLOR_APPWORKSPACE        */
911
        RGB(128,   0,   0),     /* COLOR_HIGHLIGHT           */
912
        RGB(255, 255, 255),     /* COLOR_HIGHLIGHTTEXT       */
913
        A_RGB(213, 204, 187)    /* COLOR_BTNFACE           15*/
914
        B_RGB(192, 192, 192)    /* COLOR_BTNFACE           15*/
915
        C_RGB(160, 160, 160)    /* COLOR_BTNFACE           15*/
916
        A_RGB(162, 141, 104)    /* COLOR_BTNSHADOW           */
917
        B_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
918
        C_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
919
        RGB( 64,  64,  64),     /* COLOR_GRAYTEXT            */
920
        RGB(  0,   0,   0),     /* COLOR_BTNTEXT             */
921
        RGB(192, 192, 192),     /* COLOR_INACTIVECAPTIONTEXT */
922
        A_RGB(234, 230, 221)    /* COLOR_BTNHIGHLIGHT      20*/
923
        B_RGB(255, 255, 255)    /* COLOR_BTNHIGHLIGHT      20*/
924
        C_RGB(223, 223, 223)    /* COLOR_BTNHIGHLIGHT      20*/
925
        RGB(  0,   0,   0),     /* COLOR_3DDKSHADOW          */
926
        A_RGB(213, 204, 187)    /* COLOR_3DLIGHT             */
927
        B_RGB(223, 223, 223)    /* COLOR_3DLIGHT             */
928
        C_RGB(192, 192, 192)    /* COLOR_3DLIGHT             */
929
        RGB(  0,   0,   0),     /* COLOR_INFOTEXT            */
930
        RGB(225, 255, 255),     /* COLOR_INFOBK              */
931
        RGB(184, 180, 184),     /* COLOR_ALTERNATEBTNFACE  25*/
932
        RGB(  0,   0, 255),     /* COLOR_HOTLIGHT              */
933
        RGB( 16, 132, 208),     /* COLOR_GRADIENTACTIVECAPTION */
934
        RGB(184, 180, 184)      /* COLOR_GRADIENTINACTIVECAPTION 28*/
935
};
936
 
937
DWORD WINAPI
938
GetSysColor(int nIndex)
939
{
940
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS)
941
                return sysColors[nIndex];
942
        return 0;
943
}
944
 
945
COLORREF WINAPI
946
SetSysColor(int nIndex, COLORREF crColor)       /* Microwindows only*/
947
{
948
        COLORREF oldColor;
949
 
950
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS) {
951
                oldColor = sysColors[nIndex];
952
                sysColors[nIndex] = crColor;
953
                return oldColor;
954
        }
955
        return 0;
956
}
957
 
958
static MWBRUSHOBJ OBJ_WHITE_BRUSH = {
959
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(255, 255, 255)
960
};
961
 
962
static MWBRUSHOBJ OBJ_LTGRAY_BRUSH = {
963
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(192, 192, 192)
964
};
965
 
966
static MWBRUSHOBJ OBJ_GRAY_BRUSH = {
967
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(128, 128, 128)
968
};
969
 
970
static MWBRUSHOBJ OBJ_DKGRAY_BRUSH = {
971
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(32, 32, 32)
972
};
973
 
974
static MWBRUSHOBJ OBJ_BLACK_BRUSH = {
975
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(0, 0, 0)
976
};
977
 
978
static MWBRUSHOBJ OBJ_NULL_BRUSH = {
979
        {OBJ_BRUSH, TRUE}, BS_NULL, RGB(0, 0, 0)
980
};
981
 
982
static MWPENOBJ OBJ_WHITE_PEN = {
983
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(255, 255, 255)
984
};
985
 
986
static MWPENOBJ OBJ_BLACK_PEN = {
987
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(0, 0, 0)
988
};
989
 
990
static MWPENOBJ OBJ_NULL_PEN = {
991
        {OBJ_PEN, TRUE}, PS_NULL, RGB(0, 0, 0)
992
};
993
 
994
static MWFONTOBJ OBJ_OEM_FIXED_FONT = {
995
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
996
};
997
 
998
static MWFONTOBJ OBJ_ANSI_FIXED_FONT = {
999
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
1000
};
1001
 
1002
static MWFONTOBJ OBJ_ANSI_VAR_FONT = {
1003
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
1004
};
1005
 
1006
static MWFONTOBJ OBJ_SYSTEM_FONT = {
1007
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
1008
};
1009
 
1010
static MWFONTOBJ OBJ_DEVICE_DEFAULT_FONT = {
1011
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
1012
};
1013
 
1014
static MWFONTOBJ OBJ_SYSTEM_FIXED_FONT = {
1015
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
1016
};
1017
 
1018
static MWFONTOBJ OBJ_DEFAULT_GUI_FONT = {
1019
        {OBJ_FONT, TRUE}, NULL, MWFONT_GUI_VAR
1020
};
1021
 
1022
static struct hgdiobj *stockObjects[MAXSTOCKOBJECTS] = {
1023
        (struct hgdiobj *)&OBJ_WHITE_BRUSH,             /* WHITE_BRUSH*/
1024
        (struct hgdiobj *)&OBJ_LTGRAY_BRUSH,            /* LTGRAY_BRUSH*/
1025
        (struct hgdiobj *)&OBJ_GRAY_BRUSH,              /* GRAY_BRUSH*/
1026
        (struct hgdiobj *)&OBJ_DKGRAY_BRUSH,            /* DKGRAY_BRUSH*/
1027
        (struct hgdiobj *)&OBJ_BLACK_BRUSH,             /* BLACK_BRUSH*/
1028
        (struct hgdiobj *)&OBJ_NULL_BRUSH,              /* NULL_BRUSH*/
1029
        (struct hgdiobj *)&OBJ_WHITE_PEN,               /* WHITE_PEN*/
1030
        (struct hgdiobj *)&OBJ_BLACK_PEN,               /* BLACK_PEN*/
1031
        (struct hgdiobj *)&OBJ_NULL_PEN,                /* NULL_PEN*/
1032
        (struct hgdiobj *)NULL,
1033
        (struct hgdiobj *)&OBJ_OEM_FIXED_FONT,          /* OEM_FIXED_FONT*/
1034
        (struct hgdiobj *)&OBJ_ANSI_FIXED_FONT,         /* ANSI_FIXED_FONT*/
1035
        (struct hgdiobj *)&OBJ_ANSI_VAR_FONT,           /* ANSI_VAR_FONT*/
1036
        (struct hgdiobj *)&OBJ_SYSTEM_FONT,             /* SYSTEM_FONT*/
1037
        (struct hgdiobj *)&OBJ_DEVICE_DEFAULT_FONT,     /* DEVICE_DEFAULT_FONT*/
1038
        (struct hgdiobj *)NULL,                         /* DEFAULT_PALETTE*/
1039
        (struct hgdiobj *)&OBJ_SYSTEM_FIXED_FONT,       /* SYSTEM_FIXED_FONT*/
1040
        (struct hgdiobj *)&OBJ_DEFAULT_GUI_FONT         /* DEFAULT_GUI_FONT*/
1041
};
1042
 
1043
HGDIOBJ WINAPI
1044
GetStockObject(int nObject)
1045
{
1046
        HGDIOBJ         pObj;
1047
        MWFONTOBJ *     pFont;
1048
 
1049
        if(nObject >= 0 && nObject < MAXSTOCKOBJECTS) {
1050
                pObj = stockObjects[nObject];
1051
 
1052
                /* create stock fonts on first access*/
1053
                if(pObj->hdr.type == OBJ_FONT) {
1054
                        pFont = (MWFONTOBJ *)pObj;
1055
                        if(pFont->pfont == NULL) {
1056
                                pFont->pfont = GdCreateFont(&scrdev,
1057
                                        pFont->name, 0, NULL);
1058
                        }
1059
                        return pObj;
1060
                }
1061
 
1062
                /* implement multiple color schemes with
1063
                 * standard background brushes...
1064
                 */
1065
                switch(nObject) {
1066
                case LTGRAY_BRUSH:
1067
                case GRAY_BRUSH:
1068
                        ((MWBRUSHOBJ *)pObj)->color =GetSysColor(COLOR_BTNFACE);
1069
                        break;
1070
                case DKGRAY_BRUSH:
1071
                        ((MWBRUSHOBJ *)pObj)->color =
1072
                                GetSysColor(COLOR_BTNSHADOW);
1073
                        break;
1074
                }
1075
                return pObj;
1076
        }
1077
        return NULL;
1078
}
1079
 
1080
HGDIOBJ WINAPI
1081
SelectObject(HDC hdc, HGDIOBJ hObject)
1082
{
1083
        HGDIOBJ         objOrg;
1084
        MWBITMAPOBJ *   pb;
1085
 
1086
        if(!hdc || !hObject)
1087
                return NULL;
1088
 
1089
        switch(hObject->hdr.type) {
1090
        case OBJ_PEN:
1091
                objOrg = (HGDIOBJ)hdc->pen;
1092
                hdc->pen = (MWPENOBJ *)hObject;
1093
                break;
1094
        case OBJ_BRUSH:
1095
                objOrg = (HGDIOBJ)hdc->brush;
1096
                hdc->brush = (MWBRUSHOBJ *)hObject;
1097
                break;
1098
        case OBJ_FONT:
1099
                objOrg = (HGDIOBJ)hdc->font;
1100
                hdc->font = (MWFONTOBJ *)hObject;
1101
                break;
1102
        case OBJ_BITMAP:
1103
                /* must be memory dc to select bitmap*/
1104
                if(!(hdc->psd->flags&PSF_MEMORY))
1105
                        return NULL;
1106
                objOrg = (HGDIOBJ)hdc->bitmap;
1107
 
1108
                /* setup mem dc for drawing into bitmap*/
1109
                pb = (MWBITMAPOBJ *)hObject;
1110
 
1111
                /* init memory context*/
1112
                if (!hdc->psd->MapMemGC(hdc->psd, pb->width, pb->height,
1113
                        pb->planes, pb->bpp, pb->linelen, pb->size,
1114
                        &pb->bits[0]))
1115
                                return NULL;
1116
 
1117
                hdc->bitmap = (MWBITMAPOBJ *)hObject;
1118
                break;
1119
#if UPDATEREGIONS
1120
        case OBJ_REGION:
1121
                /*objOrg = (HGDIOBJ)hdc->region;*/
1122
                objOrg = NULL;  /* FIXME? hdc->region is destroyed below*/
1123
                SelectClipRgn(hdc, (HRGN)hObject);
1124
                break;
1125
#endif
1126
        default:
1127
                return NULL;
1128
        }
1129
 
1130
        return objOrg;
1131
}
1132
 
1133
BOOL WINAPI
1134
DeleteObject(HGDIOBJ hObject)
1135
{
1136
        if(!hObject || hObject->hdr.stockobj)
1137
                return FALSE;
1138
        if(hObject->hdr.type == OBJ_FONT)
1139
                GdDestroyFont(((MWFONTOBJ *)hObject)->pfont);
1140
        if(hObject->hdr.type == OBJ_REGION)
1141
                GdDestroyRegion(((MWRGNOBJ *)hObject)->rgn);
1142
        GdItemFree(hObject);
1143
        return TRUE;
1144
}
1145
 
1146
#if UPDATEREGIONS
1147
/* region is passed in client coords (win32 api doc bug)*/
1148
int WINAPI
1149
SelectClipRgn(HDC hdc, HRGN hrgn)
1150
{
1151
        return ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
1152
}
1153
 
1154
/*
1155
 * Select a user clip region into DC, recalculate final clipregion.
1156
 * Only a copy of the passed region is used.
1157
 */
1158
/* region is passed in client coords (win32 api doc bug)*/
1159
int WINAPI
1160
ExtSelectClipRgn(HDC hdc, HRGN hrgn, int fnMode)
1161
{
1162
        HRGN    newrgn;
1163
 
1164
        if(!hdc)
1165
                return ERROR;
1166
        if(hdc->region != (MWRGNOBJ *)hrgn) {
1167
                /* combine region if not null*/
1168
                if(hrgn) {
1169
                        newrgn = CreateRectRgn(0, 0, 0, 0);
1170
 
1171
                        /*
1172
                         * Temporarily convert region from
1173
                         * client coords to screen coords, since
1174
                         * hwnd->update is kept in screen coords.
1175
                         */
1176
                        OffsetRgn(hrgn, hdc->hwnd->clirect.left,
1177
                                hdc->hwnd->clirect.top);
1178
 
1179
                        if(fnMode == RGN_COPY)
1180
                                CombineRgn(newrgn, hrgn, NULL, fnMode);
1181
                        else CombineRgn(newrgn, (HRGN)hdc->region, hrgn,fnMode);
1182
 
1183
                        /* convert passed region back to client coords*/
1184
                        OffsetRgn(hrgn, -hdc->hwnd->clirect.left,
1185
                                -hdc->hwnd->clirect.top);
1186
 
1187
 
1188
                        hrgn = newrgn;
1189
                }
1190
                DeleteObject((HRGN)hdc->region);
1191
                hdc->region = (MWRGNOBJ *)hrgn;
1192
 
1193
                /* force recalc of clipregion*/
1194
                cliphdc = NULL;
1195
                MwPrepareDC(hdc);
1196
        }
1197
        if(hrgn)
1198
                return ((MWRGNOBJ *)hrgn)->rgn->type;
1199
        return NULLREGION;
1200
}
1201
 
1202
/* update region is returned in client coordinates*/
1203
int WINAPI
1204
GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL bErase)
1205
{
1206
        /* FIXME bErase*/
1207
        if(!hwnd)
1208
                return ERROR;
1209
 
1210
        /* convert internal update region to client coords*/
1211
        GdOffsetRegion(hwnd->update, -hwnd->clirect.left, -hwnd->clirect.top);
1212
        GdCopyRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->update);
1213
        GdOffsetRegion(hwnd->update, hwnd->clirect.left, hwnd->clirect.top);
1214
        return hwnd->update->type;
1215
}
1216
#endif /* UPDATEREGIONS*/
1217
 
1218
/* update rectangle is returned in client coords*/
1219
BOOL WINAPI
1220
GetUpdateRect(HWND hwnd, LPRECT lpRect, BOOL bErase)
1221
{
1222
        /* FIXME bErase*/
1223
        if(!hwnd)
1224
                return FALSE;
1225
#if UPDATEREGIONS
1226
        if(lpRect) {
1227
                *lpRect = hwnd->update->extents;
1228
                /* convert to client coords*/
1229
                ScreenToClient(hwnd, (LPPOINT)&lpRect->left);
1230
                ScreenToClient(hwnd, (LPPOINT)&lpRect->right);
1231
        }
1232
 
1233
        /* return TRUE if update region is non-empty*/
1234
        return hwnd->update->type != NULLREGION;
1235
#else
1236
        GetClientRect(hwnd, lpRect);
1237
        return TRUE;
1238
#endif
1239
}
1240
 
1241
HBRUSH WINAPI
1242
CreateSolidBrush(COLORREF crColor)
1243
{
1244
        MWBRUSHOBJ *hbr;
1245
 
1246
        hbr = GdItemNew(MWBRUSHOBJ);
1247
        if(!hbr)
1248
                return NULL;
1249
        hbr->hdr.type = OBJ_BRUSH;
1250
        hbr->hdr.stockobj = FALSE;
1251
        hbr->style = BS_SOLID;
1252
        hbr->color = crColor;
1253
        return (HBRUSH)hbr;
1254
}
1255
 
1256
HPEN WINAPI
1257
CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
1258
{
1259
        MWPENOBJ *hpen;
1260
 
1261
        /* fix: nWidth > 1*/
1262
        hpen = GdItemNew(MWPENOBJ);
1263
        if(!hpen)
1264
                return NULL;
1265
        hpen->hdr.type = OBJ_PEN;
1266
        hpen->hdr.stockobj = FALSE;
1267
        hpen->style = nPenStyle;
1268
        hpen->color = crColor;
1269
        return (HPEN)hpen;
1270
}
1271
 
1272
HBITMAP WINAPI
1273
CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight)
1274
{
1275
        MWBITMAPOBJ *   hbitmap;
1276
        int             size;
1277
        int             linelen;
1278
 
1279
        if(!hdc)
1280
                return NULL;
1281
 
1282
        nWidth = MWMAX(nWidth, 1);
1283
        nHeight = MWMAX(nHeight, 1);
1284
 
1285
        /* calc memory allocation size and linelen from width and height*/
1286
        if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen))
1287
                return NULL;
1288
 
1289
        /* allocate gdi object*/
1290
        hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
1291
        if(!hbitmap)
1292
                return NULL;
1293
        hbitmap->hdr.type = OBJ_BITMAP;
1294
        hbitmap->hdr.stockobj = FALSE;
1295
        hbitmap->width = nWidth;
1296
        hbitmap->height = nHeight;
1297
 
1298
        /* create compatible with hdc*/
1299
        hbitmap->planes = hdc->psd->planes;
1300
        hbitmap->bpp = hdc->psd->bpp;
1301
        hbitmap->linelen = linelen;
1302
        hbitmap->size = size;
1303
 
1304
        return (HBRUSH)hbitmap;
1305
}
1306
 
1307
/* return NULL if no driver bitblit available*/
1308
HDC WINAPI
1309
CreateCompatibleDC(HDC hdc)
1310
{
1311
        HDC     hdcmem;
1312
        PSD     psd;
1313
        PSD     mempsd;
1314
 
1315
        /* allow NULL hdc to mean screen*/
1316
        psd = hdc? hdc->psd: &scrdev;
1317
 
1318
        /* allocate memory device, if driver doesn't blit will fail*/
1319
        mempsd = psd->AllocateMemGC(psd);
1320
        if(!mempsd)
1321
                return NULL;
1322
 
1323
        /* allocate a DC for DesktopWindow*/
1324
        hdcmem = GetDCEx(NULL, NULL, DCX_DEFAULTCLIP);
1325
        if(!hdcmem) {
1326
                mempsd->FreeMemGC(mempsd);
1327
                return NULL;
1328
        }
1329
        hdcmem->psd = mempsd;
1330
 
1331
        /* select in default bitmap to setup mem device parms*/
1332
        SelectObject(hdcmem, (HGDIOBJ)&default_bitmap);
1333
        return hdcmem;
1334
}
1335
 
1336
BOOL WINAPI
1337
BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
1338
        HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
1339
{
1340
        /* use stretch blit with equal src and dest width/height*/
1341
        return StretchBlt(hdcDest, nXDest, nYDest, nWidth, nHeight,
1342
                hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
1343
}
1344
 
1345
BOOL WINAPI
1346
StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest,
1347
        int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
1348
        int nWidthSrc, int nHeightSrc, DWORD dwRop)
1349
{
1350
 
1351
        HWND    hwnd;
1352
        POINT   dst, src;
1353
 
1354
        if(!hdcDest || !hdcSrc)
1355
                return FALSE;
1356
        dst.x = nXOriginDest;
1357
        dst.y = nYOriginDest;
1358
        src.x = nXOriginSrc;
1359
        src.y = nYOriginSrc;
1360
 
1361
        /* if src screen DC, convert coords*/
1362
        /* FIXME: src clipping isn't checked, only one set of cliprects also*/
1363
        if(!MwIsMemDC(hdcSrc) && MwIsClientDC(hdcSrc)) {
1364
                if(!(hwnd = MwPrepareDC(hdcSrc)))
1365
                        return FALSE;
1366
                ClientToScreen(hwnd, &src);
1367
        }
1368
        /* if dst screen DC, convert coords and set clipping*/
1369
        /* FIXME: if dest is also screen, src clipping will be overwritten*/
1370
        if(!MwIsMemDC(hdcDest) && MwIsClientDC(hdcDest)) {
1371
                if(!(hwnd = MwPrepareDC(hdcDest)))
1372
                        return FALSE;
1373
                ClientToScreen(hwnd, &dst);
1374
        }
1375
 
1376
        if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc) {
1377
                GdBlit(hdcDest->psd, dst.x, dst.y, nWidthDest, nHeightDest,
1378
                        hdcSrc->psd, src.x, src.y, dwRop);
1379
        } else {
1380
                GdStretchBlit(hdcDest->psd, dst.x, dst.y,
1381
                        nWidthDest, nHeightDest, hdcSrc->psd, src.x, src.y,
1382
                        nWidthSrc, nHeightSrc, dwRop);
1383
        }
1384
        return TRUE;
1385
}
1386
 
1387
UINT WINAPI
1388
GetSystemPaletteEntries(HDC hdc,UINT iStartIndex,UINT nEntries,
1389
        LPPALETTEENTRY lppe)
1390
{
1391
        UINT            i;
1392
        MWPALENTRY      rgb;
1393
 
1394
        /* currently, we only work for screen device*/
1395
        if(!hdc || hdc->psd != &scrdev)
1396
                return 0;
1397
 
1398
        for(i=0; i<nEntries; ++i) {
1399
                if(!GdGetPalette(hdc->psd, i+iStartIndex, 1, &rgb))
1400
                        break;
1401
                lppe->peRed = rgb.r;
1402
                lppe->peGreen = rgb.g;
1403
                lppe->peBlue = rgb.b;
1404
                lppe->peFlags = 0;
1405
                ++lppe;
1406
        }
1407
        return i;
1408
}
1409
 
1410
/* allow NULL hdc for scrdev*/
1411
int WINAPI
1412
GetDeviceCaps(HDC hdc, int nIndex)
1413
{
1414
        PSD     psd;
1415
 
1416
        if (!hdc)
1417
                psd = &scrdev;
1418
        else psd = hdc->psd;
1419
 
1420
        switch(nIndex) {
1421
        case HORZRES:
1422
                return psd->xvirtres;
1423
        case VERTRES:
1424
                return psd->yvirtres;
1425
        case BITSPIXEL:
1426
                return psd->bpp;
1427
        case PLANES:
1428
                return psd->planes;
1429
        case LOGPIXELSX:
1430
        case LOGPIXELSY:
1431
                return 96;
1432
        case SIZEPALETTE:
1433
                if (psd->bpp <= 8)
1434
                        return psd->ncolors;
1435
                break;
1436
        }
1437
        return 0;
1438
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.