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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [gfx/] [mw/] [current/] [src/] [mwin/] [wingdi.c] - Blame information for rev 819

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*
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_TRUECOLOR233:
380
                /* create RGB colorval from 2/3/3 pixel*/
381
                return PIXEL233TOCOLORVAL(pixel);
382
 
383
        case MWPF_PALETTE:
384
                if(GdGetPalette(hdc->psd, pixel, 1, &rgb))
385
                        return RGB(rgb.r, rgb.g, rgb.b);
386
        }
387
        return CLR_INVALID;
388
}
389
 
390
COLORREF WINAPI
391
SetPixel(HDC hdc, int x, int y, COLORREF crColor)
392
{
393
        HWND            hwnd;
394
        POINT           pt;
395
 
396
        hwnd = MwPrepareDC(hdc);
397
        if(!hwnd)
398
                return 0;        /* doesn't return previous color*/
399
        pt.x = x;
400
        pt.y = y;
401
        if(MwIsClientDC(hdc))
402
                ClientToScreen(hwnd, &pt);
403
 
404
        /* draw point in passed color*/
405
        GdSetForeground(GdFindColor(crColor));
406
        GdPoint(hdc->psd, pt.x, pt.y);
407
        return 0;                /* doesn't return previous color*/
408
}
409
 
410
BOOL WINAPI
411
MoveToEx(HDC hdc, int x, int y, LPPOINT lpPoint)
412
{
413
        if(!hdc)
414
                return FALSE;
415
        if(lpPoint)
416
                *lpPoint = hdc->pt;
417
        hdc->pt.x = x;
418
        hdc->pt.y = y;
419
        return TRUE;
420
}
421
 
422
BOOL WINAPI
423
LineTo(HDC hdc, int x, int y)
424
{
425
        HWND            hwnd;
426
        POINT           beg, end;
427
 
428
        hwnd = MwPrepareDC(hdc);
429
        if(!hwnd)
430
                return FALSE;
431
 
432
        beg.x = hdc->pt.x;
433
        beg.y = hdc->pt.y;
434
        end.x = x;
435
        end.y = y;
436
        if(MwIsClientDC(hdc)) {
437
                ClientToScreen(hwnd, &beg);
438
                ClientToScreen(hwnd, &end);
439
        }
440
 
441
        /* draw line in current pen color*/
442
        if(hdc->pen->style != PS_NULL) {
443
                GdSetForeground(GdFindColor(hdc->pen->color));
444
                /* don't draw last point*/
445
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
446
        }
447
        hdc->pt.x = x;
448
        hdc->pt.y = y;
449
        return TRUE;
450
}
451
 
452
/* draw line segments by connecting passed points*/
453
BOOL WINAPI
454
Polyline(HDC hdc, CONST POINT *lppt, int cPoints)
455
{
456
        HWND            hwnd;
457
        POINT           beg, end;
458
 
459
        if(cPoints <= 1)
460
                return FALSE;
461
 
462
        hwnd = MwPrepareDC(hdc);
463
        if(!hwnd)
464
                return FALSE;
465
 
466
        if(hdc->pen->style == PS_NULL)
467
                return TRUE;
468
 
469
        /* draw line in current pen color*/
470
        GdSetForeground(GdFindColor(hdc->pen->color));
471
 
472
        beg = *lppt++;
473
        if(MwIsClientDC(hdc))
474
                ClientToScreen(hwnd, &beg);
475
        while(--cPoints > 0) {
476
                end = *lppt++;
477
                if(MwIsClientDC(hdc))
478
                        ClientToScreen(hwnd, &end);
479
 
480
                /* don't draw last point*/
481
                GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE);
482
 
483
                beg = end;
484
        }
485
        return TRUE;
486
}
487
 
488
BOOL WINAPI
489
Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom)
490
{
491
        HWND    hwnd;
492
        RECT    rc;
493
 
494
        hwnd = MwPrepareDC(hdc);
495
        if(!hwnd)
496
                return FALSE;
497
 
498
        SetRect(&rc, nLeft, nTop, nRight, nBottom);
499
        if(MwIsClientDC(hdc))
500
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
501
 
502
        /* draw rectangle in current pen color*/
503
        if(hdc->pen->style != PS_NULL) {
504
                GdSetForeground(GdFindColor(hdc->pen->color));
505
                GdRect(hdc->psd, rc.left, rc.top,
506
                        rc.right - rc.left, rc.bottom - rc.top);
507
        }
508
 
509
        /* fill rectangle in current brush color*/
510
        if(hdc->brush->style != BS_NULL) {
511
                InflateRect(&rc, -1, -1);
512
                GdSetForeground(GdFindColor(hdc->brush->color));
513
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
514
                        rc.bottom - rc.top);
515
        }
516
 
517
        return TRUE;
518
}
519
 
520
BOOL WINAPI
521
Ellipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
522
{
523
        HWND    hwnd;
524
        int     rx, ry;
525
        RECT    rc;
526
 
527
        hwnd = MwPrepareDC(hdc);
528
        if(!hwnd)
529
                return FALSE;
530
 
531
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
532
        if(MwIsClientDC(hdc))
533
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
534
 
535
        rx = (rc.right - rc.left)/2 - 1;
536
        ry = (rc.bottom - rc.top)/2 - 1;
537
        rc.left += rx;
538
        rc.top += ry;
539
 
540
        /* fill ellipse in current brush color*/
541
        if(hdc->brush->style != BS_NULL) {
542
                InflateRect(&rc, -1, -1);
543
                GdSetForeground(GdFindColor(hdc->brush->color));
544
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE);
545
        }
