Changeset 208

Show
Ignore:
Timestamp:
06/10/06 07:24:26 (2 years ago)
Author:
jordi
Message:

When getting the cursor coordinates relative to the document's page, now I take into account that the size of the page can be less than the size of the widget and that could cause problems (see ticket #34.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/gtk/PageView.cxx

    r190 r208  
    9090    g_assert (NULL != width && "Tried to save the width to a NULL pointer."); 
    9191    g_assert (NULL != height && "Tried to save the height to a NULL pointer."); 
    92    
     92 
    9393    gint vScrollSize = 0; 
    9494    gint hScrollSize = 0; 
     
    119119    gdouble docX1 = getHorizontalScroll () - PAGE_VIEW_PADDING; 
    120120    gdouble docX2 = docX1 + hAdjustment->page_size; 
    121      
     121 
    122122    gdouble dx = 0.0; 
    123123    if ( realX1 < docX1 ) 
     
    134134                   hAdjustment->lower, 
    135135                   hAdjustment->upper - hAdjustment->page_size)); 
    136      
     136 
    137137    // Calculate the vertical adjustment. 
    138138    GtkAdjustment *vAdjustment = gtk_scrolled_window_get_vadjustment ( 
     
    211211{ 
    212212    IPageView::setPresenter (pter); 
    213      
     213 
    214214    // When resizing. 
    215215    g_signal_connect (G_OBJECT (m_PageScroll), "size-allocate", 
     
    245245                   hAdjustment->lower, 
    246246                   hAdjustment->upper - hAdjustment->page_size)); 
    247      
     247 
    248248    GtkAdjustment *vAdjustment = gtk_scrolled_window_get_vadjustment ( 
    249249            GTK_SCROLLED_WINDOW (m_PageScroll)); 
     
    295295        gint width = gdk_pixbuf_get_width (originalPage); 
    296296        gint height = gdk_pixbuf_get_height (originalPage); 
    297         
    298         PangoLayout *layout =  
     297 
     298        PangoLayout *layout = 
    299299            gtk_widget_create_pango_layout (m_PageImage, text); 
    300300 
     
    318318        pango_layout_set_font_description (layout, fontDescription); 
    319319        pango_layout_get_pixel_extents (layout, NULL, &logicalRectangle); 
    320          
     320 
    321321        // Once the font are set up, I just need to render  
    322322        // the pixbuf to the pixmap (copying from client-side to  
     
    346346            g_object_unref (mask); 
    347347        } 
    348          
     348 
    349349        gtk_image_set_from_pixbuf (GTK_IMAGE (m_PageImage), modifiedPage); 
    350350        g_object_unref (modifiedPage); 
     
    366366{ 
    367367    g_assert ( NULL != pageX && "Tried to save the page's X to NULL."); 
    368     g_assert ( NULL != pageY && "Tried to save the page's Y to NULL.");     
    369  
    370     *pageX = widgetX - PAGE_VIEW_PADDING + (gint)getHorizontalScroll (); 
    371     *pageY = widgetY - PAGE_VIEW_PADDING + (gint)getVerticalScroll (); 
     368    g_assert ( NULL != pageY && "Tried to save the page's Y to NULL."); 
     369 
     370    // Since the page is centered on the GtkImage widget, we need to 
     371    // get the current widget size and the current image size to know 
     372    // how many widget space is being used for padding. 
     373    GdkPixbuf *page = gtk_image_get_pixbuf (GTK_IMAGE (m_PageImage)); 
     374    gint horizontalPadding = 
     375        (m_PageImage->allocation.width - gdk_pixbuf_get_width (page)) / 2; 
     376    gint verticalPadding = 
     377        (m_PageImage->allocation.height - gdk_pixbuf_get_height (page)) / 2; 
     378 
     379    *pageX = widgetX - horizontalPadding + (gint)getHorizontalScroll (); 
     380    *pageY = widgetY - verticalPadding + (gint)getVerticalScroll (); 
    372381} 
    373382 
     
    441450    g_assert ( NULL != data && "The data is NULL."); 
    442451    PageView *view = (PageView *)data; 
    443      
     452 
    444453    gint event_x; 
    445454    gint event_y; 
     
    459468    g_assert (NULL != width && "Tried to save the width to a NULL pointer."); 
    460469    g_assert (NULL != height && "Tried to save the height to a NULL pointer."); 
    461    
     470 
    462471    gint borderWidth = widget->style->xthickness; 
    463472    gint borderHeight = widget->style->ythickness; 
     
    468477        borderHeight += widget->style->ythickness; 
    469478    } 
    470      
     479 
    471480    gint scrollBarSpacing = 0; 
    472481    gtk_widget_style_get (widget, "scrollbar-spacing", &scrollBarSpacing, NULL); 
    473      
     482 
    474483    GtkWidget *vScrollBar = GTK_SCROLLED_WINDOW (widget)->vscrollbar; 
    475484    *width = vScrollBar->allocation.width + 
     
    489498{ 
    490499    g_assert ( NULL != data && "The data parameter is NULL."); 
    491      
     500 
    492501    gint vScrollSize = 0; 
    493502    gint hScrollSize = 0; 
     
    541550    gboolean horizontal = FALSE; 
    542551    PagePter *pter = (PagePter *)data; 
    543      
     552 
    544553    GtkAdjustment *adjustment =  
    545554        gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget)); 
    546555    gdouble position = gtk_adjustment_get_value (adjustment); 
    547      
     556 
    548557    if ( event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK) ) 
    549558    { 
    550559        return FALSE; 
    551560    } 
    552      
     561 
    553562    switch ( event->keyval ) 
    554563    { 
     
    558567            horizontal = TRUE; 
    559568            break; 
    560          
     569 
    561570        case GDK_Right: 
    562571        case GDK_KP_Right: 
     
    564573            direction = GTK_SCROLL_STEP_RIGHT; 
    565574            break; 
    566          
     575 
    567576        case GDK_Up: 
    568577        case GDK_KP_Up: 
    569578            direction = GTK_SCROLL_STEP_UP; 
    570579            break; 
    571          
     580 
    572581        case GDK_Down: 
    573582        case GDK_KP_Down: 
    574583            direction = GTK_SCROLL_STEP_DOWN; 
    575584            break; 
    576          
     585 
    577586        case GDK_Page_Up: 
    578587        case GDK_KP_Page_Up: 
     
    584593            direction = GTK_SCROLL_START; 
    585594            break; 
    586          
     595 
    587596        case GDK_Page_Down: 
    588597        case GDK_KP_Page_Down: 
     
    594603            direction = GTK_SCROLL_END; 
    595604            break; 
    596          
     605 
    597606        default: 
    598607            return FALSE; 
    599608    } 
    600      
     609 
    601610    g_signal_emit_by_name(G_OBJECT(widget), "scroll-child", 
    602611                          direction, horizontal);