summaryrefslogtreecommitdiff
path: root/vcl/os2/source/gdi/salgdi2.cxx
blob: ccc966d13aa3c962beaf45a5a0ff335c2ebff398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
/*************************************************************************
 *
 *  $RCSfile: salgdi2.cxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000-09-18 17:05:34 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include <string.h>
#include <tools/svpm.h>

#define _SV_SALGDI2_CXX

#ifndef _SV_SALBMP_HXX
#include <salbmp.hxx>
#endif
#ifndef _SV_SALDATA_HXX
#include <saldata.hxx>
#endif
#ifndef _SV_SALIDS_HRC
#include <salids.hrc>
#endif
#ifndef _SV_SALGDI_HXX
#include <salgdi.hxx>
#endif
#ifndef _SV_SALVD_HXX
#include <salvd.hxx>
#endif
#ifndef _SV_SALBTYPE_HXX
#include <salbtype.hxx>
#endif

BOOL bFastTransparent = FALSE;

// -----------
// - Defines -
// -----------

#define RGBCOLOR( r, g, b ) ((ULONG)(((BYTE)(b)|((USHORT)(g)<<8))|(((ULONG)(BYTE)(r))<<16)))
#define TY( y )             (maGraphicsData.mnHeight-(y)-1)

// ---------------
// - SalGraphics -
// ---------------

void SalGraphics::CopyBits( const SalTwoRect* pPosAry, SalGraphics* pSrcGraphics )
{
    HPS     hSrcPS;
    POINTL  thePoints[4];
    long    nSrcHeight;

    if ( pSrcGraphics )
    {
        hSrcPS = pSrcGraphics->maGraphicsData.mhPS;
        nSrcHeight = pSrcGraphics->maGraphicsData.mnHeight;
    }
    else
    {
        hSrcPS = maGraphicsData.mhPS;
        nSrcHeight = maGraphicsData.mnHeight;
    }

    // lower-left corner of target
    thePoints[0].x = pPosAry->mnDestX;
    thePoints[0].y = TY( pPosAry->mnDestY + pPosAry->mnDestHeight - 1 );

    // upper-right corner of target
    thePoints[1].x = pPosAry->mnDestX + pPosAry->mnDestWidth;
    thePoints[1].y = TY( pPosAry->mnDestY - 1 );

    // lower-left corner of source
    thePoints[2].x = pPosAry->mnSrcX;
    thePoints[2].y = nSrcHeight - ( pPosAry->mnSrcY + pPosAry->mnSrcHeight );

    if ( ( pPosAry->mnDestWidth != pPosAry->mnSrcWidth ) || ( pPosAry->mnDestHeight != pPosAry->mnSrcHeight ) )
    {
        // upper-right corner of Source
        thePoints[3].x = pPosAry->mnSrcX + pPosAry->mnSrcWidth;
        thePoints[3].y = nSrcHeight - pPosAry->mnSrcY + pPosAry->mnSrcHeight;

        GpiBitBlt( maGraphicsData.mhPS, hSrcPS, 4, thePoints,
                   maGraphicsData.mbXORMode ? ROP_SRCINVERT : ROP_SRCCOPY, BBO_IGNORE );
    }
    else
    {
        GpiBitBlt( maGraphicsData.mhPS, hSrcPS, 3, thePoints,
                   maGraphicsData.mbXORMode ? ROP_SRCINVERT : ROP_SRCCOPY, BBO_IGNORE );
    }
}

// -----------------------------------------------------------------------

void SalGraphics::CopyArea( long nDestX, long nDestY,
                            long nSrcX, long nSrcY,
                            long nSrcWidth, long nSrcHeight,
                            USHORT nFlags )
{
    POINTL thePoints[3];

    // lower-left corner of target
    thePoints[0].x = nDestX;
    thePoints[0].y = TY( nDestY + nSrcHeight - 1 );

    // upper-right corner of target
    thePoints[1].x = nDestX + nSrcWidth;
    thePoints[1].y = TY( nDestY - 1 );

    // lower-left corner of source
    thePoints[2].x = nSrcX;
    thePoints[2].y = TY( nSrcY + nSrcHeight - 1);

    GpiBitBlt( maGraphicsData.mhPS, maGraphicsData.mhPS, 3, thePoints,
               ROP_SRCCOPY, BBO_IGNORE );

    if ( (nFlags & SAL_COPYAREA_WINDOWINVALIDATE) && maGraphicsData.mbWindow )
    {
        // Overlap-Bereich berechnen und invalidieren
        Point       aVCLSrcPos( nSrcX, nSrcY );
        Size        aVCLSrcSize( nSrcWidth, nSrcHeight );
        Rectangle   aVCLSrcRect( aVCLSrcPos, aVCLSrcSize );
        Rectangle   aVCLClipRect;
        SWP         aSWP;

        WinQueryWindowPos( maGraphicsData.mhWnd, &aSWP );
        aVCLClipRect.Right()    = aSWP.cx-1;
        aVCLClipRect.Bottom()   = aSWP.cy-1;
        if ( !aVCLSrcRect.Intersection( aVCLClipRect ).IsEmpty() )
        {
            RECTL   aSrcRect;
            RECTL   aTempRect;
            HRGN    hInvalidateRgn;
            HRGN    hTempRgn;
            HWND    hWnd;
            long    nRgnType;

            long nVCLScrHeight  = aVCLSrcRect.GetHeight();
            aSrcRect.xLeft      = aVCLSrcRect.Left();
            aSrcRect.yBottom    = TY( aVCLSrcRect.Top()+nVCLScrHeight-1 );
            aSrcRect.xRight     = aSrcRect.xLeft+aVCLSrcRect.GetWidth();
            aSrcRect.yTop       = aSrcRect.yBottom+nVCLScrHeight;

            // Rechteck in Screen-Koordinaaten umrechnen
            POINTL  aPt;
            long    nScreenDX = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
            long    nScreenDY = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
            aPt.x = 0;
            aPt.y = 0;
            WinMapWindowPoints( maGraphicsData.mhWnd, HWND_DESKTOP, &aPt, 1 );
            aSrcRect.xLeft   += aPt.x;
            aSrcRect.yTop    += aPt.y;
            aSrcRect.xRight  += aPt.x;
            aSrcRect.yBottom += aPt.y;
            hInvalidateRgn = 0;
            // Bereiche ausserhalb des sichtbaren Bereiches berechnen
            if ( aSrcRect.xLeft < 0 )
            {
                if ( !hInvalidateRgn )
                    hInvalidateRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                aTempRect.xLeft     = -31999;
                aTempRect.yBottom   = 0;
                aTempRect.xRight    = 0;
                aTempRect.yTop      = 31999;
                hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aTempRect );
                GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hInvalidateRgn, hTempRgn, CRGN_DIFF );
                GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
            }
            if ( aSrcRect.yBottom < 0 )
            {
                if ( !hInvalidateRgn )
                    hInvalidateRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                aTempRect.xLeft     = 0;
                aTempRect.yBottom   = -31999;
                aTempRect.xRight    = 31999;
                aTempRect.yTop      = 0;
                hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aTempRect );
                GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hInvalidateRgn, hTempRgn, CRGN_DIFF );
                GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
            }
            if ( aSrcRect.xRight > nScreenDX )
            {
                if ( !hInvalidateRgn )
                    hInvalidateRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                aTempRect.xLeft     = nScreenDX;
                aTempRect.yBottom   = 0;
                aTempRect.xRight    = 31999;
                aTempRect.yTop      = 31999;
                hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aTempRect );
                GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hInvalidateRgn, hTempRgn, CRGN_DIFF );
                GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
            }
            if ( aSrcRect.yTop > nScreenDY )
            {
                if ( !hInvalidateRgn )
                    hInvalidateRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                aTempRect.xLeft     = 0;
                aTempRect.yBottom   = nScreenDY;
                aTempRect.xRight    = 31999;
                aTempRect.yTop      = 31999;
                hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aTempRect );
                GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hInvalidateRgn, hTempRgn, CRGN_DIFF );
                GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
            }

            // Bereiche die von anderen Fenstern ueberlagert werden berechnen
            HWND hWndParent = WinQueryWindow( maGraphicsData.mhWnd, QW_PARENT );
            hWnd = WinQueryWindow( HWND_DESKTOP, QW_TOP );
            aVCLSrcRect = Rectangle( aSrcRect.xLeft, aSrcRect.yBottom, aSrcRect.xRight, aSrcRect.yTop );
            while ( hWnd )
            {
                if ( hWnd == hWndParent )
                    break;
                if ( WinIsWindowVisible( hWnd ) )
                {
                    WinQueryWindowPos( hWnd, &aSWP );
                    if ( !(aSWP.fl & SWP_MINIMIZE) )
                    {
                        aVCLClipRect = Rectangle( Point( aSWP.x, aSWP.y ), Size( aSWP.cx, aSWP.cy ) );
                        if ( aVCLSrcRect.IsOver( aVCLClipRect ) )
                        {
                            if ( !hInvalidateRgn )
                                hInvalidateRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                            aTempRect.xLeft     = aSWP.x;
                            aTempRect.yBottom   = aSWP.y;
                            aTempRect.xRight    = aTempRect.xLeft+aSWP.cx;
                            aTempRect.yTop      = aTempRect.yBottom+aSWP.cy;
                            hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aTempRect );
                            GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hInvalidateRgn, hTempRgn, CRGN_DIFF );
                            GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
                        }
                    }
                }
                hWnd = WinQueryWindow( hWnd, QW_NEXT );
            }

            if ( hInvalidateRgn )
            {
                hTempRgn = GpiCreateRegion( maGraphicsData.mhPS, 1, &aSrcRect );
                nRgnType = GpiCombineRegion( maGraphicsData.mhPS, hInvalidateRgn, hTempRgn, hInvalidateRgn, CRGN_DIFF );
                GpiDestroyRegion( maGraphicsData.mhPS, hTempRgn );
                if ( (nRgnType != RGN_ERROR) && (nRgnType != RGN_NULL) )
                {
                    long nOffX = (nDestX-nSrcX);
                    long nOffY = (nSrcY-nDestY);
                    aPt.x = nOffX-aPt.x;
                    aPt.y = nOffY-aPt.y;
                    GpiOffsetRegion( maGraphicsData.mhPS, hInvalidateRgn, &aPt );
                    WinInvalidateRegion( maGraphicsData.mhWnd, hInvalidateRgn, TRUE );
                    // Hier loesen wir nur ein Update aus, wenn es der
                    // MainThread ist, damit es beim Bearbeiten der
                    // Paint-Message keinen Deadlock gibt, da der
                    // SolarMutex durch diesen Thread schon gelockt ist
                    SalData*    pSalData = GetSalData();
                    ULONG       nCurThreadId = ImplSalGetCurrentThreadId();
                    if ( pSalData->mnAppThreadId != nCurThreadId )
                        WinUpdateWindow( maGraphicsData.mhWnd );
                }
                GpiDestroyRegion( maGraphicsData.mhPS, hInvalidateRgn );
            }
        }
    }
}

// -----------------------------------------------------------------------

void ImplDrawBitmap( HPS hPS, long nScreenHeight,
                     const SalTwoRect* pPosAry, const SalBitmap& rSalBitmap,
                     BOOL bPrinter, int nDrawMode )
{
    if( hPS )
    {
        HANDLE      hDrawDIB;
        HBITMAP     hDrawDDB = rSalBitmap.ImplGethDDB();
        SalBitmap*  pTmpSalBmp = NULL;
        BOOL        bPrintDDB = ( bPrinter && hDrawDDB );
        BOOL        bDrawDDB1 = ( ( rSalBitmap.GetBitCount() == 1 ) && hDrawDDB );

        if( bPrintDDB || bDrawDDB1 )
        {
            pTmpSalBmp = new SalBitmap;
            pTmpSalBmp->Create( rSalBitmap, rSalBitmap.GetBitCount() );
            hDrawDIB = pTmpSalBmp->ImplGethDIB();
        }
        else
            hDrawDIB = rSalBitmap.ImplGethDIB();

        if( hDrawDIB )
        {
            HANDLE              hSubst = rSalBitmap.ImplGethDIB1Subst();
            POINTL              pts[ 4 ];
            BITMAPINFO2*        pBI = (BITMAPINFO2*) hDrawDIB;
            BITMAPINFOHEADER2*  pBIH = (BITMAPINFOHEADER2*) pBI;
            const long          nHeight = pBIH->cy;
            long                nInfoSize = *(ULONG*) pBI + rSalBitmap.ImplGetDIBColorCount( hDrawDIB ) * sizeof( RGB2 );
            BYTE*               pBits = (BYTE*) pBI + nInfoSize;

            pts[0].x = pPosAry->mnDestX;
            pts[0].y = nScreenHeight - pPosAry->mnDestY - pPosAry->mnDestHeight;
            pts[1].x = pPosAry->mnDestX + pPosAry->mnDestWidth - 1;
            pts[1].y = nScreenHeight - pPosAry->mnDestY - 1;

            pts[2].x = pPosAry->mnSrcX;
            pts[2].y = nHeight - ( pPosAry->mnSrcY + pPosAry->mnSrcHeight );
            pts[3].x = pPosAry->mnSrcX + pPosAry->mnSrcWidth;
            pts[3].y = nHeight - pPosAry->mnSrcY;

            // if we've got a 1Bit DIB, we create a 4Bit substitute
            if( ( pBIH->cBitCount == 1 ) && !hSubst )
            {
                // create 4Bit substitute
                hSubst = SalBitmap::ImplCreateDIB4FromDIB1( hDrawDIB );

                // replace substitute only, if it is no temporary SalBitmap
                if( !( bPrintDDB || bDrawDDB1 ) )
                    ( (SalBitmap&) rSalBitmap ).ImplReplacehDIB1Subst( hSubst );
            }

            if( hSubst )
            {
                pBI = (BITMAPINFO2*) hSubst;
                pBIH = (BITMAPINFOHEADER2*) pBI;
                nInfoSize = *(ULONG*) pBI + rSalBitmap.ImplGetDIBColorCount( hSubst ) * sizeof( RGB2 );
                pBits = (BYTE*) pBI + nInfoSize;
            }

            if( bPrinter )
            {
                BYTE* pDummy;

                // expand 8Bit-DIB's to 24Bit-DIB's, because some printer drivers
                // have problems to print these DIB's (strange)
                if( pBIH->cBitCount == 8 && pBIH->ulCompression == BCA_UNCOMP )
                {
                    const long          nWidth = pBIH->cx;
                    const long          nHeight = pBIH->cy;
                    const long          nWidthAl8 = AlignedWidth4Bytes( nWidth * 8 );
                    const long          nWidthAl24 = AlignedWidth4Bytes( nWidth * 24 );
                    const long          nNewImageSize = nHeight * nWidthAl24;
                    BITMAPINFOHEADER2*  pNewInfo;

                    pDummy = new BYTE[ sizeof( BITMAPINFO2 ) + nNewImageSize ];
                    memset( pDummy, 0, sizeof( BITMAPINFO2 ) );

                    pNewInfo = (BITMAPINFOHEADER2*) pDummy;
                    pNewInfo->cbFix = sizeof( BITMAPINFOHEADER2 );
                    pNewInfo->cx = nWidth;
                    pNewInfo->cy = nHeight;
                    pNewInfo->cPlanes = 1;
                    pNewInfo->cBitCount = 24;
                    pNewInfo->ulCompression = BCA_UNCOMP;
                    pNewInfo->cbImage = nNewImageSize;

                    BYTE* pBitsSrc = (BYTE*) pBIH + nInfoSize;
                    BYTE* pBitsDst = pDummy + sizeof( BITMAPINFO2 );

                    for( long nY = 0UL; nY < nHeight; nY++ )
                    {
                        BYTE* pSrcLine = pBitsSrc + nY * nWidthAl8;
                        BYTE* pDstLine = pBitsDst + nY * nWidthAl24;

                        for( long nX = 0UL; nX < nWidth; nX++ )
                        {
                            const RGB2& rQuad = pBI->argbColor[ *pSrcLine++ ];

                            *pDstLine++ = rQuad.bBlue;
                            *pDstLine++ = rQuad.bGreen;
                            *pDstLine++ = rQuad.bRed;
                        }
                    }

                    nInfoSize = sizeof( BITMAPINFO2 );
                }
                else
                {
                    const long nImageSize = ( pBIH->cbImage ? pBIH->cbImage : ( pBIH->cy * AlignedWidth4Bytes( pBIH->cx * pBIH->cBitCount ) ) );
                    const long nTotalSize = nInfoSize + nImageSize;

                    pDummy = new BYTE[ nTotalSize ];
                    memcpy( pDummy, pBI, nTotalSize );
                }

                GpiDrawBits( hPS, pDummy + nInfoSize, (BITMAPINFO2*) pDummy, 4L, pts, nDrawMode, BBO_IGNORE );
                delete[] pDummy;
            }
            else
                GpiDrawBits( hPS, pBits, pBI, 4L, pts, nDrawMode, BBO_IGNORE );
        }
        else if( hDrawDDB && !bPrintDDB )
        {
            POINTL pts[ 4 ];

            pts[0].x = pPosAry->mnDestX;
            pts[0].y = nScreenHeight - pPosAry->mnDestY - pPosAry->mnDestHeight;
            pts[1].x = pPosAry->mnDestX + pPosAry->mnDestWidth - 1;
            pts[1].y = nScreenHeight - pPosAry->mnDestY - 1;

            pts[2].x = pPosAry->mnSrcX;
            pts[2].y = rSalBitmap.GetSize().Height() - ( pPosAry->mnSrcY + pPosAry->mnSrcHeight );
            pts[3].x = pPosAry->mnSrcX + pPosAry->mnSrcWidth;
            pts[3].y = rSalBitmap.GetSize().Height() - pPosAry->mnSrcY;

            GpiWCBitBlt( hPS, hDrawDDB, 4L, pts, nDrawMode, BBO_IGNORE );
/*
            HPS hDrawPS = ImplGetCachedPS( CACHED_HPS_DRAW, hDrawDDB );
            GpiBitBlt( hPS, hDrawPS, 4, pts, nDrawMode, BBO_IGNORE );
            ImplReleaseCachedPS( CACHED_HPS_DRAW );
*/
        }

        if( bPrintDDB || bDrawDDB1 )
            delete pTmpSalBmp;
    }
}