546
 
547
        /* draw ellipse outline in current pen color*/
548
        if(hdc->pen->style != PS_NULL) {
549
                GdSetForeground(GdFindColor(hdc->pen->color));
550
                GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE);
551
        }
552
 
553
        return TRUE;
554
}
555
 
556
static void
557
dopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
558
        int ax, int ay, int bx, int by, int type)
559
{
560
        HWND    hwnd;
561
        int     rx, ry;
562
        RECT    rc, rc2;
563
 
564
        hwnd = MwPrepareDC(hdc);
565
        if(!hwnd)
566
                return;
567
 
568
        SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect);
569
        SetRect(&rc2, ax, ay, bx, by);
570
        if(MwIsClientDC(hdc)) {
571
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
572
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2);
573
        }
574
 
575
        rx = (rc.right - rc.left)/2 - 1;
576
        ry = (rc.bottom - rc.top)/2 - 1;
577
        rc.left += rx;
578
        rc.top += ry;
579
 
580
        /* fill ellipse in current brush color*/
581
        if(hdc->brush->style != BS_NULL && type == MWPIE) {
582
                GdSetForeground(GdFindColor(hdc->brush->color));
583
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
584
                        rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE);
585
        }
586
 
587
        /* draw ellipse outline in current pen color*/
588
        if(hdc->pen->style != PS_NULL) {
589
                GdSetForeground(GdFindColor(hdc->pen->color));
590
                if(type == MWPIE)
591
                        type = MWARC;   /* MWARCOUTLINE?*/
592
                GdArc(hdc->psd, rc.left, rc.top, rx, ry,
593
                        rc2.left, rc2.top, rc2.right, rc2.bottom, type);
594
        }
595
}
596
 
597
BOOL WINAPI
598
Arc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
599
        int nXStartArc, int nYStartArc, int nXEndArc, int nYEndArc)
600
{
601
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
602
                nXStartArc, nYStartArc, nXEndArc, nYEndArc, MWARC);
603
        return TRUE;
604
}
605
 
606
BOOL WINAPI
607
Pie(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect,
608
        int nXRadial1, int nYRadial1, int nXRadial2, int nYRadial2)
609
{
610
        dopiearc(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect,
611
                nXRadial1, nYRadial1, nXRadial2, nYRadial2, MWPIE);
612
        return TRUE;
613
}
614
 
615
BOOL WINAPI
616
Polygon(HDC hdc, CONST POINT *lpPoints, int nCount)
617
{
618
        HWND    hwnd;
619
        int     i;
620
        LPPOINT pp, ppAlloc = NULL;
621
 
622
        hwnd = MwPrepareDC(hdc);
623
        if(!hwnd)
624
                return FALSE;
625
 
626
        if(MwIsClientDC(hdc)) {
627
                /* convert points to client coords*/
628
                ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT));
629
                if(!ppAlloc)
630
                        return FALSE;
631
                memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT));
632
                pp = ppAlloc;
633
                for(i=0; i<nCount; ++i)
634
                        ClientToScreen(hwnd, pp++);
635
                pp = ppAlloc;
636
        } else pp = (LPPOINT)lpPoints;
637
 
638
        /* fill polygon in current brush color*/
639
        if(hdc->brush->style != BS_NULL) {
640
                GdSetForeground(GdFindColor(hdc->brush->color));
641
                GdFillPoly(hdc->psd, nCount, pp);
642
        }
643
 
644
        /* draw polygon outline in current pen color*/
645
        if(hdc->pen->style != PS_NULL) {
646
                GdSetForeground(GdFindColor(hdc->pen->color));
647
                GdPoly(hdc->psd, nCount, pp);
648
        }
649
 
650
        if(ppAlloc)
651
                free(ppAlloc);
652
        return TRUE;
653
}
654
 
655
/* draw nCount polygons*/
656
BOOL WINAPI
657
PolyPolygon(HDC hdc, CONST POINT *lpPoints, LPINT lpPolyCounts, int nCount)
658
{
659
        while(--nCount >= 0) {
660
                if (!Polygon(hdc, lpPoints, *lpPolyCounts))
661
                        return FALSE;
662
                lpPoints += *lpPolyCounts++;
663
        }
664
        return TRUE;
665
}
666
 
667
int WINAPI
668
FillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr)
669
{
670
        HWND            hwnd;
671
        RECT            rc;
672
        MWBRUSHOBJ *    obr = (MWBRUSHOBJ *)hbr;
673
        COLORREF        crFill;
674
 
675
        hwnd = MwPrepareDC(hdc);
676
        if(!hwnd || !obr)
677
                return FALSE;
678
 
679
        if(!lprc) {
680
                if(MwIsClientDC(hdc))
681
                        GetClientRect(hwnd, &rc);
682
                else
683
                        GetWindowRect(hwnd, &rc);
684
                lprc = &rc;
685
        } else
686
                rc = *lprc;
687
        if(MwIsClientDC(hdc))
688
                MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
689
 
690
        /* handle COLOR_xxx + 1 passed as HBRUSH*/
691
        if((PTRTOINT)obr <= MAXSYSCOLORS)
692
                crFill = GetSysColor((int)obr-1);
693
        else {
694
                /* get color from passed HBRUSH*/
695
                if(obr->style == BS_NULL)
696
                        return TRUE;
697
                crFill = obr->color;
698
        }
699
 
700
        /* fill rectangle in passed brush color*/
701
        GdSetForeground(GdFindColor(crFill));
702
        GdFillRect(hdc->psd, rc.left, rc.top,
703
                rc.right - rc.left, rc.bottom - rc.top);
704
        return TRUE;
705
}
706
 
