Changeset 22 for trunk/Lucide


Ignore:
Timestamp:
May 13, 2006, 6:09:46 PM (15 years ago)
Author:
Eugene Romanenko
Message:

intermediate commit, text selection in continuous view nearly works

Location:
trunk/Lucide/SOURCE/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Lucide/SOURCE/gui/docViewer.cpp

    r19 r22  
    111111
    112112    if ( doc != NULL ) {
    113         LuDocument::freeRectangles( ev, selrects );
     113        freeRects( selrects );
     114        freeRects( foundrects );
    114115        freeLinks();
    115         freeFoundrects();
    116116    }
    117117
     
    143143    fullwidth   = 0;
    144144    fullheight  = 0;
     145
    145146    delete pagesizes;
    146147    pagesizes   = NULL;
    147     freeFoundrects();
     148
     149    freeRects( foundrects );
    148150    delete foundrects;
    149151    foundrects  = NULL;
     152
     153    freeRects( selrects );
     154    delete selrects;
     155    selrects  = NULL;
     156
    150157    freeLinks();
    151158
     
    161168        }
    162169
     170        selrects = new PLuRectSequence[ totalpages ];
     171        memset( selrects, 0, sizeof( PLuRectSequence ) * totalpages );
     172
    163173        foundrects = new PLuRectSequence[ totalpages ];
    164174        memset( foundrects, 0, sizeof( PLuRectSequence ) * totalpages );
     175
    165176        links = new PLuLinkMapSequence[ totalpages ];
    166177        memset( links, 0, sizeof( PLuLinkMapSequence ) * totalpages );
     178
    167179        enableAsynchDraw = doc->isAsynchRenderingSupported( ev );
    168180        goToPage( 0 );
     
    184196}
    185197
    186 void DocumentViewer::freeFoundrects()
    187 {
    188     if ( foundrects != NULL )
     198void DocumentViewer::freeRects( LuDocument_LuRectSequence **rects )
     199{
     200    if ( rects != NULL )
    189201    {
    190202        for ( long i = 0; i < totalpages; i++ ) {
    191             if ( foundrects[ i ] != NULL ) {
    192                 LuDocument::freeRectangles( ev, foundrects[ i ] );
    193                 foundrects[ i ] = NULL;
     203            if ( rects[ i ] != NULL ) {
     204                LuDocument::freeRectangles( ev, rects[ i ] );
     205                rects[ i ] = NULL;
    194206            }
    195207        }
     
    258270    abortSearch = false;
    259271    if ( !continueSearch ) {
    260         freeFoundrects();
     272        freeRects( foundrects );
    261273    }
    262274
     
    377389    else
    378390    {
    379         LuDocument::freeRectangles( ev, selrects );
    380         selrects = NULL;
     391        LuDocument::freeRectangles( ev, selrects[ currentpage ] );
     392        selrects[ currentpage ] = NULL;
     393
    381394        if ( links != NULL ) {
    382395            if ( links[ currentpage ] == NULL ) {
     
    384397            }
    385398        }
     399
    386400        Lucide::enableCopy( false );
    387401        adjustSize();
     
    624638                        PageDrawArea *pda = &(*_this->drawareas)[ i ];
    625639
    626                         // TODO: continuous
    627                         //_this->drawSelection( hps, &pda->drawrect );
     640                        _this->drawSelection( pda->pagenum, hps, &pda->drawrect );
    628641                        _this->drawFound( pda->pagenum, hps, &pda->drawrect );
    629642                    }
     
    729742    }
    730743
    731     /*if ( isSubrect( &savedRcl, &rcl ) && ( sVscrollInc == 0 ) && ( sHscrollInc == 0 ) ) {
     744    if ( isSubrect( &savedRcl, &rcl ) && ( sVscrollInc == 0 ) && ( sHscrollInc == 0 ) ) {
    732745        return;
    733     } */
     746    }
    734747
    735748    abortAsynch = true;
     
    755768
    756769    delete drawareas;
    757     drawareas = foundDrawAreas( &rcl );
     770    drawareas = findDrawAreas( &rcl );
    758771
    759772    for ( int i = 0; i < drawareas->size(); i++ )
     
    765778            links[ pda->pagenum ] = doc->getLinkMapping( ev, pda->pagenum );
    766779        }
    767 
    768         pda->startpos.x = sHscrollPos + pda->drawrect.xLeft;
    769780    }
    770781    DosReleaseMutexSem( todrawAccess );
     
    855866// founds pages and it's areas to draw
    856867// for continuous view only
    857 DrawAreas *DocumentViewer::foundDrawAreas( PRECTL r )
     868DrawAreas *DocumentViewer::findDrawAreas( PRECTL r )
    858869{
    859870    DrawAreas *areas = new DrawAreas;
     
    875886                pda.drawrect.yTop    = i;
    876887
    877                 pda.startpos.x = 0;
     888                pda.startpos.x = sHscrollPos + pda.drawrect.xLeft;
    878889                pda.startpos.y = ( pagesizes[ pg ].y * realzoom ) - pageRest;
    879890
     
    895906    RECTL rcl = { 0 };
    896907    WinQueryWindowRect( hWndDoc, &rcl );
    897     DrawAreas *areas = foundDrawAreas( &rcl );
     908    DrawAreas *areas = findDrawAreas( &rcl );
    898909    long pg = 0;
    899910    long sz = 0;
     
    924935
    925936    delete drawareas;
    926     drawareas = foundDrawAreas( &rcl );
     937    drawareas = findDrawAreas( &rcl );
    927938
    928939    for ( int i = 0; i < drawareas->size(); i++ )
     
    935946        }
    936947
    937         spos_x = sHscrollPos + pda->drawrect.xLeft;
     948        spos_x = pda->startpos.x;
    938949        //spos_y = ( cyClient - pda->drawrect.yTop ) + ( sVscrollPos * VScrollStep );
    939950        spos_y = pda->startpos.y;
     
    959970
    960971        // TODO
    961         //drawSelection( hpsBuffer, &rclDraw );
     972        drawSelection( pda->pagenum, hpsBuffer, &pda->drawrect );
    962973        drawFound( pda->pagenum, hpsBuffer, &pda->drawrect );
    963974
     
    975986
    976987// converts window position to document position
     988// single page mode only
    977989void DocumentViewer::winPosToDocPos( PPOINTL startpoint, PPOINTL endpoint, LuRectangle *r )
    978990{
     
    981993    r->x2 = ( endpoint->x + sHscrollPos ) / realzoom;
    982994    r->y2 = ( ( cyClient - endpoint->y ) + sVscrollPos ) / realzoom;
     995}
     996
     997// converts window position to document position
     998// continuous view mode only
     999void DocumentViewer::winPosToDocPos( PageDrawArea *pda, LuRectangle *r )
     1000{
     1001    r->x1 = ( sHscrollPos + pda->drawrect.xLeft ) / realzoom;;
     1002    r->y1 = pda->startpos.y / realzoom;
     1003    r->x2 = ( ( pda->drawrect.xRight - pda->drawrect.xLeft ) / realzoom ) + r->x1;
     1004    r->y2 = ( ( pda->drawrect.yTop - pda->drawrect.yBottom ) / realzoom ) + r->y1;
    9831005}
    9841006
     
    10201042    GpiSetMix( hps, FM_XOR );
    10211043    GpiSetColor( hps, CLR_YELLOW );
    1022     HRGN selectRegion = rectsToRegion( pagenum, hps, selrects, false );
     1044    HRGN selectRegion = rectsToRegion( pagenum, hps, selrects[ pagenum ], false );
    10231045    if ( r != NULL )
    10241046    {
     
    10871109    if ( mousePressed && ( doc != NULL ) )
    10881110    {
    1089         // TODO: continuous
    1090         if ( continuous ) {
    1091             return FALSE;
    1092         }
    1093 
    10941111        selectionEnd.x = xpos;
    10951112        selectionEnd.y = ypos;
    10961113
    1097         winPosToDocPos( &selectionStart, &selectionEnd, &selection );
    1098 
    1099         HPS hps = WinGetPS( hwnd );
    1100         HRGN scrolledRegion = NULLHANDLE; //GpiCreateRegion( hps, 0, NULL );
    1101 
    1102         scrollToPos( hwnd, scrolledRegion, xpos, ypos, true );
    1103 
    1104         // 127/191/255
    1105         //LONG lclr = ( 127 << 16 ) | ( 191 << 8 ) | 255;
    1106         //LONG lclr = ( 128 << 16 ) | ( 64 << 8 );
    1107         //LONG ltabl[ 1 ] = { lclr };
    1108         //GpiCreateLogColorTable( hps, 0, LCOLF_CONSECRGB, 100, 1, ltabl );
    1109 
    1110         GpiSetMix( hps, FM_XOR );
    1111         GpiSetColor( hps, CLR_YELLOW );
    1112         //GpiSetColor( hps, 100 );
    1113 
    1114         HRGN clearRegion = rectsToRegion( currentpage, hps, selrects, false );
    1115         LuDocument::freeRectangles( ev, selrects );
    1116         if ( ( selectionStart.x == selectionEnd.x ) &&
    1117              ( selectionStart.y == selectionEnd.y ) ) {
    1118             selrects = NULL;
    1119         }
    1120         else {
    1121             selrects = doc->getSelectionRectangles( ev, currentpage, realzoom, &selection );
    1122         }
    1123         HRGN selectRegion = rectsToRegion( currentpage, hps, selrects, false );
    1124         GpiCombineRegion( hps, selectRegion, selectRegion, clearRegion, CRGN_XOR );
    1125         //GpiCombineRegion( hps, selectRegion, selectRegion, scrolledRegion, CRGN_DIFF );
    1126         GpiPaintRegion( hps, selectRegion );
    1127         GpiDestroyRegion( hps, clearRegion );
    1128         GpiDestroyRegion( hps, selectRegion );
    1129         //GpiDestroyRegion( hps, scrolledRegion );
    1130 
    1131         WinReleasePS( hps );
     1114        if ( continuous )
     1115        {
     1116            RECTL selRect = {
     1117                selectionStart.x < selectionEnd.x ? selectionStart.x : selectionEnd.x,
     1118                selectionStart.y < selectionEnd.y ? selectionStart.y : selectionEnd.y,
     1119                selectionStart.x < selectionEnd.x ? selectionEnd.x : selectionStart.x,
     1120                selectionStart.y < selectionEnd.y ? selectionEnd.y : selectionStart.y
     1121            };
     1122
     1123            DrawAreas *areas = findDrawAreas( &selRect );
     1124
     1125            HPS hps = WinGetPS( hwnd );
     1126            GpiSetMix( hps, FM_XOR );
     1127            GpiSetColor( hps, CLR_YELLOW );
     1128
     1129            for ( int i = 0; i < areas->size(); i++ )
     1130            {
     1131                PageDrawArea *pda = &(*areas)[ i ];
     1132
     1133                winPosToDocPos( pda, &selection );
     1134
     1135                HRGN clearRegion = rectsToRegion( pda->pagenum, hps, selrects[ pda->pagenum ], false );
     1136                LuDocument::freeRectangles( ev, selrects[ pda->pagenum ] );
     1137                selrects[ pda->pagenum ] = doc->getSelectionRectangles( ev, pda->pagenum, realzoom, &selection );
     1138                HRGN selectRegion = rectsToRegion( pda->pagenum, hps, selrects[ pda->pagenum ], false );
     1139                GpiCombineRegion( hps, selectRegion, selectRegion, clearRegion, CRGN_XOR );
     1140                GpiPaintRegion( hps, selectRegion );
     1141                GpiDestroyRegion( hps, clearRegion );
     1142                GpiDestroyRegion( hps, selectRegion );
     1143            }
     1144
     1145            WinReleasePS( hps );
     1146            delete areas;
     1147        }
     1148        else
     1149        {
     1150            winPosToDocPos( &selectionStart, &selectionEnd, &selection );
     1151
     1152            HPS hps = WinGetPS( hwnd );
     1153            HRGN scrolledRegion = NULLHANDLE; //GpiCreateRegion( hps, 0, NULL );
     1154
     1155            scrollToPos( hwnd, scrolledRegion, xpos, ypos, true );
     1156
     1157            // 127/191/255
     1158            //LONG lclr = ( 127 << 16 ) | ( 191 << 8 ) | 255;
     1159            //LONG lclr = ( 128 << 16 ) | ( 64 << 8 );
     1160            //LONG ltabl[ 1 ] = { lclr };
     1161            //GpiCreateLogColorTable( hps, 0, LCOLF_CONSECRGB, 100, 1, ltabl );
     1162
     1163            GpiSetMix( hps, FM_XOR );
     1164            GpiSetColor( hps, CLR_YELLOW );
     1165            //GpiSetColor( hps, 100 );
     1166
     1167            HRGN clearRegion = rectsToRegion( currentpage, hps, selrects[ currentpage ], false );
     1168            LuDocument::freeRectangles( ev, selrects[ currentpage ] );
     1169            if ( ( selectionStart.x == selectionEnd.x ) &&
     1170                 ( selectionStart.y == selectionEnd.y ) ) {
     1171                selrects[ currentpage ] = NULL;
     1172            }
     1173            else {
     1174                selrects[ currentpage ] = doc->getSelectionRectangles( ev, currentpage, realzoom, &selection );
     1175            }
     1176            HRGN selectRegion = rectsToRegion( currentpage, hps, selrects[ currentpage ], false );
     1177            GpiCombineRegion( hps, selectRegion, selectRegion, clearRegion, CRGN_XOR );
     1178            //GpiCombineRegion( hps, selectRegion, selectRegion, scrolledRegion, CRGN_DIFF );
     1179            GpiPaintRegion( hps, selectRegion );
     1180            GpiDestroyRegion( hps, clearRegion );
     1181            GpiDestroyRegion( hps, selectRegion );
     1182            //GpiDestroyRegion( hps, scrolledRegion );
     1183
     1184            WinReleasePS( hps );
     1185        }
    11321186    }
    11331187    else if ( links != NULL )
     
    12481302}
    12491303
     1304// handles WM_BUTTON1DOWN
     1305void DocumentViewer::wmButton1Down( HWND hwnd, SHORT xpos, SHORT ypos )
     1306{
     1307    if ( continuous )
     1308    {
     1309        // clear selection
     1310        RECTL rcl = { 0 };
     1311        WinQueryWindowRect( hwnd, &rcl );
     1312        DrawAreas *areas = findDrawAreas( &rcl );
     1313
     1314        HPS hps = WinGetPS( hwnd );
     1315        GpiSetMix( hps, FM_XOR );
     1316        GpiSetColor( hps, CLR_YELLOW );
     1317
     1318        for ( int i = 0; i < areas->size(); i++ )
     1319        {
     1320            PageDrawArea *pda = &(*areas)[ i ];
     1321
     1322            HRGN clearRegion = rectsToRegion( pda->pagenum, hps, selrects[ pda->pagenum ], false );
     1323            GpiPaintRegion( hps, clearRegion );
     1324            GpiDestroyRegion( hps, clearRegion );
     1325        }
     1326        WinReleasePS( hps );
     1327        delete areas;
     1328
     1329        freeRects( selrects );
     1330    }
     1331
     1332    WinSetCapture( HWND_DESKTOP, hwnd );
     1333    mousePressed = true;
     1334    selectionStart.x = xpos;
     1335    selectionStart.y = ypos;
     1336}
     1337
    12501338
    12511339// static, window procedure
     
    12971385
    12981386        case WM_BUTTON1DOWN:
    1299             {
    1300                 WinSetCapture( HWND_DESKTOP, hwnd );
    1301                 _this->mousePressed = true;
    1302                 _this->selectionStart.x = SHORT1FROMMP( mp1 );
    1303                 _this->selectionStart.y = SHORT2FROMMP( mp1 );
    1304             }
     1387            _this->wmButton1Down( hwnd, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
    13051388            break;
    13061389
     
    13091392                WinSetCapture( HWND_DESKTOP, NULLHANDLE );
    13101393                _this->mousePressed = false;
    1311                 Lucide::enableCopy( _this->selrects != NULL );
     1394                // TODO Lucide::enableCopy( _this->selrects != NULL );
    13121395            }
    13131396            break;
  • trunk/Lucide/SOURCE/gui/docViewer.h

    r19 r22  
    5555        void wmPaintAsynch( HWND hwnd );
    5656        void wmPaintContAsynch( HWND hwnd );
     57        void wmButton1Down( HWND hwnd, SHORT xpos, SHORT ypos );
    5758        BOOL wmMouseMove( HWND hwnd, SHORT xpos, SHORT ypos );
    5859        BOOL wmClick( HWND hwnd, SHORT xpos, SHORT ypos );
    5960        BOOL wmChar( HWND hwnd, MPARAM mp1, MPARAM mp2 );
    6061        void winPosToDocPos( PPOINTL startpoint, PPOINTL endpoint, LuRectangle *r );
     62        void winPosToDocPos( PageDrawArea *pda, LuRectangle *r );
    6163        void docPosToWinPos( long pagenum, LuRectangle *r, PRECTL rcl, bool useZoom = true );
    6264        HRGN rectsToRegion( long pagenum, HPS hps, LuDocument_LuRectSequence *rects, bool useZoom );
    6365        void drawSelection( long pagenum, HPS hps, PRECTL r );
    6466        void scrollToPos( HWND hwnd, HRGN hrgn, LONG xpos, LONG ypos, bool withSelection );
    65         void freeFoundrects();
     67        void freeRects( LuDocument_LuRectSequence **rects );
    6668        void freeLinks();
    6769        void drawFound( long pagenum, HPS hps, PRECTL r );
    68         DrawAreas *foundDrawAreas( PRECTL r );
     70        DrawAreas *findDrawAreas( PRECTL r );
    6971        void determineCurrentPage();
    7072        long posToPagenum( LONG yPosWin, double *pageRest );
     
    125127        POINTL selectionEnd;
    126128        LuRectangle selection;
    127         LuDocument_LuRectSequence *selrects;
     129        LuDocument_LuRectSequence **selrects;
    128130
    129131        // links
Note: See TracChangeset for help on using the changeset viewer.