Changeset 277 for trunk/src/PagePter.cxx

Show
Ignore:
Timestamp:
06/11/07 09:12:09 (18 months ago)
Author:
jordi
Message:

Added a patch by Igor Vagulin which adds text selection and copy to clipboard features. This fixes bug #14.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/PagePter.cxx

    r275 r277  
    1616// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1717 
     18#include <gdk/gdk.h> 
    1819#include "epdfview.h" 
    1920 
     
    4849    gint y; 
    4950    /// The horizontal position of the page view scroll when the drag started. 
    50     gdouble scrollX; 
     51    int startX; 
    5152    /// The vertical position of the page view scroll when the drag started. 
    52     gdouble scrollY; 
     53    int startY; 
    5354}; 
    5455 
     
    6162PagePter::PagePter (IDocument *document) 
    6263{ 
     64    m_LastSelection = NULL; 
    6365    m_Document = document; 
    6466    m_Document->attach (this); 
     
    6668    m_NextPageScroll = PAGE_SCROLL_START; 
    6769    m_PageView = NULL; 
     70    m_Mode = PagePterModeScroll; 
    6871} 
    6972 
     
    130133 
    131134            IPageView &view = getView (); 
    132             m_DragInfo->scrollX = view.getHorizontalScroll (); 
    133             m_DragInfo->scrollY = view.getVerticalScroll (); 
    134             view.setCursor (PAGE_VIEW_CURSOR_DRAG); 
     135            m_DragInfo->startX = x; 
     136            m_DragInfo->startY = y; 
     137            if(m_Mode == PagePterModeScroll) 
     138                view.setCursor (PAGE_VIEW_CURSOR_DRAG); 
     139            else 
     140                view.setCursor (PAGE_VIEW_CURSOR_SELECT_TEXT); 
    135141        } 
    136142    } 
     
    150156    if ( 1 == button ) 
    151157    { 
     158        if(m_LastSelection) 
     159            gdk_region_destroy(m_LastSelection); 
     160        m_LastSelection = NULL; 
     161 
     162        if(m_Document->isLoaded() && m_Mode == PagePterModeSelectText){ 
     163            DocumentRectangle rect(m_DragInfo->startX, m_DragInfo->startY, 
     164                                   m_DragInfo->x, m_DragInfo->y); 
     165            m_Document->setTextSelection(&rect); 
     166        } 
     167 
    152168        delete m_DragInfo; 
    153169        m_DragInfo = NULL; 
     170 
     171        refreshPage(PAGE_SCROLL_NONE, FALSE); 
     172         
    154173        getView ().setCursor (PAGE_VIEW_CURSOR_NORMAL); 
    155174    } 
     
    182201        } 
    183202    } 
    184     else 
    185     { 
    186         view.scrollPage (view.getHorizontalScroll (), view.getVerticalScroll (), 
    187                          x - m_DragInfo->x, y - m_DragInfo->y); 
     203    else{ 
     204        m_DragInfo->x = x; 
     205        m_DragInfo->y = y;   
     206 
     207        if(m_Mode == PagePterModeScroll){ 
     208            view.scrollPage (view.getHorizontalScroll (), view.getVerticalScroll (), 
     209                             x - m_DragInfo->startX, y - m_DragInfo->startY); 
     210        } 
     211        else{ 
     212            if(!m_Document->isLoaded()) 
     213                return ; 
     214             
     215            DocumentRectangle rect(m_DragInfo->startX, m_DragInfo->startY, 
     216                                          m_DragInfo->x, m_DragInfo->y); 
     217 
     218            GdkRegion *region = m_Document->getTextRegion (&rect); 
     219 
     220            if( !m_LastSelection || !gdk_region_equal(m_LastSelection, region)){ 
     221                if(m_LastSelection) 
     222                    gdk_region_destroy(m_LastSelection); 
     223                m_LastSelection = gdk_region_copy(region); 
     224                DocumentPage *page = m_Document->getCurrentPage(); 
     225                if ( NULL != page ) 
     226                    refreshPage (PAGE_SCROLL_NONE, FALSE); 
     227            } 
     228        } 
    188229    } 
    189230} 
     
    274315        { 
    275316            g_WaitingForPage = FALSE; 
     317            if ( NULL != m_LastSelection ) 
     318                documentPage->setSelection(m_LastSelection); 
    276319            view.showPage (documentPage, pageScroll); 
    277320        }