707
/* ascii*/
708
BOOL WINAPI
709
TextOut(HDC hdc, int x, int y, LPCSTR lpszString, int cbString)
710
{
711
        /* kaffe port wants MWTF_UTF8 here...*/
712
        return MwExtTextOut(hdc, x, y, 0, NULL, lpszString, cbString, NULL,
713
                MWTF_ASCII);
714
}
715
 
716
/* ascii*/
717
BOOL WINAPI
718
ExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
719
        LPCSTR lpszString, UINT cbCount, CONST INT *lpDx)
720
{
721
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
722
                cbCount, lpDx, MWTF_ASCII);
723
}
724
 
725
/* unicode*/
726
BOOL WINAPI
727
ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
728
        LPCWSTR lpszString, UINT cbCount, CONST INT *lpDx)
729
{
730
        return MwExtTextOut(hdc, x, y, fuOptions, lprc, lpszString,
731
                cbCount, lpDx, MWTF_UC16);
732
}
733
 
734
/* internal version of ExtTextOut, passed flags for text data type*/
735
static BOOL
736
MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc,
737
        LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags)
738
{
739
        HWND    hwnd;
740
        POINT   pt;
741
        RECT    rc;
742
 
743
        hwnd = MwPrepareDC(hdc);
744
        if(!hwnd)
745
                return FALSE;
746
 
747
        pt.x = x;
748
        pt.y = y;
749
        if(MwIsClientDC(hdc))
750
                ClientToScreen(hwnd, &pt);
751
 
752
        /* optionally fill passed rectangle*/
753
        if(lprc && (fuOptions&ETO_OPAQUE)) {
754
                rc = *lprc;
755
                if(MwIsClientDC(hdc))
756
                        MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
757
 
758
                /* fill rectangle with current background color*/
759
                GdSetForeground(GdFindColor(hdc->bkcolor));
760
                GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left,
761
                        rc.bottom - rc.top);
762
                GdSetUseBackground(FALSE);
763
        } else {
764
                /* use current background mode for text background draw*/
765
                GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE);
766
                /* always set background color in case GdArea is
767
                 * used to draw, which compares gr_foreground != gr_background
768
                 * if gr_usebg is false...
769
                 */
770
                /*if(hdc->bkmode == OPAQUE)*/
771
                        GdSetBackground(GdFindColor(hdc->bkcolor));
772
        }
773
 
774
        /* nyi: lpDx*/
775
 
776
        /* draw text in current text foreground and background color*/
777
        GdSetForeground(GdFindColor(hdc->textcolor));
778
        GdSetFont(hdc->font->pfont);
779
 
780
        /* this whole text alignment thing needs rewriting*/
781
        if((hdc->textalign & TA_BASELINE) == TA_BASELINE) {
782
                 /* this is not right... changed for kaffe port
783
                flags |= MWTF_TOP;
784
                 */
785
                flags |= MWTF_BASELINE;
786
        } else if(hdc->textalign & TA_BOTTOM) {
787
                MWCOORD ph, pw, pb;
788
 
789
                if(lprc)
790
                        pt.y += lprc->bottom - lprc->top;
791
                else {
792
                        GdGetTextSize(hdc->font->pfont, lpszString, cbCount,
793
                                &pw, &ph, &pb, flags);
794
                        pt.y += ph;
795
                }
796
                flags |= MWTF_BOTTOM;
797
        } else
798
                flags |= MWTF_TOP;
799
        GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags);
800
 
801
        return TRUE;
802
}
803
 
804
/* ascii*/
805
int WINAPI
806
DrawTextA(HDC hdc, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
807
{
808
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_ASCII);
809
}
810
 
811
/* unicode*/
812
int WINAPI
813
DrawTextW(HDC hdc, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat)
814
{
815
        return MwDrawText(hdc, lpString, nCount, lpRect, uFormat, MWTF_UC16);
816
}
817
 
818
/* note: many DT_x aren't implemented in this function*/
819
/* internal version of DrawText, passed flags for text data type*/
820
static int
821
MwDrawText(HDC hdc, LPCVOID lpString, int nCount, LPRECT lpRect, UINT uFormat,
822
        int flags)
823
{
824
        MWCOORD x, y, width, height, baseline;
825
 
826
        if(nCount == -1)
827
                nCount = strlen(lpString);
828
 
829
        if(uFormat & (DT_CALCRECT|DT_CENTER|DT_RIGHT)) {
830
                if(!hdc)
831
                        return 0;
832
                GdGetTextSize(hdc->font->pfont, lpString, nCount,
833
                        &width, &height, &baseline, MWTF_ASCII);
834
        }
835
        x = lpRect->left;
836
        y = lpRect->top;
837
 
838
        if(uFormat & DT_CALCRECT) {
839
                lpRect->right = x + width;
840
                lpRect->bottom = y + height;
841
                return height;
842
        }
843
 
844
        if(uFormat & DT_CENTER)
845
                x = (lpRect->left + lpRect->right - width) / 2;
846
        else if(uFormat & DT_RIGHT)
847
                x += lpRect->right - width;
848
 
849
        /* draw text at DT_TOP using current fg, bg and bkmode*/
850
        MwExtTextOut(hdc, x, y, 0, NULL, lpString, nCount, NULL, flags);
851
        return height;
852
}
853
 