// -----------------------------------------------------------------------

void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry,
                              const SalBitmap& rSalBitmap )
{
    ImplDrawBitmap( maGraphicsData.mhPS, maGraphicsData.mnHeight,
                    pPosAry, rSalBitmap,
                    maGraphicsData.mbPrinter,
                    maGraphicsData.mbXORMode ? ROP_SRCINVERT : ROP_SRCCOPY );
}

// -----------------------------------------------------------------------

void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry,
                              const SalBitmap& rSalBitmap,
                              SalColor nTransparentColor )
{
    // an FM: kann erst einmal unberuecksichtigt bleiben
    DrawBitmap( pPosAry, rSalBitmap );
}

// -----------------------------------------------------------------------

void SalGraphics::DrawBitmap( const SalTwoRect* pPosAry,
                              const SalBitmap& rSalBitmap,
                              const SalBitmap& rTransparentBitmap )
{
    if( bFastTransparent )
    {
        ImplDrawBitmap( maGraphicsData.mhPS, maGraphicsData.mnHeight, pPosAry, rTransparentBitmap, FALSE, ROP_SRCAND );
        ImplDrawBitmap( maGraphicsData.mhPS, maGraphicsData.mnHeight, pPosAry, rSalBitmap, FALSE, ROP_SRCPAINT );
    }
    else
    {
        SalTwoRect      aPosAry = *pPosAry;
        int             nDstX = (int) aPosAry.mnDestX;
        int             nDstY = (int) aPosAry.mnDestY;
        int             nDstWidth = (int) aPosAry.mnDestWidth;
        int             nDstHeight = (int) aPosAry.mnDestHeight;
        HAB             hAB = GetSalData()->mhAB;
        HPS             hPS = maGraphicsData.mhPS;
        DEVOPENSTRUC    aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
        SIZEL           aSizeL = { nDstWidth, nDstHeight };
        POINTL          aPtL[ 3 ];

        HDC                hMemDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5L, (PDEVOPENDATA)&aDevOpenStruc, 0 );
        HPS                hMemPS = GpiCreatePS( hAB, hMemDC, &aSizeL, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
        HBITMAP            hMemBitmap = ImplCreateVirDevBitmap( hMemDC, hMemPS, nDstWidth, nDstHeight, 0 );
        HBITMAP            hMemOld = (HBITMAP) GpiSetBitmap( hMemPS, hMemBitmap );
        HDC                hMaskDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5L, (PDEVOPENDATA)&aDevOpenStruc, 0 );
        HPS                hMaskPS = GpiCreatePS( hAB, hMaskDC, &aSizeL, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
        HBITMAP            hMaskBitmap = ImplCreateVirDevBitmap( hMaskDC, hMaskPS, nDstWidth, nDstHeight, 0 );
        HBITMAP            hMaskOld = (HBITMAP) GpiSetBitmap( hMaskPS, hMaskBitmap );
/*
        HPS hMemPS = ImplGetCachedPS( CACHED_HPS_1, 0 );
        HPS hMaskPS = ImplGetCachedPS( CACHED_HPS_2, 0 );
*/
        aPosAry.mnDestX = aPosAry.mnDestY = 0L;

        aPtL[ 0 ].x = 0;
        aPtL[ 0 ].y = 0;
        aPtL[ 1 ].x = nDstWidth;
        aPtL[ 1 ].y = nDstHeight;
        aPtL[ 2 ].x = nDstX;
        aPtL[ 2 ].y = TY( nDstY + nDstHeight - 1 );

        GpiBitBlt( hMemPS, hPS, 3, aPtL, ROP_SRCCOPY, BBO_IGNORE );
        ImplDrawBitmap( hMaskPS, nDstHeight, &aPosAry, rTransparentBitmap, FALSE, ROP_SRCCOPY );

        aPtL[ 2 ].x = 0;
        aPtL[ 2 ].y = 0;

        GpiBitBlt( hMemPS, hMaskPS, 3, aPtL, ROP_SRCAND, BBO_IGNORE );
        ImplDrawBitmap( hMaskPS, nDstHeight, &aPosAry, rSalBitmap, FALSE, ROP_SRCERASE );
        GpiBitBlt( hMemPS, hMaskPS, 3, aPtL, ROP_SRCPAINT, BBO_IGNORE );

        aPtL[ 0 ].x = nDstX;
        aPtL[ 0 ].y = TY( nDstY + nDstHeight - 1 );
        aPtL[ 1 ].x = nDstX + nDstWidth;
        aPtL[ 1 ].y = TY( nDstY - 1 );

        GpiBitBlt( hPS, hMemPS, 3, aPtL, ROP_SRCCOPY, BBO_IGNORE );

        GpiSetBitmap( hMaskPS, hMaskOld );
        GpiDestroyPS( hMaskPS );
        DevCloseDC( hMaskDC );
        GpiDeleteBitmap( hMaskBitmap );

        GpiSetBitmap( hMemPS, hMemOld );
        GpiDestroyPS( hMemPS );
        DevCloseDC( hMemDC );
        GpiDeleteBitmap( hMemBitmap );

/*
        ImplReleaseCachedPS( CACHED_HPS_1 );
        ImplReleaseCachedPS( CACHED_HPS_2 );
*/
    }
}

