Ignore:
Timestamp:
Feb 6, 2006, 10:43:39 PM (20 years ago)
Author:
dmik
Message:

Implemented QRegion(..., QRegion::Eclipse) and QRegion(QPointArray &,...) constructors.
Improved Qt<->GPI region coordinates translation (it's now implicit), QRegion::handle() takes a height of the target devise as an argument (defaults to 0).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel/qpainter_pm.cpp

    r59 r61  
    4242#include "qpixmapcache.h"
    4343#include "qptrlist.h"
    44 //@@TODO (dmik): later
     44/// @todo (dmik) later
    4545//#include "qprinter.h"
    4646#include <stdlib.h>
     
    5353#include "qfontengine_p.h"
    5454
    55 //@@TODO (dmik): does OS/2 have this bug?
    56 ///*
    57 //  Workaround for win32 bug. When GM_ADVANCED graphicsmode is used with a non identity
    58 //  matrix, subsequent calls to Ellipse, Chord and Pie will be inclusive. Also after
    59 //  graphics mode is reset to GM_COMPATIBLE. This causes ellipses to grow in size
    60 //  after a call to drawText when the painter is transformated.
    61 //
    62 //  To work around this we register if a non identity transform is set in
    63 //  QPainter::nativeXForm() and reduce the size by one if native xform has been used.
    64 //
    65 //  Testcase for confirmation is checked in in:
    66 //  //depot/manualtests/platformbugs/win32/ellipseafteradvgrmode.cpp
    67 //*/
    68 
    6955// QRgb has the same RGB format (0xaarrggbb) as OS/2 uses (ignoring the
    7056// highest alpha byte) so we just mask alpha to get the valid OS/2 color.
    7157#define COLOR_VALUE(c) ((flags & RGBColor) ? (c.rgb() & RGB_MASK) : c.pixel())
    7258
    73 //@@TODO (dmik): Innotek GCC 3.2.2 beta 4 CSD1 lacks this function in
    74 //  its version of the toolkit header. This should be fixed soon.
     59// Innotek GCC lacks some API functions in its version of OS/2 Toolkit headers
    7560#if defined(Q_CC_GNU) && !defined(USE_OS2_TOOLKIT_HEADERS)
    7661extern "C" LONG  APIENTRY GpiQueryNearestPaletteIndex(HPAL hpal, ULONG color);
     
    10085    rc &= GpiSetAttrs( hps, PRIM_LINE, LBB_BACK_MIX_MODE, 0, (PBUNDLE) &lb );
    10186    return rc;
    102 }
    103 
    104 // helper function to select clip regions to the hps
    105 void qt_GpiSetClipRegion( HPS hps, HRGN hrgn, int devh, HRGN *hrgnOldRet )
    106 {
    107     if ( hrgn ) {
    108         // convert region y coordinates from Qt to GPI (see qregion_pm.cpp)
    109         if ( devh ) {
    110             POINTL ptl = { 0, devh };
    111             GpiOffsetRegion( hps, hrgn, &ptl );
    112         }
    113     }
    114     HRGN hrgnOld;
    115     GpiSetClipRegion( hps, hrgn, &hrgnOld );
    116     if ( hrgnOldRet )
    117         *hrgnOldRet = hrgnOld;
    118     else
    119         GpiDestroyRegion( hps, hrgnOld );
    12087}
    12188
     
    183150    }
    184151    if ( bg_pixmap ) {
    185 //@@TODO (dmik): don't realize why the windows code doesn't do it...
    186152        // normalize pixmap offsets according to x and y
    187153        // to ensure that the offsets are always relative to
     
    224190{
    225191    d = 0;
    226 //@@TODO (dmik): later
    227 //    hasUsedNativeXForm = FALSE;
    228 //    usingNativeXForm = FALSE;
    229192    flags = IsStartingUp;
    230193    pdev = 0;
     
    240203    wm_stack = 0;
    241204    hps = 0;
    242 //@@TODO (dmik): remove?
    243 //    hpen = 0;
    244 //    hbrush = 0;
    245 //    hfont = 0;
    246205    holdpal = 0;
    247     holdrgn = 0;
     206    holdrgn = HRGN_ERROR;
    248207    hbrushbm = 0;
    249208    pixmapBrush = nocolBrush = FALSE;
     
    407366    }
    408367
    409     //@@TODO (dmik): possibly pixmapBrush is not needed, hbrushbm and
     368    /// @todo (dmik) possibly pixmapBrush is not needed, hbrushbm and
    410369    //  CustomPattern can substitute it.
    411370    pixmapBrush = nocolBrush = FALSE;
     
    521480    hps = 0;
    522481    holdpal = 0;
    523     holdrgn = 0;
     482    holdrgn = HRGN_ERROR;
    524483    devh = 0;
    525484
    526     QRegion *pRepaintRgn = 0;
     485    QRegion *repaintRgn = 0;
    527486
    528487    if ( testf(ExtDev) ) {                      // external device
     
    574533        devh = wh;                              // for final y coord. flipping
    575534        if ( !w->isDesktop() )
    576             pRepaintRgn =                       // clip rgn passed from repaint()
     535            repaintRgn =                        // clip rgn passed from repaint()
    577536                (QRegion *) WinQueryWindowULong( w->winId(), QWL_QTCLIPRGN );
    578537        if ( w->testWState(Qt::WState_InPaintEvent) ) {
    579538            hps = w->hps;                       // during paint event
    580539        } else {
    581             if ( w->isDesktop() ) {
    582                 hps = WinGetScreenPS( HWND_DESKTOP );
    583             } else {
    584                 if ( unclipped || w->testWFlags( WPaintUnclipped ) ) {
    585                     hps = WinGetClipPS( w->winId(), 0, PSF_PARENTCLIP );
    586                 } else {
    587                     hps = WinGetPS( w->winId() );
    588                 }
    589             }
     540            hps = w->getTargetPS ( unclipped ? QWidget::Unclipped :
     541                                               QWidget::ClipAll );
    590542            w->hps = hps;
    591543        }
     
    608560            cpen.setColor( color1 );
    609561        }
    610 //@@TODO (dmik): later
     562/// @todo (dmik) later
    611563//    } else if ( dt == QInternal::Printer ) {  // device is a printer
    612564//      if ( pdev->handle() )
     
    634586        cpen = QPen( copyFrom->foregroundColor() );
    635587        bg_col = copyFrom->backgroundColor();
    636         pRepaintRgn =
     588        repaintRgn =
    637589            (QRegion *) WinQueryWindowULong( copyFrom->winId(), QWL_QTCLIPRGN );
    638590    }
     
    658610    setBrushOrigin( 0, 0 );
    659611    if ( hps ) {
    660         HRGN hrgn = 0;
    661         if ( pRepaintRgn ) {
    662             // make a shallow copy (for the case if the QWL_QTCLIPRGN pointer
    663             // will become invalid -- it should not ever happen though)
    664             repaintRgn = *pRepaintRgn;
    665             QRegion rgn = repaintRgn;
    666             // clip region in OS/2 cannot be used for anything else, make a deep copy
    667             rgn.detach();
    668             hrgn = rgn.handle();
    669             // prevent QRegion's destructor from destroying the region handle
    670             // (qt_GpiSetClipRegion does the job)
    671             rgn.data->rgn = 0;
     612        holdrgn = GpiQueryClipRegion( hps );
     613        if ( repaintRgn ) {
     614            // ensure that def_crgn is not null after assignment in any case
     615            def_crgn = repaintRgn->isNull() ? QRegion( FALSE ) : *repaintRgn;
    672616        }
    673         qt_GpiSetClipRegion( hps, hrgn, devh, &holdrgn );
     617        // clip region in GPI cannot be used for anything else, so detach it
     618        def_crgn.detach();
     619        if ( holdrgn ) {
     620            // intersect the original clip region and the region from repaint()
     621            if ( def_crgn.isNull() )
     622                def_crgn = QRegion( 0, 0, ww, wh );
     623            GpiSetClipRegion( hps, 0, NULL ); // deselect holdrgn
     624            HRGN hrgn = def_crgn.handle( devh );
     625            GpiCombineRegion( hps, hrgn, hrgn, holdrgn, CRGN_AND ); 
     626        }
     627        cur_crgn = def_crgn;
     628        if ( !cur_crgn.isNull() )
     629            GpiSetClipRegion( hps, cur_crgn.handle( devh ), NULL );
    674630    } else {
    675631        holdrgn = HRGN_ERROR;
     
    695651        GpiSetPatternSet( hps, LCID_DEFAULT );
    696652        GpiDeleteSetId( hps, LCID_QTPixmapBrush );
    697     }
    698 //@@TODO (dmik): remove or set the LCID_DEFAULT font here?
    699 //    if ( hfont ) {
    700 //      SelectObject( hdc, stock_sysfont );
    701 //      hfont = 0;
    702 //    }
    703     if ( holdrgn != HRGN_ERROR )
    704         qt_GpiSetClipRegion( hps, holdrgn, 0, NULL );
    705     if ( holdpal )
     653        hbrushbm = 0;
     654    }
     655    if ( holdrgn != HRGN_ERROR ) {
     656        GpiSetClipRegion( hps, holdrgn, NULL );
     657        holdrgn = HRGN_ERROR;
     658    }
     659    if ( holdpal ) {
    706660        GpiSelectPalette( hps, holdpal );
     661        holdpal = 0;
     662    }
    707663    if ( !pdev )
    708664        return FALSE;
     
    719675    }
    720676
     677    if ( !def_crgn.isNull() )
     678        def_crgn = QRegion();
     679    cur_crgn = def_crgn;
     680   
    721681    if ( pfont ) {
    722682        delete pfont;
     
    741701void QPainter::flush()
    742702{
    743 //@@TODO (dmik): need something here?
    744 //    GdiFlush();
    745703}
    746704
     
    945903    }
    946904
    947     HRGN hrgn = 0;
    948     QRegion rgn;
     905    // the current clip region is stored in cur_crgn, so deselect the handle
     906    // to let us operate on it. Note that the assignment op below will destroy
     907    // the handle if it is no more referred, so there is no need to do it
     908    // explicitly.
     909    GpiSetClipRegion( hps, 0, NULL );
    949910
    950911    if ( enable ) {
    951         if ( !repaintRgn.isNull() )
    952             rgn = crgn.intersect( repaintRgn );
     912        if ( !def_crgn.isNull() )
     913            cur_crgn = crgn.intersect( def_crgn );
    953914        else
    954             rgn = crgn;
     915            cur_crgn = crgn.isNull() ? QRegion( FALSE ) : crgn;
    955916#ifndef QT_NO_PRINTER
    956 //@@TODO (dmik): later
     917/// @todo (dmik) later
    957918//      if ( pdev->devType() == QInternal::Printer ) {
    958919//          double xscale = ((float)pdev->metric( QPaintDeviceMetrics::PdmPhysicalDpiX )) /
     
    971932#endif
    972933    } else {
    973         if ( !repaintRgn.isNull() )
    974             rgn = repaintRgn;
    975     }
    976 
    977     if ( !rgn.isNull() ) {
    978         // clip region in OS/2 cannot be used for anything else, make a deep copy
    979         rgn.detach();
    980         hrgn = rgn.handle();
    981         // prevent QRegion's destructor from destroying the region handle
    982         // (qt_GpiSetClipRegion does the job)
    983         rgn.data->rgn = 0;
    984     }
    985     qt_GpiSetClipRegion( hps, hrgn, devh, NULL );
     934        cur_crgn = def_crgn;
     935    }
     936
     937    // clip region in GPI cannot be used for anything else, so detach it
     938    cur_crgn.detach();
     939   
     940    if ( !cur_crgn.isNull() )
     941        GpiSetClipRegion( hps, cur_crgn.handle( devh ), NULL );
    986942}
    987943
     
    13151271        qt_end_geom_line( hps, &gh );
    13161272    }
    1317 //@@TODO (dmik): does OS/2 PM have the same bug?
    1318 //    if ( (cpen.width() == 0) && (cpen.style() == SolidLine) )
    1319 //      SetPixelV( hdc, x, y, COLOR_VALUE(cpen.color()) );
    13201273}
    13211274
     
    18241777#endif // QT_NO_BEZIER
    18251778
    1826 //@@TODO (dmik): remove?
    1827 //extern uint qt_bitblt_foreground;             // in qpaintdevice_pm.cpp
    1828 
    18291779void QPainter::drawPixmap( int x, int y, const QPixmap &pixmap,
    18301780                           int sx, int sy, int sw, int sh )
     
    18871837
    18881838    if ( txop <= TxTranslate ) {                // use optimized bitBlt
    1889 //@@TODO (dmik): remove?
    1890 //      if ( pixmap.depth() == 1 )
    1891 //          qt_bitblt_foreground = COLOR_VALUE(cpen.color());
    18921839        bitBlt( pdev, x, y, &pixmap, sx, sy, sw, sh, (RasterOp)rop );
    18931840        return;
     
    20041951    */
    20051952    QBitmap *mask = (QBitmap *)pixmap.mask();
    2006 //@@TODO (dmik): is OS/2 buggy too?
    2007 //#if 0 // Windows is too buggy, so we just use our own code (which is faster).
    20081953    if ( !testf(ExtDev) && txop <= TxTranslate && mask == 0 ) {
    20091954        if ( txop == TxTranslate )
     
    20121957        return;
    20131958    }
    2014 //#endif
    20151959    if ( sw*sh < 8192 && sw*sh < 16*w*h ) {
    20161960        int tw = sw, th = sh;
     
    20321976}
    20331977
    2034 //@@TODO (dmik): need this at all?
    20351978#if 0
    20361979//
     
    21572100        int ypos = y + si->y - ascent;
    21582101
    2159 //@@TODO (dmik): remove
    2160 //#ifndef Q_OS_TEMP
    2161 //      if ( rop != CopyROP ) {
    2162 //          // Doesn't work for non-TrueType fonts, but we dealt with those
    2163 //          // with the bitmap above.
    2164 //          BeginPath(hdc);
    2165 //      }
    2166 //#endif
    2167 
    2168 //@@TODO (dmik): do we really need this? we already have painter->handle()
     2102/// @todo (dmik) do we really need this? we already have painter->handle()
    21692103//  inside QFontEngine::draw(), and the font should have been selected into
    21702104//  hps by updateFont()
     
    21792113
    21802114        fe->draw( this, xpos, ypos, engine, si, textFlags );
    2181 //@@TODO (dmik): need?
     2115/// @todo (dmik) need?
    21822116//        fe->hps = oldPs;
    2183 
    2184 //@@TODO (dmik): remove
    2185 //      if ( rop != CopyROP ) {
    2186 //#ifndef Q_OS_TEMP
    2187 //          EndPath(hdc);
    2188 //#endif
    2189 //          uint pix = COLOR_VALUE(cpen.data->color);
    2190 //          HBRUSH tbrush = CreateSolidBrush( pix );
    2191 //          SelectObject( hdc, tbrush );
    2192 //#ifndef Q_OS_TEMP
    2193 //          FillPath(hdc);
    2194 //#endif
    2195 //          SelectObject( hdc, hbrush );
    2196 //          DeleteObject( tbrush );
    2197 //      }
    21982117    }
    21992118}
     
    22232142    y += si->y;
    22242143
    2225 //@@TODO (dmik): do we really need this? we already have painter->handle()
     2144/// @todo (dmik) do we really need this? we already have painter->handle()
    22262145//  inside QFontEngine::draw(), and the font should have been selected into
    22272146//  hps by updateFont()
     
    22312150
    22322151    fe->draw( this, x,  y, engine, si, textFlags );
    2233 //@@TODO (dmik): need?
     2152/// @todo (dmik) need?
    22342153//    fe->hps = oldPs;
    22352154}
Note: See TracChangeset for help on using the changeset viewer.