854
/* Microwindows only*/
855
BOOL WINAPI
856
DrawDIB(HDC hdc,int x,int y,PMWIMAGEHDR pimage)
857
{
858
        HWND            hwnd;
859
        POINT           pt;
860
 
861
        hwnd = MwPrepareDC(hdc);
862
        if(!hwnd || !pimage)
863
                return FALSE;
864
        pt.x = x;
865
        pt.y = y;
866
        if(MwIsClientDC(hdc))
867
                ClientToScreen(hwnd, &pt);
868
 
869
        GdDrawImage(hdc->psd, pt.x, pt.y, pimage);
870
        return TRUE;
871
}
872
 
873
/* define color scheme: A (tan), B (winstd) or C (old)*/
874
#if ELKS
875
#define B
876
#else
877
#define A
878
#endif
879
 
880
#define A_RGB(r,g,b)
881
#define B_RGB(r,g,b)
882
#define C_RGB(r,g,b)
883
 
884
#ifdef A
885
#undef  A_RGB
886
#define A_RGB(r,g,b)    RGB(r,g,b),
887
#endif
888
#ifdef B
889
#undef  B_RGB
890
#define B_RGB(r,g,b)    RGB(r,g,b),
891
#endif
892
#ifdef C
893
#undef  C_RGB
894
#define C_RGB(r,g,b)    RGB(r,g,b),
895
#endif
896
 
897
static COLORREF sysColors[MAXSYSCOLORS] = {
898
        RGB(192, 192, 192),     /* COLOR_SCROLLBAR          0*/
899
        RGB(  0, 128, 128),     /* COLOR_BACKGROUND          */
900
        A_RGB(128,   0,   0)      /* COLOR_ACTIVECAPTION       */
901
        B_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
902
        C_RGB(128,   0, 128)     /* COLOR_ACTIVECAPTION       */
903
        A_RGB(162, 141, 104)    /* COLOR_INACTIVECAPTION     */
904
        B_RGB(128, 128, 128)    /* COLOR_INACTIVECAPTION     */
905
        C_RGB(  0,  64, 128)     /* COLOR_INACTIVECAPTION     */
906
        RGB(192, 192, 192),     /* COLOR_MENU                */
907
        RGB(255, 255, 255),     /* COLOR_WINDOW             5*/
908
        RGB(  0,   0,   0),     /* COLOR_WINDOWFRAME         */
909
        RGB(  0,   0,   0),     /* COLOR_MENUTEXT            */
910
        RGB(  0,   0,   0),     /* COLOR_WINDOWTEXT          */
911
        RGB(255, 255, 255),     /* COLOR_CAPTIONTEXT         */
912
        RGB(192, 192, 192),     /* COLOR_ACTIVEBORDER      10*/
913
        RGB(192, 192, 192),     /* COLOR_INACTIVEBORDER      */
914
        RGB(128, 128, 128),     /* COLOR_APPWORKSPACE        */
915
        RGB(128,   0,   0),     /* COLOR_HIGHLIGHT           */
916
        RGB(255, 255, 255),     /* COLOR_HIGHLIGHTTEXT       */
917
        A_RGB(213, 204, 187)    /* COLOR_BTNFACE           15*/
918
        B_RGB(192, 192, 192)    /* COLOR_BTNFACE           15*/
919
        C_RGB(160, 160, 160)    /* COLOR_BTNFACE           15*/
920
        A_RGB(162, 141, 104)    /* COLOR_BTNSHADOW           */
921
        B_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
922
        C_RGB(128, 128, 128)    /* COLOR_BTNSHADOW           */
923
        RGB( 64,  64,  64),     /* COLOR_GRAYTEXT            */
924
        RGB(  0,   0,   0),     /* COLOR_BTNTEXT             */
925
        RGB(192, 192, 192),     /* COLOR_INACTIVECAPTIONTEXT */
926
        A_RGB(234, 230, 221)    /* COLOR_BTNHIGHLIGHT      20*/
927
        B_RGB(255, 255, 255)    /* COLOR_BTNHIGHLIGHT      20*/
928
        C_RGB(223, 223, 223)    /* COLOR_BTNHIGHLIGHT      20*/
929
        RGB(  0,   0,   0),     /* COLOR_3DDKSHADOW          */
930
        A_RGB(213, 204, 187)    /* COLOR_3DLIGHT             */
931
        B_RGB(223, 223, 223)    /* COLOR_3DLIGHT             */
932
        C_RGB(192, 192, 192)    /* COLOR_3DLIGHT             */
933
        RGB(  0,   0,   0),     /* COLOR_INFOTEXT            */
934
        RGB(225, 255, 255),     /* COLOR_INFOBK              */
935
        RGB(184, 180, 184),     /* COLOR_ALTERNATEBTNFACE  25*/
936
        RGB(  0,   0, 255),     /* COLOR_HOTLIGHT              */
937
        RGB( 16, 132, 208),     /* COLOR_GRADIENTACTIVECAPTION */
938
        RGB(184, 180, 184)      /* COLOR_GRADIENTINACTIVECAPTION 28*/
939
};
940
 