// -----------------------------------------------------------------------

void SalGraphics::DrawMask( const SalTwoRect* pPosAry,
                            const SalBitmap& rSalBitmap,
                            SalColor nMaskColor )
{
    SalTwoRect  aPosAry = *pPosAry;
    HPS         hPS = maGraphicsData.mhPS;
    IMAGEBUNDLE aBundle, aOldBundle;
    AREABUNDLE  aAreaBundle, aOldAreaBundle;
    const ULONG    nColor = RGBCOLOR( SALCOLOR_RED( nMaskColor ),
                                    SALCOLOR_GREEN( nMaskColor ),
                                    SALCOLOR_BLUE( nMaskColor ) );

    GpiQueryAttrs( hPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR, &aOldBundle );
    aBundle.lColor = RGBCOLOR( 0, 0, 0 );
    aBundle.lBackColor = RGBCOLOR( 0xFF, 0xFF, 0xFF );
    GpiSetAttrs( hPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR, 0, &aBundle );

    GpiQueryAttrs( hPS, PRIM_AREA, ABB_COLOR | ABB_BACK_COLOR | ABB_SYMBOL |
                   ABB_MIX_MODE | ABB_BACK_MIX_MODE, &aOldAreaBundle );
    aAreaBundle.lColor = nColor;
    aAreaBundle.lBackColor = nColor;
    aAreaBundle.usSymbol = PATSYM_SOLID;
    aAreaBundle.usMixMode = FM_OVERPAINT;
    aAreaBundle.usBackMixMode = BM_OVERPAINT;
    GpiSetAttrs( hPS, PRIM_AREA, ABB_COLOR | ABB_BACK_COLOR | ABB_SYMBOL |
                 ABB_MIX_MODE | ABB_BACK_MIX_MODE, 0, &aAreaBundle );

    ImplDrawBitmap( hPS, maGraphicsData.mnHeight, &aPosAry, rSalBitmap, FALSE, 0x00B8L );

    GpiSetAttrs( hPS, PRIM_IMAGE, IBB_COLOR | IBB_BACK_COLOR, 0, &aOldBundle );
    GpiSetAttrs( hPS, PRIM_AREA, ABB_COLOR | ABB_BACK_COLOR | ABB_SYMBOL |
                 ABB_MIX_MODE | ABB_BACK_MIX_MODE, 0, &aOldAreaBundle );
}

