void TLFrameSequenceLayout::updateContentSize()
{
    if ( contentsHeight() < number_of_frame_sequences * 24 )
    {
    	resizeContents( contentsWidth(), number_of_frame_sequences * 24 );
    }
    else if ( contentsHeight() > number_of_frame_sequences * 24 && contentsHeight() > 90 )
    {
        resizeContents( contentsWidth(), contentsHeight() - 24 );
    }
    updateContents();
    updateScrollBars();
    parent_widget -> update();
}
Exemplo n.º 2
0
void KVocTrainTable::keyPressEvent(QKeyEvent * e)
{
  delayTimer->stop();
  switch(e->key())
  {
    case Key_Right: {
      int topCell = rowAt(0);
      int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight()));
      if (numCols() > 2)
        for (int i = topCell; i <= lastRowVisible; i++)
          updateCell(i, KV_COL_ORG);
    }  // fallthrough
    case Key_Up:
    case Key_Down:
    case Key_Next:
    case Key_Prior:
      QTable::keyPressEvent(e);
      break;

      case Key_Left: {
        QTable::keyPressEvent(e);
        int topCell = rowAt(0);
        int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight()));
        if (numCols() > 2)
          for (int i = topCell; i <= lastRowVisible; i++)
            updateCell(i, KV_COL_ORG);
      }
      break;

    case Key_Shift:
    case Key_Alt:
      case Key_Control:  // fallthrough
        QTable::keyPressEvent(e);
        emit forwardKeyPressEvent(e);
        break;

    case Key_Minus:
    case Key_Plus:
    case Key_Tab:
      case Key_Backtab:  // fallthrough
        emit forwardKeyPressEvent(e);
        break;

    default:
      QTable::keyPressEvent(e);
      break;
  }
}
Exemplo n.º 3
0
void HistoryView::messageReceived(ICQMessage *msg)
{
    if (msg->getUin() != m_nUin) return;
    if (msg->Id >= MSG_PROCESS_ID) return;
    int x = contentsX();
    int y = contentsY();
    bool bUnread = false;
    ICQUser *u = pClient->getUser(m_nUin);
    if (u){
        for (list<unsigned long>::iterator it = u->unreadMsgs.begin(); it != u->unreadMsgs.end(); it++){
            if ((*it) == msg->Id){
                bUnread = true;
                break;
            }
        }
    }
    if (bBack){
        QString saveText = text();
        setText("");
        addMessage(msg, bUnread, false);
        y += contentsHeight();
        setText(text() + saveText);
    }else{
        addMessage(msg, bUnread, false);
    }
    setContentsPos(x, y);
}
void KexiSimplePrintPreviewScrollView::setFullWidth()
{
    viewport()->setUpdatesEnabled(false);
    double widthMM = KoPageFormat::width(
                         m_window->settings().pageLayout.format,
                         m_window->settings().pageLayout.orientation);
    double heightMM = KoPageFormat::height(
                          m_window->settings().pageLayout.format, m_window->settings().pageLayout.orientation);
// int constantWidth = m_window->width()- KexiSimplePrintPreviewScrollView_MARGIN*6;
    double constantWidth = width() - KexiSimplePrintPreviewScrollView_MARGIN * 6;
    double heightForWidth = constantWidth * heightMM / widthMM;
// heightForWidth = qMin(kapp->desktop()->height()*4/5, heightForWidth);
    kDebug() << "1: " << heightForWidth;
#if 0 //todo we can use this if we want to fix the height to width of the page
    heightForWidth = qMin(height(), heightForWidth);
    kDebug() << "2: " << heightForWidth;
#endif
    constantWidth = heightForWidth * widthMM / heightMM;
    widget->resize((int)constantWidth, (int)heightForWidth); //keep aspect
    resizeContents(int(widget->width() + 2*KexiSimplePrintPreviewScrollView_MARGIN),
                   int(widget->height() + 2*KexiSimplePrintPreviewScrollView_MARGIN));
    moveChild(widget, (contentsWidth() - widget->width()) / 2,
              (contentsHeight() - widget->height()) / 2);
    viewport()->setUpdatesEnabled(true);
    resize(size() + QSize(1, 1)); //to update pos.
    widget->enablePainting = true;
    widget->repaint();
}
Exemplo n.º 5
0
void DrawZone::setZoom(double z)
{
	_zoom=z;
	imageRect.setHeight(myround(image.height()*_zoom));
	imageRect.setWidth(myround(image.width()*_zoom));
	zoomedImage=QPixmap(imageRect.width(),imageRect.height());
	QPainter p(&zoomedImage);
	p.scale(z,z);
	QPixmap pix;
	pix.convertFromImage(image);
	// if the picture has transparent areas,
	// fill them with Gimp like background
	if (pix.mask()) {
  	QPixmap backPix(32,32);
  	QPainter p2(&backPix);
  	p2.fillRect(0,0,32,32,QColor(156,149,156));
  	p2.fillRect(0,16,16,16,QColor(98,105,98));
  	p2.fillRect(16,0,16,16,QColor(98,105,98));
  	p2.flush();
  	p.setPen(QPen());
  	p.fillRect(imageRect.left(),imageRect.top(),imageRect.width(),imageRect.height(),QBrush(QColor("black"),backPix));
	}
	p.drawPixmap(imageRect.left(),imageRect.top(),pix);
	p.flush();
	resizeContents(visibleWidth()>imageRect.width() ? visibleWidth() : imageRect.width(),
								 visibleHeight()>imageRect.height() ? visibleHeight() : imageRect.height());
	repaintContents(0,0,contentsWidth(),contentsHeight(),true);
}
// this is called from the clicked PatternWidget when in signal mode //
void 
PolicyViewClass::endAddTransition(PatternWidgetClass* patternWidget)
{
  // if addTransition mode is on, finish it and add the signal //
  if (isAddTransitionMode()) {
    viewport()->setMouseTracking(false);
    addTransitionMode = false;

    bool ok = false;
    QString message = QInputDialog::getText(tr( "Add Transition" ),
					    tr( "Transition name:" ),
					    QLineEdit::Normal, QString::null, &ok, this );
    if ( ok && !message.isEmpty() ) {
      QString target  = patternWidget->getPatternName();
      if (document.addTransition(pickedPattern, message, target))
	updateContents(contentsX(), contentsY(),
		       contentsWidth(), contentsHeight());
      else
	QMessageBox::warning(this, 
			     "Add Transition", 
			     "Transition " + message + " allready exists.\n" + 
			     "No transition added.");

    }
  }
}
Exemplo n.º 7
0
/******************************************************************************
*  Sets the last column in the list view to extend at least to the right hand
*  edge of the list view.
*/
void EventListViewBase::resizeLastColumn()
{
    int lastColumnWidth = mLastColumnHeaderWidth;
    for (EventListViewItemBase* item = firstChild();  item;  item = item->nextSibling())
    {
        int mw = item->lastColumnWidth();
        if (mw > lastColumnWidth)
            lastColumnWidth = mw;
    }
    QHeader* head = header();
    int x = head->sectionPos(mLastColumn);
    int availableWidth = visibleWidth() - x;
    int rightColWidth = 0;
    int index = head->mapToIndex(mLastColumn);
    if (index < mLastColumn)
    {
        // The last column has been dragged by the user to a different position.
        // Ensure that the columns now to the right of it are still shown.
        for (int i = index + 1;  i <= mLastColumn;  ++i)
            rightColWidth += columnWidth(head->mapToSection(i));
        availableWidth -= rightColWidth;
    }
    if (availableWidth < lastColumnWidth)
        availableWidth = lastColumnWidth;
    setColumnWidth(mLastColumn, availableWidth);
    if (contentsWidth() > x + availableWidth + rightColWidth)
        resizeContents(x + availableWidth + rightColWidth, contentsHeight());
}
Exemplo n.º 8
0
void UIPageText::updateContents()
{
        int ch = contentsHeight();
        int vw = visibleWidth();

        ensureVisible( 0, ch, 0, 0 );
        repaintContents( 0, ch - 40, vw, 40, true );
}
Exemplo n.º 9
0
int Q3ScrollView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = Q3Frame::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 23)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 23;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< ResizePolicy*>(_v) = resizePolicy(); break;
        case 1: *reinterpret_cast< ScrollBarMode*>(_v) = vScrollBarMode(); break;
        case 2: *reinterpret_cast< ScrollBarMode*>(_v) = hScrollBarMode(); break;
        case 3: *reinterpret_cast< int*>(_v) = visibleWidth(); break;
        case 4: *reinterpret_cast< int*>(_v) = visibleHeight(); break;
        case 5: *reinterpret_cast< int*>(_v) = contentsWidth(); break;
        case 6: *reinterpret_cast< int*>(_v) = contentsHeight(); break;
        case 7: *reinterpret_cast< int*>(_v) = contentsX(); break;
        case 8: *reinterpret_cast< int*>(_v) = contentsY(); break;
        case 9: *reinterpret_cast< bool*>(_v) = dragAutoScroll(); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setResizePolicy(*reinterpret_cast< ResizePolicy*>(_v)); break;
        case 1: setVScrollBarMode(*reinterpret_cast< ScrollBarMode*>(_v)); break;
        case 2: setHScrollBarMode(*reinterpret_cast< ScrollBarMode*>(_v)); break;
        case 9: setDragAutoScroll(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 10;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemplo n.º 10
0
void RosegardenScrollView::updateScrollBars()
{
    horizontalScrollBar()->setPageStep(visibleWidth());
//    horizontalScrollBar()->setLineStep(visibleWidth() / 10);
    horizontalScrollBar()->setMaximum(
        std::max(contentsWidth()-visibleWidth(),0));
    verticalScrollBar()->setPageStep(visibleHeight());
//    verticalScrollBar()->setLineStep(visibleHeight() / 10);
    verticalScrollBar()->setMaximum(
        std::max(contentsHeight()-visibleHeight(),0));

//	RG_DEBUG << "RosegardenScrollView::updateScrollBars :" << 
//        " pagewidth - " << visibleWidth() << 
//        " pageheight - " << visibleHeight();
}
Exemplo n.º 11
0
void QGridView::paintEmptyArea( QPainter *p, int cx ,int cy, int cw, int ch)
{
    if ( gridSize().width() >= contentsWidth() && gridSize().height() >= contentsHeight() )
	return;
    // Region of the rect we should draw
    contentsToViewport( cx, cy, cx, cy );
    QRegion reg( QRect( cx, cy, cw, ch ) );
    // Subtract the table from it
    reg = reg.subtract( QRect( contentsToViewport( QPoint( 0, 0 ) ), gridSize() ) );

    // And draw the rectangles (transformed as needed)
    QMemArray<QRect> r = reg.rects();
    const QBrush &brush = backgroundBrush();
    for ( int i = 0; i < (int)r.count(); ++i)
	p->fillRect( r[ i ], brush );
}
Exemplo n.º 12
0
bool ScrollView::platformHandleVerticalAdjustment(const IntSize& scroll)
{
    if (m_verticalAdjustment) {
        m_verticalAdjustment->page_size = visibleHeight();
        m_verticalAdjustment->step_increment = visibleHeight() / 10.0;
        m_verticalAdjustment->page_increment = visibleHeight() * 0.9;
        m_verticalAdjustment->lower = 0;
        m_verticalAdjustment->upper = contentsHeight();
        gtk_adjustment_changed(m_verticalAdjustment);

        if (m_scrollOffset.height() != scroll.height()) {
            m_verticalAdjustment->value = scroll.height();
            gtk_adjustment_value_changed(m_verticalAdjustment);
        }
        return true;
    } 
    return false;
}
Exemplo n.º 13
0
bool ScrollView::platformHandleVerticalAdjustment(const IntSize& scroll)
{
    if (m_verticalAdjustment) {
        m_verticalAdjustment->page_size = visibleHeight();
        m_verticalAdjustment->step_increment = cScrollbarPixelsPerLineStep;
        m_verticalAdjustment->page_increment = visibleHeight() - cAmountToKeepWhenPaging;
        m_verticalAdjustment->lower = 0;
        m_verticalAdjustment->upper = contentsHeight();
        gtk_adjustment_changed(m_verticalAdjustment);

        if (m_verticalAdjustment->value != scroll.height()) {
            m_verticalAdjustment->value = scroll.height();
            gtk_adjustment_value_changed(m_verticalAdjustment);
        }
        return true;
    } 
    return false;
}
Exemplo n.º 14
0
void QtFileIconView::newDirectory()
{
    setAutoArrange( FALSE );
    selectAll( FALSE );
    if ( viewDir.mkdir( QString( "New Folder %1" ).arg( ++newFolderNum ) ) ) {
        QFileInfo *fi = new QFileInfo( viewDir, QString( "New Folder %1" ).arg( newFolderNum ) );
        QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) );
        item->setKey( QString( "000000%1" ).arg( fi->fileName() ) );
        delete fi;
        repaintContents( contentsX(), contentsY(), contentsWidth(), contentsHeight(), FALSE );
        ensureItemVisible( item );
        item->setSelected( TRUE, TRUE );
        setCurrentItem( item );
        repaintItem( item );
        qApp->processEvents();
        item->rename();
    }
    setAutoArrange( TRUE );
}
Exemplo n.º 15
0
// Reimplemented 
void QmvList::resizeEvent( QResizeEvent *e )
{
    QListView::resizeEvent( e );
    QSize vs = viewportSize( 0, contentsHeight() );

    int os = header()->sectionSize( 1 );
    int ns = vs.width() - header()->sectionSize( 0 );
    if ( ns < 16 )
	ns = 16;
	
    header()->resizeSection( 1, ns );
    header()->repaint( header()->width() - header()->sectionSize( 1 ),
                       0, header()->sectionSize( 1 ), header()->height() );

    int elipsis = fontMetrics().width("...") + 10;
    viewport()->repaint( header()->sectionPos(1) + os - elipsis, 0, elipsis, viewport()->height(), FALSE );
    if ( currentItem() )
	( ( QmvItem* )currentItem() )->showEditor();
}
Exemplo n.º 16
0
void KImportIconView::drawContents ( QPainter *p, int cx, int cy, int cw, int ch )
{
    if ( !m_bDropped)
    {
        QIconView::drawContents ( p, cx, cy, cw, ch );

        p->save();
        QFont font ( p->font() );
        font.setBold ( true );
        font.setFamily ( "Helvetica [Adobe]" );
        font.setPointSize ( 10 );
        p->setFont ( font );
        p->setPen ( QPen ( KGlobalSettings::highlightColor() ) );

        QRect rect = frameRect();
        QFontMetrics fm ( p->font() );
        rect.setLeft ( rect.left() + 30 );
        rect.setRight ( rect.right() - 30 );

        resizeContents ( contentsWidth(), contentsHeight() );

        // word-wrap the string
        KWordWrap* wordWrap1 = KWordWrap::formatText( fm, rect, AlignHCenter | WordBreak, m_strIntro );
        KWordWrap* wordWrap2 = KWordWrap::formatText( fm, rect, AlignHCenter | WordBreak, i18n("Or just use the buttons.") );

        QRect introRect1 = wordWrap1->boundingRect();
		QRect introRect2 = wordWrap2->boundingRect();

        wordWrap1->drawText ( p, ( ( frameRect().right() - introRect1.right() ) / 2 ), ( ( frameRect().bottom() - introRect1.bottom() ) / 2 ) - 20, AlignHCenter | AlignVCenter );
        wordWrap2->drawText ( p, ( ( frameRect().right() - introRect2.right() ) / 2 ), ( ( frameRect().bottom() - introRect2.bottom() ) / 2 ) + introRect1.bottom(), AlignHCenter | AlignVCenter );

        p->restore();
    }
    else
    {
        QIconView::drawContents ( p, cx, cy, cw, ch );
    }
}
Exemplo n.º 17
0
void KVocTrainTable::contentsMousePressEvent(QMouseEvent * e)
{
  delayTimer->stop();
  int cc = columnAt(e->x());
  int cr = rowAt(e->y());
  int co = currentColumn();

  QTable::contentsMousePressEvent(e);

  if(cc >= KV_EXTRA_COLS) {
    // update color of original when column changes and more than 1 translation
    bool update_org = false;
    if (cc != co && numCols() > 2)
      update_org = true;

    int topCell = rowAt(0);
    int lastRowVisible = QMIN(numRows(), rowAt(contentsHeight()));
    if (update_org)
      for (int i = topCell; i <= lastRowVisible; i++)
        updateCell(i, KV_COL_ORG);
  }
  if(e->button() == LeftButton)
    setCurrentCell(cr, cc);
}
Exemplo n.º 18
0
QSize QVFbView::sizeHint() const
{
    int f = 2 * frameWidth();
    return QSize( contentsWidth() + f, contentsHeight() + f );
}
Exemplo n.º 19
0
void PageView::layoutPages(bool zoomChanged)
{
  // Paranoid safety check
  if (widgetList == 0)
    return;

  // If there are no widgets, e.g. because the last widget has been
  // removed, the matter is easy: set the contents size to 0. If there
  // are no widgets because previously existing widgets were removed
  // (we detect that by looking at the contentsWidth and -Height).
  if (widgetList->isEmpty()) {
    if ((contentsWidth() != 0) || (contentsHeight() != 0)) {
      QScrollView::resizeContents(0,0);
    }
    return;
  }

  // Ok, now we are in a situation where we do have some widgets that
  // shall be centered.
  int distance = distanceBetweenWidgets;
  if (singlePageFullScreenMode())
  {
    // In single page fullscreen mode we don't want a margin around the pages
    distance = 0;
  }

  QMemArray<Q_UINT32> colWidth(nrCols);
  for(Q_UINT8 i=0; i<colWidth.size(); i++)
    colWidth[i] = 0;

  Q_UINT16 numRows;
  if(nrCols <= 2)
  {
    numRows = (widgetList->size()+2*nrCols-2) / nrCols;
  }
  else
  {
    numRows = (Q_INT16)ceil(((double)widgetList->size()) / nrCols);
  }

  QMemArray<Q_UINT32> rowHeight(numRows);
  for(Q_UINT16 i=0; i<rowHeight.size(); i++)
    rowHeight[i] = 0;

  // Now find the widths and heights of the columns
  for(Q_UINT16 i=0; i<widgetList->size(); i++) 
  {
    Q_UINT8 col;
    Q_UINT16 row;

    if (nrCols == 2) {
      // In two-column display, start with the right column
      col = (i+1+nrCols) % nrCols;
      row = (i+1+nrCols) / nrCols - 1;
    } else {
      col = (i+nrCols) % nrCols;
      row = (i+nrCols) / nrCols - 1;
    }

    colWidth[col] = QMAX(colWidth[col], (Q_UINT32)widgetList->at(i)->pageSize().width());
    rowHeight[row] = QMAX(rowHeight[row], (Q_UINT32)widgetList->at(i)->pageSize().height());
  }

  // Calculate the total width and height of the display
  Q_UINT32 totalHeight = 0;
  for(Q_UINT16 i=0; i<rowHeight.size(); i++)
    totalHeight += rowHeight[i];

  totalHeight += (numRows+1)*distance;
  Q_UINT32 totalWidth = 0;
  for(Q_UINT8 i=0; i<colWidth.size(); i++)
    totalWidth += colWidth[i];

  totalWidth += (nrCols+1)*distance;
  QSize newViewportSize = viewportSize( totalWidth, totalHeight );
  Q_UINT32 centeringLeft = 0;
  if( (Q_UINT32)newViewportSize.width() > totalWidth )
    centeringLeft = ( newViewportSize.width() - totalWidth )/2;
  Q_UINT32 centeringTop = 0;
  if( (Q_UINT32)newViewportSize.height() > totalHeight )
    centeringTop = ( newViewportSize.height() - totalHeight)/2;

  // Resize the viewport
  if (((Q_UINT32)contentsWidth() != totalWidth) || ((Q_UINT32)contentsHeight() != totalHeight))
  {
    // Calculate the point in the coordinates of the contents which is currently at the center of the viewport.
    QPoint midPoint = QPoint(visibleWidth() / 2 + contentsX(), visibleHeight() / 2 + contentsY()); 
    double midPointRatioX = (double)(midPoint.x()) / contentsWidth();
    double midPointRatioY = (double)(midPoint.y()) / contentsHeight();

    resizeContents(totalWidth,totalHeight);

    // If the zoom changed recenter the former midPoint
    if (zoomChanged)
      center((int)(contentsWidth() * midPointRatioX), (int)(contentsHeight() * midPointRatioY));
  }

  // Finally, calculate the left and top coordinates of each row and
  // column, respectively
  QMemArray<Q_UINT32> colLeft(nrCols);
  colLeft[0] = distance;
  for(Q_UINT8 i=1; i<colLeft.size(); i++)
    colLeft[i] = colLeft[i-1]+colWidth[i-1]+distance;

  QMemArray<Q_UINT32> rowTop(numRows);
  rowTop[0] = distance;
  for(Q_UINT16 i=1; i<rowTop.size(); i++)
    rowTop[i] = rowTop[i-1]+rowHeight[i-1]+distance;

  for(Q_UINT16 i=0; i<widgetList->size(); i++) 
  {
    Q_UINT8 col;
    Q_UINT16 row;
    if (nrCols == 2)
    {
      // In two column-mode start with the right column.
      col = (i+nrCols-1) % nrCols;
      row = (i+nrCols-1) / nrCols;
    }
    else
    {
      col = (i+nrCols) % nrCols;
      row = i / nrCols;
    }
    if (nrCols == 2)
    {
      // in 2-column mode right justify the first column, and leftjustify the second column
      int width = widgetList->at(i)->width();
      int left;
      if (col == 0)
        left = centeringLeft + colLeft[col] + colWidth[col]-width + distance/2;
      else
        left = centeringLeft + colLeft[col];
      moveChild( widgetList->at(i), left, centeringTop+rowTop[row]);
    }
    else
    {
      // in single column and overview mode center the widgets
      int widgetWidth = widgetList->at(i)->width();
      int left = centeringLeft + colLeft[col] + ((int)colWidth[col]-widgetWidth)/2;
      moveChild(widgetList->at(i), left, centeringTop+rowTop[row]);
    }
  }
  calculateCurrentPageNumber();
}
Exemplo n.º 20
0
void ScrollView::updateScrollbars(const IntSize& desiredOffset)
{
    // Don't allow re-entrancy into this function.
    if (m_data->m_inUpdateScrollbars)
        return;

    // FIXME: This code is here so we don't have to fork FrameView.h/.cpp.
    // In the end, FrameView should just merge with ScrollView.
    if (static_cast<const FrameView*>(this)->frame()->prohibitsScrolling())
        return;

    m_data->m_inUpdateScrollbars = true;

    bool hasVerticalScrollbar = m_data->m_vBar;
    bool hasHorizontalScrollbar = m_data->m_hBar;
    bool oldHasVertical = hasVerticalScrollbar;
    bool oldHasHorizontal = hasHorizontalScrollbar;
    ScrollbarMode hScroll = m_data->m_hScrollbarMode;
    ScrollbarMode vScroll = m_data->m_vScrollbarMode;
    
    const int cVerticalWidth = PlatformScrollbar::verticalScrollbarWidth();
    const int cHorizontalHeight = PlatformScrollbar::horizontalScrollbarHeight();

    for (int pass = 0; pass < 2; pass++) {
        bool scrollsVertically;
        bool scrollsHorizontally;

        if (!m_data->m_scrollbarsSuppressed && (hScroll == ScrollbarAuto || vScroll == ScrollbarAuto)) {
            // Do a layout if pending before checking if scrollbars are needed.
            if (hasVerticalScrollbar != oldHasVertical || hasHorizontalScrollbar != oldHasHorizontal)
                static_cast<FrameView*>(this)->layout();

            scrollsVertically = (vScroll == ScrollbarAlwaysOn) || (vScroll == ScrollbarAuto && contentsHeight() > height());
            if (scrollsVertically)
                scrollsHorizontally = (hScroll == ScrollbarAlwaysOn) || (hScroll == ScrollbarAuto && contentsWidth() + cVerticalWidth > width());
            else {
                scrollsHorizontally = (hScroll == ScrollbarAlwaysOn) || (hScroll == ScrollbarAuto && contentsWidth() > width());
                if (scrollsHorizontally)
                    scrollsVertically = (vScroll == ScrollbarAlwaysOn) || (vScroll == ScrollbarAuto && contentsHeight() + cHorizontalHeight > height());
            }
        }
        else {
            scrollsHorizontally = (hScroll == ScrollbarAuto) ? hasHorizontalScrollbar : (hScroll == ScrollbarAlwaysOn);
            scrollsVertically = (vScroll == ScrollbarAuto) ? hasVerticalScrollbar : (vScroll == ScrollbarAlwaysOn);
        }
        
        if (hasVerticalScrollbar != scrollsVertically) {
            m_data->setHasVerticalScrollbar(scrollsVertically);
            hasVerticalScrollbar = scrollsVertically;
        }

        if (hasHorizontalScrollbar != scrollsHorizontally) {
            m_data->setHasHorizontalScrollbar(scrollsHorizontally);
            hasHorizontalScrollbar = scrollsHorizontally;
        }
    }
    
    // Set up the range (and page step/line step).
    IntSize maxScrollPosition(contentsWidth() - visibleWidth(), contentsHeight() - visibleHeight());
    IntSize scroll = desiredOffset.shrunkTo(maxScrollPosition);
    scroll.clampNegativeToZero();
 
    if (m_data->m_hBar) {
        int clientWidth = visibleWidth();
        m_data->m_hBar->setEnabled(contentsWidth() > clientWidth);
        int pageStep = (clientWidth - PAGE_KEEP);
        if (pageStep < 0) pageStep = clientWidth;
        IntRect oldRect(m_data->m_hBar->frameGeometry());
        IntRect hBarRect = IntRect(0,
                                   height() - m_data->m_hBar->height(),
                                   width() - (m_data->m_vBar ? m_data->m_vBar->width() : 0),
                                   m_data->m_hBar->height());
        m_data->m_hBar->setRect(hBarRect);
        if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_hBar->frameGeometry())
            m_data->m_hBar->invalidate();

        if (m_data->m_scrollbarsSuppressed)
            m_data->m_hBar->setSuppressInvalidation(true);
        m_data->m_hBar->setSteps(LINE_STEP, pageStep);
        m_data->m_hBar->setProportion(clientWidth, contentsWidth());
        m_data->m_hBar->setValue(scroll.width());
        if (m_data->m_scrollbarsSuppressed)
            m_data->m_hBar->setSuppressInvalidation(false); 
    } 

    if (m_data->m_vBar) {
        int clientHeight = visibleHeight();
        m_data->m_vBar->setEnabled(contentsHeight() > clientHeight);
        int pageStep = (clientHeight - PAGE_KEEP);
        if (pageStep < 0) pageStep = clientHeight;
        IntRect oldRect(m_data->m_vBar->frameGeometry());
        IntRect vBarRect = IntRect(width() - m_data->m_vBar->width(), 
                                   0,
                                   m_data->m_vBar->width(),
                                   height() - (m_data->m_hBar ? m_data->m_hBar->height() : 0));
        m_data->m_vBar->setRect(vBarRect);
        if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_vBar->frameGeometry())
            m_data->m_vBar->invalidate();

        if (m_data->m_scrollbarsSuppressed)
            m_data->m_vBar->setSuppressInvalidation(true);
        m_data->m_vBar->setSteps(LINE_STEP, pageStep);
        m_data->m_vBar->setProportion(clientHeight, contentsHeight());
        m_data->m_vBar->setValue(scroll.height());
        if (m_data->m_scrollbarsSuppressed)
            m_data->m_vBar->setSuppressInvalidation(false);
    }

    if (oldHasVertical != (m_data->m_vBar != 0) || oldHasHorizontal != (m_data->m_hBar != 0))
        geometryChanged();

    // See if our offset has changed in a situation where we might not have scrollbars.
    // This can happen when editing a body with overflow:hidden and scrolling to reveal selection.
    // It can also happen when maximizing a window that has scrollbars (but the new maximized result
    // does not).
    IntSize scrollDelta = scroll - m_data->m_scrollOffset;
    if (scrollDelta != IntSize()) {
       m_data->m_scrollOffset = scroll;
       m_data->scrollBackingStore(scrollDelta);
    }

    m_data->m_inUpdateScrollbars = false;
}
Exemplo n.º 21
0
IntSize ScrollView::maximumScroll() const
{
    IntSize delta = (IntSize(contentsWidth(), contentsHeight()) - IntSize(visibleWidth(), visibleHeight())) - scrollOffset();
    delta.clampNegativeToZero();
    return delta;
}