941
DWORD WINAPI
942
GetSysColor(int nIndex)
943
{
944
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS)
945
                return sysColors[nIndex];
946
        return 0;
947
}
948
 
949
COLORREF WINAPI
950
SetSysColor(int nIndex, COLORREF crColor)       /* Microwindows only*/
951
{
952
        COLORREF oldColor;
953
 
954
        if(nIndex >= 0 && nIndex < MAXSYSCOLORS) {
955
                oldColor = sysColors[nIndex];
956
                sysColors[nIndex] = crColor;
957
                return oldColor;
958
        }
959
        return 0;
960
}
961
 
962
static MWBRUSHOBJ OBJ_WHITE_BRUSH = {
963
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(255, 255, 255)
964
};
965
 
966
static MWBRUSHOBJ OBJ_LTGRAY_BRUSH = {
967
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(192, 192, 192)
968
};
969
 
970
static MWBRUSHOBJ OBJ_GRAY_BRUSH = {
971
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(128, 128, 128)
972
};
973
 
974
static MWBRUSHOBJ OBJ_DKGRAY_BRUSH = {
975
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(32, 32, 32)
976
};
977
 
978
static MWBRUSHOBJ OBJ_BLACK_BRUSH = {
979
        {OBJ_BRUSH, TRUE}, BS_SOLID, RGB(0, 0, 0)
980
};
981
 
982
static MWBRUSHOBJ OBJ_NULL_BRUSH = {
983
        {OBJ_BRUSH, TRUE}, BS_NULL, RGB(0, 0, 0)
984
};
985
 
986
static MWPENOBJ OBJ_WHITE_PEN = {
987
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(255, 255, 255)
988
};
989
 
990
static MWPENOBJ OBJ_BLACK_PEN = {
991
        {OBJ_PEN, TRUE}, PS_SOLID, RGB(0, 0, 0)
992
};
993
 
994
static MWPENOBJ OBJ_NULL_PEN = {
995
        {OBJ_PEN, TRUE}, PS_NULL, RGB(0, 0, 0)
996
};
997
 
998
static MWFONTOBJ OBJ_OEM_FIXED_FONT = {
999
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
1000
};
1001
 
1002
static MWFONTOBJ OBJ_ANSI_FIXED_FONT = {
1003
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
1004
};
1005
 
1006
static MWFONTOBJ OBJ_ANSI_VAR_FONT = {
1007
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
1008
};
1009
 
1010
static MWFONTOBJ OBJ_SYSTEM_FONT = {
1011
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_VAR
1012
};
1013
 
1014
static MWFONTOBJ OBJ_DEVICE_DEFAULT_FONT = {
1015
        {OBJ_FONT, TRUE}, NULL, MWFONT_OEM_FIXED
1016
};
1017
 
1018
static MWFONTOBJ OBJ_SYSTEM_FIXED_FONT = {
1019
        {OBJ_FONT, TRUE}, NULL, MWFONT_SYSTEM_FIXED
1020
};
1021
 
1022
static MWFONTOBJ OBJ_DEFAULT_GUI_FONT = {
1023
        {OBJ_FONT, TRUE}, NULL, MWFONT_GUI_VAR
1024
};
1025
 
1026
static struct hgdiobj *stockObjects[MAXSTOCKOBJECTS] = {
1027
        (struct hgdiobj *)&OBJ_WHITE_BRUSH,             /* WHITE_BRUSH*/
1028
        (struct hgdiobj *)&OBJ_LTGRAY_BRUSH,            /* LTGRAY_BRUSH*/
1029
        (struct hgdiobj *)&OBJ_GRAY_BRUSH,              /* GRAY_BRUSH*/
1030
        (struct hgdiobj *)&OBJ_DKGRAY_BRUSH,            /* DKGRAY_BRUSH*/
1031
        (struct hgdiobj *)&OBJ_BLACK_BRUSH,             /* BLACK_BRUSH*/
1032
        (struct hgdiobj *)&OBJ_NULL_BRUSH,              /* NULL_BRUSH*/
1033
        (struct hgdiobj *)&OBJ_WHITE_PEN,               /* WHITE_PEN*/
1034
        (struct hgdiobj *)&OBJ_BLACK_PEN,               /* BLACK_PEN*/
1035
        (struct hgdiobj *)&OBJ_NULL_PEN,                /* NULL_PEN*/
1036
        (struct hgdiobj *)NULL,
1037
        (struct hgdiobj *)&OBJ_OEM_FIXED_FONT,          /* OEM_FIXED_FONT*/
1038
        (struct hgdiobj *)&OBJ_ANSI_FIXED_FONT,         /* ANSI_FIXED_FONT*/
1039
        (struct hgdiobj *)&OBJ_ANSI_VAR_FONT,           /* ANSI_VAR_FONT*/
1040
        (struct hgdiobj *)&OBJ_SYSTEM_FONT,             /* SYSTEM_FONT*/
1041
        (struct hgdiobj *)&OBJ_DEVICE_DEFAULT_FONT,     /* DEVICE_DEFAULT_FONT*/
1042
        (struct hgdiobj *)NULL,                         /* DEFAULT_PALETTE*/
1043
        (struct hgdiobj *)&OBJ_SYSTEM_FIXED_FONT,       /* SYSTEM_FIXED_FONT*/
1044
        (struct hgdiobj *)&OBJ_DEFAULT_GUI_FONT         /* DEFAULT_GUI_FONT*/
1045
};
1046
 