// -----------------------------------------------------------------------

SalBitmap* SalGraphics::GetBitmap( long nX, long nY, long nDX, long nDY )
{
    HAB            hAB = GetSalData()->mhAB;
    SIZEL        size = { nDX, nDY };
    SalBitmap*    pSalBitmap = NULL;

    // create device context (at this time allways display compatible)
    DEVOPENSTRUC    aDevOpenStruc = { NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL };
    HDC             hMemDC = DevOpenDC( hAB, OD_MEMORY, (PSZ)"*", 5L, (PDEVOPENDATA)&aDevOpenStruc, 0 );
    HPS             hMemPS = GpiCreatePS( hAB, hMemDC, &size, GPIT_MICRO | GPIA_ASSOC | PU_PELS );
    HBITMAP         hMemBmp = ImplCreateVirDevBitmap( hMemDC, hMemPS, nDX, nDY, 0 );
    HBITMAP         hMemOld = GpiSetBitmap( hMemPS, hMemBmp );

    // creation successfull?
    if( hMemDC && hMemPS && hMemBmp )
    {
        POINTL thePoints[ 3 ];

        // lower-left corner of target
        thePoints[ 0 ].x = 0;
        thePoints[ 0 ].y = 0;

        // upper-right corner of target
        thePoints[ 1 ].x = nDX;
        thePoints[ 1 ].y = nDY;

        // lower-left corner of source
        thePoints[ 2 ].x = nX;
        thePoints[ 2 ].y = TY( nY + nDY - 1 );

        long lHits = GpiBitBlt( hMemPS, maGraphicsData.mhPS, 3, thePoints,
                                maGraphicsData.mbXORMode ? ROP_SRCINVERT : ROP_SRCCOPY, BBO_IGNORE );

        if( hMemPS )
        {
            GpiSetBitmap( hMemPS, hMemOld );
            GpiDestroyPS( hMemPS );
        }

        if( hMemDC )
            DevCloseDC( hMemDC );

        if( lHits == GPI_OK )
        {
            pSalBitmap = new SalBitmap;

            if( !pSalBitmap->Create( hMemBmp, FALSE, FALSE ) )
            {
                delete pSalBitmap;
                pSalBitmap = NULL;
            }
        }
    }

    if( !pSalBitmap )
        GpiDeleteBitmap( hMemBmp );

    // return pointer to SAL-Bitmap
    return pSalBitmap;
}