1047
HGDIOBJ WINAPI
1048
GetStockObject(int nObject)
1049
{
1050
        HGDIOBJ         pObj;
1051
        MWFONTOBJ *     pFont;
1052
 
1053
        if(nObject >= 0 && nObject < MAXSTOCKOBJECTS) {
1054
                pObj = stockObjects[nObject];
1055
 
1056
                /* create stock fonts on first access*/
1057
                if(pObj->hdr.type == OBJ_FONT) {
1058
                        pFont = (MWFONTOBJ *)pObj;
1059
                        if(pFont->pfont == NULL) {
1060
                                pFont->pfont = GdCreateFont(&scrdev,
1061
                                        pFont->name, 0, NULL);
1062
                        }
1063
                        return pObj;
1064
                }
1065
 
1066
                /* implement multiple color schemes with
1067
                 * standard background brushes...
1068
                 */
1069
                switch(nObject) {
1070
                case LTGRAY_BRUSH:
1071
                case GRAY_BRUSH:
1072
                        ((MWBRUSHOBJ *)pObj)->color =GetSysColor(COLOR_BTNFACE);
1073
                        break;
1074
                case DKGRAY_BRUSH:
1075
                        ((MWBRUSHOBJ *)pObj)->color =
1076
                                GetSysColor(COLOR_BTNSHADOW);
1077
                        break;
1078
                }
1079
                return pObj;
1080
        }
1081
        return NULL;
1082
}
1083
 
1084
HGDIOBJ WINAPI
1085
SelectObject(HDC hdc, HGDIOBJ hObject)
1086
{
1087
        HGDIOBJ         objOrg;
1088
        MWBITMAPOBJ *   pb;
1089
 
1090
        if(!hdc || !hObject)
1091
                return NULL;
1092
 
1093
        switch(hObject->hdr.type) {
1094
        case OBJ_PEN:
1095
                objOrg = (HGDIOBJ)hdc->pen;
1096
                hdc->pen = (MWPENOBJ *)hObject;
1097
                break;
1098
        case OBJ_BRUSH:
1099
                objOrg = (HGDIOBJ)hdc->brush;
1100
                hdc->brush = (MWBRUSHOBJ *)hObject;
1101
                break;
1102
        case OBJ_FONT:
1103
                objOrg = (HGDIOBJ)hdc->font;
1104
                hdc->font = (MWFONTOBJ *)hObject;
1105
                break;
1106
        case OBJ_BITMAP:
1107
                /* must be memory dc to select bitmap*/
1108
                if(!(hdc->psd->flags&PSF_MEMORY))
1109
                        return NULL;
1110
                objOrg = (HGDIOBJ)hdc->bitmap;
1111
 
1112
                /* setup mem dc for drawing into bitmap*/
1113
                pb = (MWBITMAPOBJ *)hObject;
1114
 
1115
                /* init memory context*/
1116
                if (!hdc->psd->MapMemGC(hdc->psd, pb->width, pb->height,
1117
                        pb->planes, pb->bpp, pb->linelen, pb->size,
1118
                        &pb->bits[0]))
1119
                                return NULL;
1120
 
1121
                hdc->bitmap = (MWBITMAPOBJ *)hObject;
1122
                break;
1123
#if UPDATEREGIONS
1124
        case OBJ_REGION:
1125
                /*objOrg = (HGDIOBJ)hdc->region;*/
1126
                objOrg = NULL;  /* FIXME? hdc->region is destroyed below*/
1127
                SelectClipRgn(hdc, (HRGN)hObject);
1128
                break;
1129
#endif
1130
        default:
1131
                return NULL;
1132
        }
1133
 
1134
        return objOrg;
1135
}
1136
 
1137
BOOL WINAPI
1138
DeleteObject(HGDIOBJ hObject)
1139
{
1140
        if(!hObject || hObject->hdr.stockobj)
1141
                return FALSE;
1142
        if(hObject->hdr.type == OBJ_FONT)
1143
                GdDestroyFont(((MWFONTOBJ *)hObject)->pfont);
1144
        if(hObject->hdr.type == OBJ_REGION)
1145
                GdDestroyRegion(((MWRGNOBJ *)hObject)->rgn);
1146
        GdItemFree(hObject);
1147
        return TRUE;
1148
}
1149
 
1150
#if UPDATEREGIONS
1151
/* region is passed in client coords (win32 api doc bug)*/
1152
int WINAPI
1153
SelectClipRgn(HDC hdc, HRGN hrgn)
1154
{
1155
        return ExtSelectClipRgn(hdc, hrgn, RGN_COPY);
1156
}
1157
 
1158
/*
1159
 * Select a user clip region into DC, recalculate final clipregion.
1160
 * Only a copy of the passed region is used.
1161
 */