// -----------------------------------------------------------------------

SalColor SalGraphics::GetPixel( long nX, long nY )
{
    POINTL    aPt = { nX, TY( nY ) };
    LONG    nColor = GpiQueryPel( maGraphicsData.mhPS, &aPt );

    return MAKE_SALCOLOR( (BYTE) ( nColor >> 16 ), (BYTE) ( nColor >> 8 ), (BYTE) nColor );
}

// -----------------------------------------------------------------------

void SalGraphics::Invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags )
{
    if( nFlags & SAL_INVERT_TRACKFRAME )
    {
        // save old vylues
        LINEBUNDLE oldLb;
        LINEBUNDLE lb;
        GpiQueryAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, &oldLb );

        // set linetype to short dash
        lb.lColor = RGBCOLOR( 255, 255, 255 );
        lb.usMixMode = FM_XOR;
        lb.usType = LINETYPE_ALTERNATE;
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, 0, &lb );

        // draw inverted box
        POINTL aPt;

        aPt.x = nX;
        aPt.y = TY( nY );

        GpiMove( maGraphicsData.mhPS, &aPt );

        aPt.x = nX + nWidth - 1;
        aPt.y = TY( nY + nHeight - 1 );

        GpiBox( maGraphicsData.mhPS, DRO_OUTLINE, &aPt, 0, 0 );

        // restore old values
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, 0, &oldLb );

    }
    else
    {
        // save old values
        AREABUNDLE oldAb;
        AREABUNDLE ab;

        GpiQueryAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, &oldAb );

        // set fill color to black
        ab.lColor = RGBCOLOR( 255, 255, 255 );
        ab.usMixMode = FM_XOR;
        ab.usSymbol = (nFlags & SAL_INVERT_50) ? PATSYM_DENSE5 : PATSYM_SOLID;
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, 0, &ab );

        // draw inverted box
        POINTL aPt;

        aPt.x = nX;
        aPt.y = TY( nY );

        GpiMove( maGraphicsData.mhPS, &aPt );

        aPt.x = nX + nWidth - 1;
        aPt.y = TY( nY + nHeight - 1 );

        GpiBox( maGraphicsData.mhPS, DRO_FILL, &aPt, 0, 0 );

        // restore old values
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, 0, &oldAb );
    }
}