1162
/* region is passed in client coords (win32 api doc bug)*/
1163
int WINAPI
1164
ExtSelectClipRgn(HDC hdc, HRGN hrgn, int fnMode)
1165
{
1166
        HRGN    newrgn;
1167
 
1168
        if(!hdc)
1169
                return ERROR;
1170
        if(hdc->region != (MWRGNOBJ *)hrgn) {
1171
                /* combine region if not null*/
1172
                if(hrgn) {
1173
                        newrgn = CreateRectRgn(0, 0, 0, 0);
1174
 
1175
                        /*
1176
                         * Temporarily convert region from
1177
                         * client coords to screen coords, since
1178
                         * hwnd->update is kept in screen coords.
1179
                         */
1180
                        OffsetRgn(hrgn, hdc->hwnd->clirect.left,
1181
                                hdc->hwnd->clirect.top);
1182
 
1183
                        if(fnMode == RGN_COPY)
1184
                                CombineRgn(newrgn, hrgn, NULL, fnMode);
1185
                        else CombineRgn(newrgn, (HRGN)hdc->region, hrgn,fnMode);
1186
 
1187
                        /* convert passed region back to client coords*/
1188
                        OffsetRgn(hrgn, -hdc->hwnd->clirect.left,
1189
                                -hdc->hwnd->clirect.top);
1190
 
1191
 
1192
                        hrgn = newrgn;
1193
                }
1194
                DeleteObject((HRGN)hdc->region);
1195
                hdc->region = (MWRGNOBJ *)hrgn;
1196
 
1197
                /* force recalc of clipregion*/
1198
                cliphdc = NULL;
1199
                MwPrepareDC(hdc);
1200
        }
1201
        if(hrgn)
1202
                return ((MWRGNOBJ *)hrgn)->rgn->type;
1203
        return NULLREGION;
1204
}
1205
 
1206
/* update region is returned in client coordinates*/
1207
int WINAPI
1208
GetUpdateRgn(HWND hwnd, HRGN hrgn, BOOL bErase)
1209
{
1210
        /* FIXME bErase*/
1211
        if(!hwnd)
1212
                return ERROR;
1213
 
1214
        /* convert internal update region to client coords*/
1215
        GdOffsetRegion(hwnd->update, -hwnd->clirect.left, -hwnd->clirect.top);
1216
        GdCopyRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->update);
1217
        GdOffsetRegion(hwnd->update, hwnd->clirect.left, hwnd->clirect.top);
1218
        return hwnd->update->type;
1219
}
1220
#endif /* UPDATEREGIONS*/
1221
 
1222
/* update rectangle is returned in client coords*/
1223
BOOL WINAPI
1224
GetUpdateRect(HWND hwnd, LPRECT lpRect, BOOL bErase)
1225
{
1226
        /* FIXME bErase*/
1227
        if(!hwnd)
1228
                return FALSE;
1229
#if UPDATEREGIONS
1230
        if(lpRect) {
1231
                *lpRect = hwnd->update->extents;
1232
                /* convert to client coords*/
1233
                ScreenToClient(hwnd, (LPPOINT)&lpRect->left);
1234
                ScreenToClient(hwnd, (LPPOINT)&lpRect->right);
1235
        }
1236
 
1237
        /* return TRUE if update region is non-empty*/
1238
        return hwnd->update->type != NULLREGION;
1239
#else
1240
        GetClientRect(hwnd, lpRect);
1241
        return TRUE;
1242
#endif
1243
}
1244
 
1245
HBRUSH WINAPI
1246
CreateSolidBrush(COLORREF crColor)
1247
{
1248
        MWBRUSHOBJ *hbr;
1249
 
1250
        hbr = GdItemNew(MWBRUSHOBJ);
1251
        if(!hbr)
1252
                return NULL;
1253
        hbr->hdr.type = OBJ_BRUSH;
1254
        hbr->hdr.stockobj = FALSE;
1255
        hbr->style = BS_SOLID;
1256
        hbr->color = crColor;
1257
        return (HBRUSH)hbr;
1258
}
1259
 
1260
HPEN WINAPI
1261
CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
1262
{
1263
        MWPENOBJ *hpen;
1264
 
1265
        /* fix: nWidth > 1*/
1266
        hpen = GdItemNew(MWPENOBJ);
1267
        if(!hpen)
1268
                return NULL;
1269
        hpen->hdr.type = OBJ_PEN;
1270
        hpen->hdr.stockobj = FALSE;
1271
        hpen->style = nPenStyle;
1272
        hpen->color = crColor;
1273
        return (HPEN)hpen;
1274
}
1275
 
1276
HBITMAP WINAPI
1277
CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight)
1278
{
1279
        MWBITMAPOBJ *   hbitmap;
1280
        int             size;
1281
        int             linelen;
1282
 
1283
        if(!hdc)
1284
                return NULL;
1285
 
1286
        nWidth = MWMAX(nWidth, 1);
1287
        nHeight = MWMAX(nHeight, 1);
1288
 
1289
        /* calc memory allocation size and linelen from width and height*/
1290
        if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen))
1291
                return NULL;
1292
 
1293
        /* allocate gdi object*/
1294
        hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
1295
        if(!hbitmap)
1296
                return NULL;
1297
        hbitmap->hdr.type = OBJ_BITMAP;
1298
        hbitmap->hdr.stockobj = FALSE;
1299
        hbitmap->width = nWidth;
1300
        hbitmap->height = nHeight;
1301
 
1302
        /* create compatible with hdc*/
1303
        hbitmap->planes = hdc->psd->planes;
1304
        hbitmap->bpp = hdc->psd->bpp;
1305
        hbitmap->linelen = linelen;
1306
        hbitmap->size = size;
1307
 
1308
        return (HBRUSH)hbitmap;
1309
}
1310
 