// -----------------------------------------------------------------------

void SalGraphics::Invert( ULONG nPoints, const SalPoint* pPtAry, SalInvert nFlags )
{
    if( nFlags & SAL_INVERT_TRACKFRAME )
    {
        // save old vylues
        LINEBUNDLE oldLb;
        LINEBUNDLE lb;
        GpiQueryAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, &oldLb );

        // set linetype to short dash
        lb.lColor = RGBCOLOR( 255, 255, 255 );
        lb.usMixMode = FM_XOR;
        lb.usType = LINETYPE_ALTERNATE;
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, 0, &lb );

        // Draw Polyline
        DrawPolyLine( nPoints, pPtAry );

        // restore old values
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_LINE, LBB_MIX_MODE | LBB_TYPE | LBB_COLOR, 0, &oldLb );
    }
    else
    {
        // save old values
        AREABUNDLE oldAb;
        AREABUNDLE ab;

        GpiQueryAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, &oldAb );

        // set fill color to black
        ab.lColor = RGBCOLOR( 255, 255, 255 );
        ab.usMixMode = FM_XOR;
        ab.usSymbol = (nFlags & SAL_INVERT_50) ? PATSYM_DENSE5 : PATSYM_SOLID;
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, 0, &ab );

        // Draw Polyline
        DrawPolygon( nPoints, pPtAry );

        // restore old values
        GpiSetAttrs( maGraphicsData.mhPS, PRIM_AREA, ABB_COLOR | ABB_MIX_MODE | ABB_SYMBOL, 0, &oldAb );
    }
}