1311
/* return NULL if no driver bitblit available*/
1312
HDC WINAPI
1313
CreateCompatibleDC(HDC hdc)
1314
{
1315
        HDC     hdcmem;
1316
        PSD     psd;
1317
        PSD     mempsd;
1318
 
1319
        /* allow NULL hdc to mean screen*/
1320
        psd = hdc? hdc->psd: &scrdev;
1321
 
1322
        /* allocate memory device, if driver doesn't blit will fail*/
1323
        mempsd = psd->AllocateMemGC(psd);
1324
        if(!mempsd)
1325
                return NULL;
1326
 
1327
        /* allocate a DC for DesktopWindow*/
1328
        hdcmem = GetDCEx(NULL, NULL, DCX_DEFAULTCLIP);
1329
        if(!hdcmem) {
1330
                mempsd->FreeMemGC(mempsd);
1331
                return NULL;
1332
        }
1333
        hdcmem->psd = mempsd;
1334
 
1335
        /* select in default bitmap to setup mem device parms*/
1336
        SelectObject(hdcmem, (HGDIOBJ)&default_bitmap);
1337
        return hdcmem;
1338
}
1339
 
1340
BOOL WINAPI
1341
BitBlt(HDC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,
1342
        HDC hdcSrc, int nXSrc, int nYSrc, DWORD dwRop)
1343
{
1344
        /* use stretch blit with equal src and dest width/height*/
1345
        return StretchBlt(hdcDest, nXDest, nYDest, nWidth, nHeight,
1346
                hdcSrc, nXSrc, nYSrc, nWidth, nHeight, dwRop);
1347
}
1348
 
1349
BOOL WINAPI
1350
StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest,
1351
        int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
1352
        int nWidthSrc, int nHeightSrc, DWORD dwRop)
1353
{
1354
 
1355
        HWND    hwnd;
1356
        POINT   dst, src;
1357
 
1358
        if(!hdcDest || !hdcSrc)
1359
                return FALSE;
1360
        dst.x = nXOriginDest;
1361
        dst.y = nYOriginDest;
1362
        src.x = nXOriginSrc;
1363
        src.y = nYOriginSrc;
1364
 
1365
        /* if src screen DC, convert coords*/
1366
        /* FIXME: src clipping isn't checked, only one set of cliprects also*/
1367
        if(!MwIsMemDC(hdcSrc) && MwIsClientDC(hdcSrc)) {
1368
                if(!(hwnd = MwPrepareDC(hdcSrc)))
1369
                        return FALSE;
1370
                ClientToScreen(hwnd, &src);
1371
        }
1372
        /* if dst screen DC, convert coords and set clipping*/
1373
        /* FIXME: if dest is also screen, src clipping will be overwritten*/
1374
        if(!MwIsMemDC(hdcDest) && MwIsClientDC(hdcDest)) {
1375
                if(!(hwnd = MwPrepareDC(hdcDest)))
1376
                        return FALSE;
1377
                ClientToScreen(hwnd, &dst);
1378
        }
1379
 
1380
        if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc) {
1381
                GdBlit(hdcDest->psd, dst.x, dst.y, nWidthDest, nHeightDest,
1382
                        hdcSrc->psd, src.x, src.y, dwRop);
1383
        } else {
1384
                GdStretchBlit(hdcDest->psd, dst.x, dst.y,
1385
                        nWidthDest, nHeightDest, hdcSrc->psd, src.x, src.y,
1386
                        nWidthSrc, nHeightSrc, dwRop);
1387
        }
1388
        return TRUE;
1389
}
1390
 
1391
UINT WINAPI
1392
GetSystemPaletteEntries(HDC hdc,UINT iStartIndex,UINT nEntries,
1393
        LPPALETTEENTRY lppe)
1394
{
1395
        UINT            i;
1396
        MWPALENTRY      rgb;
1397
 
1398
        /* currently, we only work for screen device*/
1399
        if(!hdc || hdc->psd != &scrdev)
1400
                return 0;
1401
 
1402
        for(i=0; i<nEntries; ++i) {
1403
                if(!GdGetPalette(hdc->psd, i+iStartIndex, 1, &rgb))
1404
                        break;
1405
                lppe->peRed = rgb.r;
1406
                lppe->peGreen = rgb.g;
1407
                lppe->peBlue = rgb.b;
1408
                lppe->peFlags = 0;
1409
                ++lppe;
1410
        }
1411
        return i;
1412
}
1413
 
1414
/* allow NULL hdc for scrdev*/
1415
int WINAPI
1416
GetDeviceCaps(HDC hdc, int nIndex)
1417
{
1418
        PSD     psd;
1419
 
1420
        if (!hdc)
1421
                psd = &scrdev;
1422
        else psd = hdc->psd;
1423
 
1424
        switch(nIndex) {
1425
        case HORZRES:
1426
                return psd->xvirtres;
1427
        case VERTRES:
1428
                return psd->yvirtres;
1429
        case BITSPIXEL:
1430
                return psd->bpp;
1431
        case PLANES:
1432
                return psd->planes;
1433
        case LOGPIXELSX:
1434
        case LOGPIXELSY:
1435
                return 96;
1436
        case SIZEPALETTE:
1437
                if (psd->bpp <= 8)
1438
                        return psd->ncolors;
1439
                break;
1440
        }
1441
        return 0;
1442
}

powered by: WebSVN 2.1.0

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