Beispiel #1
0
void
DataView::UpdateScroller()
{
	float width, height;
	GetPreferredSize(&width, &height);

	SetExplicitMinSize(BSize(250, 200));
	SetExplicitMaxSize(BSize(B_SIZE_UNSET, height));
	SetExplicitPreferredSize(BSize(width, height));

	BScrollBar *bar;
	if ((bar = ScrollBar(B_HORIZONTAL)) != NULL) {
		float delta = width - Bounds().Width();
		if (delta < 0)
			delta = 0;

		bar->SetRange(0, delta);
		bar->SetSteps(fCharWidth, Bounds().Width());
		bar->SetProportion(Bounds().Width() / width);
	}
	if ((bar = ScrollBar(B_VERTICAL)) != NULL) {
		float delta = height - Bounds().Height();
		if (delta < 0)
			delta = 0;

		bar->SetRange(0, delta);
		bar->SetSteps(fFontHeight, Bounds().Height());
		bar->SetProportion(Bounds().Height() / height);
	}
}
Beispiel #2
0
void PictureViewer::AdjustScrollBars() {
  if ( (thePic == NULL) || (setup->ViewingMode() == PEEK_IMAGE_SCALE_TO_WINDOW) ||
       (setup->ViewingMode() == PEEK_IMAGE_SCALED_NICELY)
     ) {
                         ScrollBar( B_VERTICAL ) -> SetRange( 0, 0 );
                         ScrollBar( B_HORIZONTAL ) -> SetRange( 0, 0 );
                         return;
                       }

  float x = 0;
  float y = 0;
  

                // we do a [if (thePic != NULL) ] because I can't handle the Multitasking
                // aspect of the Slideshow. Sometimes the program gets here, from the
                // top of the method and the picture has already been deleted. I've
                // tried everything to synchronize it all. Maybe I've missed something.
                if (thePic != NULL) x = thePic->Bounds().Width();
                if (thePic != NULL) y = thePic->Bounds().Height();
  
  if ( Bounds().Width()  > x ) x = 0;
                          else x = x - Bounds().Width();
  if ( Bounds().Height() > y ) y = 0;
                          else y = y - Bounds().Height();  
  
  
  ScrollBar( B_VERTICAL ) -> SetRange( 0, y );
  ScrollBar( B_HORIZONTAL ) -> SetRange( 0, x );
}
void
TextDocumentView::_UpdateScrollBars()
{
	BRect bounds(Bounds());

	BScrollBar* horizontalScrollBar = ScrollBar(B_HORIZONTAL);
	if (horizontalScrollBar != NULL) {
		long viewWidth = bounds.IntegerWidth();
		long dataWidth = (long)ceilf(
			fTextDocumentLayout.Width() + fInsetLeft + fInsetRight);

		long maxRange = dataWidth - viewWidth;
		maxRange = std::max(maxRange, 0L);

		horizontalScrollBar->SetRange(0, (float)maxRange);
		horizontalScrollBar->SetProportion((float)viewWidth / dataWidth);
		horizontalScrollBar->SetSteps(kHorizontalScrollBarStep, dataWidth / 10);
	}

 	BScrollBar* verticalScrollBar = ScrollBar(B_VERTICAL);
	if (verticalScrollBar != NULL) {
		long viewHeight = bounds.IntegerHeight();
		long dataHeight = (long)ceilf(
			fTextDocumentLayout.Height() + fInsetTop + fInsetBottom);

		long maxRange = dataHeight - viewHeight;
		maxRange = std::max(maxRange, 0L);

		verticalScrollBar->SetRange(0, maxRange);
		verticalScrollBar->SetProportion((float)viewHeight / dataHeight);
		verticalScrollBar->SetSteps(kVerticalScrollBarStep, viewHeight);
	}
}
void
ImageView::AdjustScrollBars()
{
	BRect rctview = Bounds(), rctbitmap(0, 0, 0, 0);
	if (HasImage())
		rctbitmap = fpbitmap->Bounds();

	float prop, range;
	BScrollBar *psb = ScrollBar(B_HORIZONTAL);
	if (psb) {
		range = rctbitmap.Width() + (BORDER_WIDTH * 2) - rctview.Width();
		if (range < 0) range = 0;
		prop = rctview.Width() / (rctbitmap.Width() + (BORDER_WIDTH * 2));
		if (prop > 1.0f) prop = 1.0f;
		psb->SetRange(0, range);
		psb->SetProportion(prop);
		psb->SetSteps(10, 100);
	}

	psb = ScrollBar(B_VERTICAL);
	if (psb) {
		range = rctbitmap.Height() + (BORDER_HEIGHT * 2) - rctview.Height();
		if (range < 0) range = 0;
		prop = rctview.Height() / (rctbitmap.Height() + (BORDER_HEIGHT * 2));
		if (prop > 1.0f) prop = 1.0f;
		psb->SetRange(0, range);
		psb->SetProportion(prop);
		psb->SetSteps(10, 100);
	}
}
void
BasicPreviewView::_ScrollDownBigStep(void)
{
    float height = Bounds().Height();
    int value1 = ScrollBar(B_VERTICAL)->Value() + height;

    ScrollBar(B_VERTICAL)->SetValue(value1);
}
Beispiel #6
0
// AttachedToWindow
void
YBScrollView::AttachedToWindow()
{
	BScrollView::AttachedToWindow();
	SetViewColor(B_TRANSPARENT_32_BIT);

	// relayout scrollbars as in R5
	// TODO: make this complete for all border_styles
	// and the horizontal scrollbar (but for now it is sufficient)
	BRect bounds = Bounds();
	switch (Border()) {
		case B_FANCY_BORDER: {
			BScrollBar* vScrollBar = ScrollBar(B_VERTICAL);
			if (vScrollBar) {
				vScrollBar->MoveTo(bounds.right - (B_V_SCROLL_BAR_WIDTH + 1),
								   bounds.top + 1);
				vScrollBar->ResizeTo(vScrollBar->Frame().Width(),
									 bounds.Height() - 2);
			}

			BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL);
			if (hScrollBar) {
				hScrollBar->MoveTo(bounds.left + 1,
								   bounds.bottom - (B_H_SCROLL_BAR_HEIGHT + 1));
				hScrollBar->ResizeTo(bounds.Width() - 2,
									 hScrollBar->Frame().Height());
			}
			
			if (BView* target = Target()) {
				target->MoveTo(2.0, 2.0);
				if (vScrollBar && hScrollBar) {
					target->ResizeTo(bounds.Width() - (B_V_SCROLL_BAR_WIDTH + 4),
									 bounds.Height() - (B_H_SCROLL_BAR_HEIGHT + 4));
				} else if (vScrollBar) {
					target->ResizeTo(bounds.Width() - (B_V_SCROLL_BAR_WIDTH + 4),
									 bounds.Height() - 4);
				} else if (hScrollBar) {
					target->ResizeTo(bounds.Width() - 4,
									 bounds.Height() - (B_H_SCROLL_BAR_HEIGHT + 4));
				} else {
					target->ResizeTo(bounds.Width() - 4, bounds.Height() - 4);
				}
			}
			break;
		}
		default:
			break;
	}
}
Beispiel #7
0
void
TermView::_PushLine(int cols, const VTermScreenCell* cells)
{
	ScrollBufferItem* item = (ScrollBufferItem*)malloc(sizeof(int)
		+ cols * sizeof(VTermScreenCell));
	item->cols = cols;
	memcpy(item->cells, cells, cols * sizeof(VTermScreenCell));

	fScrollBuffer.AddItem(item, 0);

	free(fScrollBuffer.RemoveItem(kScrollBackSize));

	int availableRows, availableCols;
	vterm_get_size(fTerm, &availableRows, &availableCols);

	VTermRect dirty;
	dirty.start_col = 0;
	dirty.end_col = availableCols;
	dirty.end_row = 0;
	dirty.start_row = -fScrollBuffer.CountItems();
	// FIXME we should rather use CopyRect if possible, and only invalidate the
	// newly exposed area here.
	Invalidate(_GlyphsToPixels(dirty));

	BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
	if (scrollBar != NULL) {
		float range = (fScrollBuffer.CountItems() + availableRows)
			* fFontHeight;
		scrollBar->SetRange(availableRows * fFontHeight - range, 0.0f);
		// TODO we need to adjust this in FrameResized, as availableRows can
		// change
		scrollBar->SetProportion(availableRows * fFontHeight / range);
		scrollBar->SetSteps(fFontHeight, fFontHeight * 3);
	}
}
Beispiel #8
0
void
BListView::_FixupScrollBar()
{
	BScrollBar* vertScroller = ScrollBar(B_VERTICAL);
	if (!vertScroller)
		return;

	BRect bounds = Bounds();
	int32 count = CountItems();

	float itemHeight = 0.0;

	if (CountItems() > 0)
		itemHeight = ItemAt(CountItems() - 1)->Bottom();

	if (bounds.Height() > itemHeight) {
		// no scrolling
		vertScroller->SetRange(0.0, 0.0);
		vertScroller->SetValue(0.0);
			// also scrolls ListView to the top
	} else {
		vertScroller->SetRange(0.0, itemHeight - bounds.Height() - 1.0);
		vertScroller->SetProportion(bounds.Height () / itemHeight);
		// scroll up if there is empty room on bottom
		if (itemHeight < bounds.bottom)
			ScrollBy(0.0, bounds.bottom - itemHeight);
	}

	if (count != 0)
		vertScroller->SetSteps(ceilf(FirstItem()->Height()), bounds.Height());
}
void
PackagesView::FrameResized(float width, float height)
{
    if (CountChildren() == 0)
        Invalidate();

    BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
    if (scrollBar == NULL)
        return;

    float virtualHeight = 0.0;

    int32 count = CountChildren();
    if (count > 0) {
        BView* child = ChildAt(count - 1);
        virtualHeight = child->Frame().bottom;
    }

    if (height > virtualHeight) {
        scrollBar->SetRange(0.0f, 0.0f);
        scrollBar->SetValue(0.0f);
    } else {
        scrollBar->SetRange(0.0f, virtualHeight - height);
        scrollBar->SetProportion(height / virtualHeight);
    }

    scrollBar->SetSteps(15, height);
}
inline void
BasicPreviewView::_SetScrollBarAtPage(int pageNumber)
{
    _AdaptScrollBarRange();
    ScrollBar(B_VERTICAL)->SetValue(fVMargin +
        (_PageHeight(pageNumber) + fVSpace) * _PageToRow(pageNumber));
}
Beispiel #11
0
void WrappingTextView::ResetTextRect()
{
	BRect bounds = Bounds();
	BRect textRect = bounds;
	textRect.left = 4.0;
	textRect.top = m_vertical_offset + 4.0f;
	if (m_fixed_width)
		textRect.right = 8.0f + StringWidth( "0") * float(m_fixed_width);
	else
		textRect.right -= 4.0f;
	textRect.bottom -= 4.0f;
	SetTextRect(textRect);
	// we have to readjust the scrollbar-proportion, since
	// the BTextView doesn't do it correctly when we have
	// fooled in a vertical_offset:
	float small, big;
	BScrollBar* bar = ScrollBar( B_VERTICAL);
	if (!bar) 	return;
	bar->GetSteps( &small, &big);
	float height = TextHeight( 0, TextLength());
	if (height+m_vertical_offset)
		bar->SetProportion( MIN( 1.0f, big/(height+m_vertical_offset)));
	else 
		bar->SetProportion( 1.0f);

	if (BeamOnDano) {
		// circumvent a special feature/bug in Zeta with respect to 
		// the scrollbar not always calling ValueChanged() on a click.
		// Seemingly, changing the value twice hides the bug:
		bar->SetValue(1);
		bar->SetValue(0);
	}

	bar = ScrollBar( B_HORIZONTAL);
	if (!bar) 	return;
	float width = bounds.Width();
	float maxWidth = MAX( width, textRect.right);
	int numChildren = IsEditable() ? 0 : CountChildren();
	for( int i=0; i<numChildren; ++i) {
		float w = ChildAt( i)->Frame().Width();
		if (w > maxWidth)
			maxWidth = w;
	}
	bar->SetSteps( width/10, width);
	bar->SetRange( 0, MAX(0, maxWidth-width));
	bar->SetProportion( MIN( 1.0f, width/maxWidth));
}
void
MemoryView::_RecalcScrollBars()
{
	float max = 0.0;
	BScrollBar *scrollBar = ScrollBar(B_VERTICAL);
	if (fTargetBlock != NULL) {
		BRect bounds = Bounds();
		// the left portion of the view is off limits since it
		// houses the address offset of the current line
		float baseWidth = bounds.Width() - ((fTargetAddressSize + 2)
			* fCharWidth);
		float hexWidth = 0.0;
		float textWidth = 0.0;
		int32 hexDigits = 1 << fHexMode;
		int32 sizeFactor = 1 + hexDigits;
		if (fHexMode != HexModeNone) {
			if (fTextMode != TextModeNone) {
				float hexProportion = sizeFactor / (float)(sizeFactor
					+ hexDigits / 2);
				hexWidth = baseWidth * hexProportion;
				// when sharing the display between hex and text,
				// we allocate a 2 character space to separate the views
				hexWidth -= 2 * fCharWidth;
				textWidth = baseWidth - hexWidth;
			} else
				hexWidth = baseWidth;
		} else if (fTextMode != TextModeNone)
			textWidth = baseWidth;

		int32 nybblesPerLine = int32(hexWidth / fCharWidth);
		fHexBlocksPerLine = 0;
		fTextCharsPerLine = 0;
		if (fHexMode != HexModeNone) {
			fHexBlocksPerLine = nybblesPerLine / sizeFactor;
			fHexBlocksPerLine &= ~1;
			if (fTextMode != TextModeNone)
				fTextCharsPerLine = fHexBlocksPerLine * hexDigits / 2;
		} else if (fTextMode != TextModeNone)
			fTextCharsPerLine = int32(textWidth / fCharWidth);

		int32 lineCount = 0;
		float totalHeight = 0.0;
		if (fHexBlocksPerLine > 0) {
			lineCount = fTargetBlock->Size() / (fHexBlocksPerLine
					* hexDigits / 2);
		} else if (fTextCharsPerLine > 0)
			lineCount = fTargetBlock->Size() / fTextCharsPerLine;

		totalHeight = lineCount * fLineHeight;
		if (totalHeight > 0.0) {
			max = totalHeight - bounds.Height();
			scrollBar->SetProportion(bounds.Height() / totalHeight);
			scrollBar->SetSteps(fLineHeight, bounds.Height());
		}
	}
	scrollBar->SetRange(0.0, max);
}
Beispiel #13
0
void
MemoryView::_ScrollByLines(int32 lineCount)
{
	BScrollBar* vertical = ScrollBar(B_VERTICAL);
	if (vertical == NULL)
		return;

	float value = vertical->Value();
	vertical->SetValue(value + fLineHeight * lineCount);
}
void BFIV_ScrollView::DoScrollBars()
{
	// use BView::ScrollBar(B_VERTICAL||B_HORIZONTAL) to get scroll bars
	BRect bounds = Bounds(), ibounds = fImage->Bounds();
	float curWidth = bounds.Width(), curHeight = bounds.Height();
	float maxWidth = ibounds.Width(), maxHeight = ibounds.Height();
	float propHor, propVert, rangeHor, rangeVert;
	BScrollBar *scroll;
	
	//bounds.PrintToStream();
	//ibounds.PrintToStream();
	
	// 5 pixel gutter on each side
	maxWidth += 10;
	maxHeight += 10;
	
	// proportional width and height
	propHor = curWidth/maxWidth;
	propVert = curHeight/maxHeight;
	
	// width and height ranges
	rangeHor = maxWidth - curWidth;
	rangeVert = maxHeight - curHeight;
	
	// sanity check
	if(rangeHor < 0.0) rangeHor = 0.0;
	if(rangeVert < 0.0) rangeVert = 0.0;
	
	// update scrollbars
	if ((scroll = ScrollBar(B_HORIZONTAL)) != NULL)
	{
		scroll->SetProportion(propHor);
		scroll->SetRange(0,rangeHor);
		scroll->SetSteps(curWidth / 20.0, curWidth / 5.0);
	} 
	if ((scroll = ScrollBar(B_VERTICAL)) != NULL)
	{
		scroll->SetProportion(propVert);
		scroll->SetRange(0,rangeVert);
		scroll->SetSteps(curHeight / 20.0, curHeight / 5.0);
	}
}
Beispiel #15
0
	virtual void DoLayout()
	{
		BRect innerFrame = Bounds();
		innerFrame.InsetBy(2, 2);

		BScrollBar* vScrollBar = ScrollBar(B_VERTICAL);
		BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL);

		if (vScrollBar != NULL)
			innerFrame.right -= vScrollBar->Bounds().Width() - 1;
		if (hScrollBar != NULL)
			innerFrame.bottom -= hScrollBar->Bounds().Height() - 1;

		BView* target = Target();
		if (target != NULL) {
			Target()->MoveTo(innerFrame.left, innerFrame.top);
			Target()->ResizeTo(innerFrame.Width(), innerFrame.Height());
		}

		if (vScrollBar != NULL) {
			BRect rect = innerFrame;
			rect.left = rect.right + 1;
			rect.right = rect.left + vScrollBar->Bounds().Width();
			rect.top -= 1;
			rect.bottom += 1;

			vScrollBar->MoveTo(rect.left, rect.top);
			vScrollBar->ResizeTo(rect.Width(), rect.Height());
		}

		if (hScrollBar != NULL) {
			BRect rect = innerFrame;
			rect.top = rect.bottom + 1;
			rect.bottom = rect.top + hScrollBar->Bounds().Height();
			rect.left -= 1;
			rect.right += 1;

			hScrollBar->MoveTo(rect.left, rect.top);
			hScrollBar->ResizeTo(rect.Width(), rect.Height());
		}
	}
void
MediaRoutingView::_adjustScrollBars()
{
	D_METHOD(("MediaRoutingView::_adjustScrollBars()\n"));

	BScrollBar *scrollBar;

	// adjust horizontal scroll bar
	scrollBar = ScrollBar(B_HORIZONTAL);
	if (scrollBar) {
		float bigStep = floor(MediaNodePanel::M_DEFAULT_WIDTH + M_CLEANUP_H_GAP);
		scrollBar->SetSteps(floor(bigStep / 10.0), bigStep);
	}

	// adjust vertical scroll bar
	scrollBar = ScrollBar(B_VERTICAL);
	if (scrollBar) {
		float bigStep = floor(MediaNodePanel::M_DEFAULT_HEIGHT + M_CLEANUP_V_GAP);
		scrollBar->SetSteps(floor(bigStep / 10.0), bigStep);
	}
}
inline void
BasicPreviewView::_AdaptScrollBarRange(void)
{
    if (fEngine == nullptr)
        return;

    if (fColumnWidth == 0) {
        ScrollBar(B_VERTICAL)->SetRange(0, fVMargin + (fVSpace + _PageHeight()) * fRows
            - Bounds().Height());

        float bigStepV = std::min(Bounds().Height(), _PageHeight());
        float smallStepV = Bounds().Height() / 27;
        ScrollBar(B_VERTICAL)->SetSteps(smallStepV, bigStepV);
    } else {
        ScrollBar(B_VERTICAL)->SetRange(0, fVMargin + (fVSpace + _PageHeight()) * fRows
            - Bounds().Height());

        float bigStepV = Bounds().Height();
        float smallStepV = Bounds().Height() / 27;
        ScrollBar(B_VERTICAL)->SetSteps(smallStepV, bigStepV);
    }
}
void
BasicPreviewView::MouseMoved(BPoint where, uint32 code,
    const BMessage* dragMessage)
{
    switch (code) {
		case B_EXITED_VIEW:
            fIsPanning  = false;
            break;

		default:
            break;
	}

    if (fIsPanning == true) {
        BPoint delta = fOldMousePos - where;

        ScrollBar(B_VERTICAL)->SetValue(
            ScrollBar(B_VERTICAL)->Value() + delta.y);
    }

    BView::MouseMoved(where, code, dragMessage);
}
Beispiel #19
0
void AlbumView::UpdateScrollbars(float width, float height)
{
	BScrollBar *hscroll = ScrollBar(B_HORIZONTAL);
	if (hscroll) {
		float full = PageBounds().right * fZoom;
		float range = full - width;
		if (range < 0)
			range = 0;
		hscroll->SetProportion(width / full);
		hscroll->SetRange(0, range);
		hscroll->SetSteps(fSmallStep, range/10);
	}
	BScrollBar *vscroll = ScrollBar(B_VERTICAL);
	if (vscroll) {
		float full = PageBounds().bottom * fZoom;
		float range = full - height;
		if (range < 0)
			range = 0;
		vscroll->SetProportion(height / full);
		vscroll->SetRange(0, range);
		vscroll->SetSteps(fSmallStep, range/10);
	}
}
	virtual void DoLayout()
	{
		BScrollView::DoLayout();
		// Tweak scroll bar layout to hide part of the frame for better looks.
		BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
		scrollBar->MoveBy(1, -1);
		scrollBar->ResizeBy(0, 2);
		Target()->ResizeBy(1, 0);
		// Set the scroll steps
		if (BView* item = Target()->ChildAt(0)) {
			scrollBar->SetSteps(item->MinSize().height + 1,
				item->MinSize().height + 1);
		}
	}
	virtual void DoLayout()
	{
		BGroupView::DoLayout();
		if (BScrollBar* scrollBar = ScrollBar(B_VERTICAL)) {
			BSize minSize = BGroupView::MinSize();
			float height = Bounds().Height();
			float max = minSize.height - height;
			scrollBar->SetRange(0, max);
			if (minSize.height > 0)
				scrollBar->SetProportion(height / minSize.height);
			else
				scrollBar->SetProportion(1);
		}
	}
Beispiel #22
0
	void _UpdateScrollBarVisibility()
	{
		BScrollBar* verticalBar = ScrollBar(B_VERTICAL);
		if (verticalBar != NULL) {
			float min;
			float max;
			verticalBar->GetRange(&min, &max);
			if (min == max) {
				if (!verticalBar->IsHidden(verticalBar))
					verticalBar->Hide();
			} else {
				if (verticalBar->IsHidden(verticalBar))
					verticalBar->Show();
			}
		}
	}
Beispiel #23
0
void ComboBox::set_in_window() {
	
	Container::set_in_window();

	popup = GUI_NEW( Window(get_window(),Window::MODE_POPUP) );
	
	hbc = GUI_NEW( HBCCombo );
	popup->set_root_frame( hbc );
	hbc->add( list, 1);
	list->set_cursor_hint( true );	
	ScrollBar *sb = hbc->add( GUI_NEW( ScrollBar(VERTICAL)), 0);
	sb->set_range( list->get_range() );
	sb->set_auto_hide( true );
	list->selected_signal.connect( this, &ComboBox::list_selection_changed_slot );
	
	
}
Beispiel #24
0
void BComboBox::ChoiceListView::AdjustScrollBar()
{
	BScrollBar *sb = ScrollBar(B_VERTICAL);
	if (sb) {
		float h = LineHeight();
		float max = h * fParent->fChoiceList->CountChoices();
		BRect frame(Frame());
		float diff = max - frame.Height();
		float prop = frame.Height() / max;
		if (diff < 0) {
			diff = 0.0;
			prop = 1.0;
		}
		sb->SetSteps(h, h * (frame.IntegerHeight() / h));
		sb->SetRange(0.0, diff);
		sb->SetProportion(prop);
	}	
}
Beispiel #25
0
void HTMLView::AddStatement() {

	int32 number_of_runs = (int32)insertStyles.Count();
	int32 lineCount, lastOffset;
	bool doAutoScroll = true;
	
	// Get the scrollbar position... this is the part where we do autoscroll, but only 
	//   if the scrollbar is already at the bottom. That way it won't get annoying.
	if( scroll == NULL ) scroll = ScrollBar( B_VERTICAL );
	if( scroll ) {
		float scrMin, scrMax;
		scroll->GetRange( &scrMin, &scrMax );
		if( scroll->Value() != scrMax )
			doAutoScroll = false;
	}	

	// allocate some room for the text_run_array
	text_run_array* styles = (text_run_array*)malloc( sizeof(text_run_array) +
							(sizeof(text_run) * (number_of_runs - 1)));							

	// fill in the individual text_runs
	styles->count = number_of_runs;
	for( int32 i = 0; i < number_of_runs; ++i )
		styles->runs[i] = insertStyles[i];
		
	// Get the offset of the last line
	lineCount = CountLines();
	lastOffset = OffsetAt( lineCount );

	// Add the silly thing
	Insert( lastOffset, insertText, strlen(insertText), styles );
	
	// do the autoscroll, if needed
	if( doAutoScroll ) {
		lineCount = CountLines();
		lastOffset = OffsetAt( lineCount );
		ScrollToOffset( lastOffset );	
	}
		
	// Prepare to start over
	Empty = false;
	ClearFontStates();
	free( styles );
}
Beispiel #26
0
void
MemoryView::_RecalcScrollBars()
{
	float max = 0.0;
	BScrollBar *scrollBar = ScrollBar(B_VERTICAL);
	if (fTargetBlock != NULL) {
		int32 hexDigits = _GetHexDigitsPerBlock();
		int32 sizeFactor = 1 + hexDigits;
		_RecalcBounds();

		float hexWidth = fHexRight - fHexLeft;
		int32 nybblesPerLine = int32(hexWidth / fCharWidth);
		fHexBlocksPerLine = 0;
		fTextCharsPerLine = 0;
		if (fHexMode != HexModeNone) {
			fHexBlocksPerLine = nybblesPerLine / sizeFactor;
			fHexBlocksPerLine &= ~1;
			fHexRight = fHexLeft + (fHexBlocksPerLine * sizeFactor
				* fCharWidth);
			if (fTextMode != TextModeNone)
				fTextCharsPerLine = fHexBlocksPerLine * hexDigits / 2;
		} else if (fTextMode != TextModeNone)
			fTextCharsPerLine = int32((fTextRight - fTextLeft) / fCharWidth);
		int32 lineCount = 0;
		float totalHeight = 0.0;
		if (fHexBlocksPerLine > 0) {
			lineCount = fTargetBlock->Size() / (fHexBlocksPerLine
					* hexDigits / 2);
		} else if (fTextCharsPerLine > 0)
			lineCount = fTargetBlock->Size() / fTextCharsPerLine;

		totalHeight = lineCount * fLineHeight;
		if (totalHeight > 0.0) {
			BRect bounds = Bounds();
			max = totalHeight - bounds.Height();
			scrollBar->SetProportion(bounds.Height() / totalHeight);
			scrollBar->SetSteps(fLineHeight, bounds.Height());
		}
	}
	scrollBar->SetRange(0.0, max);
}
void
BasicPreviewView::_ScrollUpBigStep(void)
{
    int value1 = ScrollBar(B_VERTICAL)->Value() - Bounds().Height();
    ScrollBar(B_VERTICAL)->SetValue(value1);
}
Beispiel #28
0
void WrappingTextView::KeyDown(const char *bytes, int32 numBytes) 
{ 
	if (IsEditable() && numBytes==1) {
		m_last_key_was_del = (bytes[0]==B_DELETE);
		switch( bytes[0]) {
			case B_RIGHT_ARROW: {
				// implement word-wise movement:
				int32 mods = Window()->CurrentMessage()->FindInt32("modifiers");
				if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) {
					int32 len=TextLength();
					int32 startPos, endPos;
					GetSelection( &startPos, &endPos);
					if (endPos==len)
						break;
					if (startPos==endPos && (mods & B_SHIFT_KEY))
						m_selection_start=B_RIGHT_ARROW;
					int32 wordStart, wordEnd;
					if (mods & B_SHIFT_KEY && m_selection_start==B_LEFT_ARROW) {
						do {
							FindWord( startPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( ++startPos < len);
						Select( MIN(endPos, wordEnd), endPos);
					} else {
						do {
							FindWord( endPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( ++endPos < len);
						if (mods & B_SHIFT_KEY) {
							Select( startPos, wordEnd);
						} else
							Select( wordEnd, wordEnd);
					}
					ScrollToSelection();
				} else
					inherited::KeyDown( bytes, numBytes);
				break;
			}
			case B_LEFT_ARROW: {
				// implement word-wise movement:
				int32 mods = Window()->CurrentMessage()->FindInt32("modifiers");
				if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) {
					int32 startPos, endPos;
					GetSelection( &startPos, &endPos);
					if (!startPos)
						break;
					if (startPos==endPos && (mods & B_SHIFT_KEY))
						m_selection_start=B_LEFT_ARROW;
					int32 wordStart, wordEnd;
					if (mods & B_SHIFT_KEY && m_selection_start==B_RIGHT_ARROW) {
						--endPos;
						do {
							FindWord( endPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( --endPos > 0);
						Select( startPos, MAX( startPos, wordStart));
					} else {
						--startPos;
						do {
							FindWord( startPos, &wordStart, &wordEnd);
							if (wordEnd > wordStart+1)
								break;
							if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ')
								break;
						} while( --startPos > 0);
						if (mods & B_SHIFT_KEY)
							Select( wordStart, endPos);
						else
							Select( wordStart, wordStart);
					}
					ScrollToSelection();
				} else
					inherited::KeyDown( bytes, numBytes);
				break;
			}
			default:
				inherited::KeyDown( bytes, numBytes);
				break;
		}
	} else if ( numBytes == 1 ) {
		// in read-only mode, we use cursor-keys to move scrollbar, and
		// we remap HOME / END to the vertical scrollbar (not the horizontal,
		// which is default).
		switch( bytes[0]) {
			case B_PAGE_UP:
			case B_PAGE_DOWN:
			case B_UP_ARROW:
			case B_DOWN_ARROW:
			case B_HOME: 
			case B_END: {
				// move vertical scrollbar:
				float min, max, smallStep, bigStep, value;
				BScrollBar* bar = ScrollBar( B_VERTICAL);
				if (!bar) 	return;
				bar->GetRange( &min, &max);
				bar->GetSteps( &smallStep, &bigStep);
				value = bar->Value();
				if (bytes[0] == B_UP_ARROW) {
					value = MAX( value-smallStep, min);
				} else if (bytes[0] == B_DOWN_ARROW) {
					value = MIN( value+smallStep, max);
				} else if (bytes[0] == B_PAGE_UP) {
					value = MAX( value-bigStep, min);
				} else if (bytes[0] == B_PAGE_DOWN) {
					value = MIN( value+bigStep, max);
				} else if (bytes[0] == B_HOME) {
					value = min;
				} else if (bytes[0] == B_END) {
					value = max;
				}
				bar->SetValue( value);
				break;
			}
			default:
				BTextView::KeyDown( bytes, numBytes);
				break;
		}
	} else
		inherited::KeyDown( bytes, numBytes);
}
Beispiel #29
0
// MouseMoved -- Handles a lot of the important stuff
//               and user input.
void PictureViewer::MouseMoved(BPoint a, uint32 m, const BMessage* msg) {
   if (mouseDown == false) return;

   uint32 buttons;
   int32 action = 0;
   BPoint ad;
   GetMouse(&ad, &buttons );
  
   if ( buttons == B_PRIMARY_MOUSE_BUTTON )  action = setup->LeftMouseAction();
   if ( buttons == B_SECONDARY_MOUSE_BUTTON )  action = setup->RightMouseAction();
   if ( buttons == B_TERTIARY_MOUSE_BUTTON )  action = setup->MiddleMouseAction();
   
   if ( action == P_SCROLLING ) {
         float toScrollX = -(ad.x - oldMousePos.x);
         float toScrollY = -(ad.y - oldMousePos.y);
         float newX = ScrollBar( B_HORIZONTAL ) -> Value() + toScrollX;
         float newY = ScrollBar( B_VERTICAL   ) -> Value() + toScrollY;
         float maxX, minX;
         float maxY, minY;
         ScrollBar( B_HORIZONTAL ) ->GetRange( &minX, &maxX );
         ScrollBar( B_VERTICAL  ) ->GetRange( &minY, &maxY );
         if ( newX < 0 ) newX = 0;
         if ( newY < 0 ) newY = 0;
         if ( newX > maxX) newX = maxX;
         if ( newY > maxY) newY = maxY;
         ScrollTo( newX, newY );
         return;
   }
   
   if ( action == P_CLIPPING ) {
         DrawClipping();
         clippingRegion.right = ad.x;
         clippingRegion.bottom = ad.y;
         DrawClipping();
         return;
   }

   if ( action == P_DRAGGING ) 
      if (thePic != NULL) {
          BBitmap *dragImage;
          BMessage *msg;
          bool negotiated = setup->DragMode();
           
          // here comes the CTRL keyboard modifier
          if ( (modifiers() & B_CONTROL_KEY) == B_CONTROL_KEY ) negotiated = ! negotiated;
          //  and now it's finished.
       
          if (negotiated) {
            setup->SetNegotiationMessage(   ((PeekApp*)be_app)->SetupNegotiationMessage(setup->DragAction())      );
            msg = new BMessage (*setup->NegotiationMessage());
            BMimeType k("image");          
            dragImage = new BBitmap(BRect(0,0,31,31),B_CMAP8);
            msg->AddString("source","Peek");
            if (k.GetIcon(dragImage,B_LARGE_ICON) == B_OK) DragMessage(msg,dragImage, B_OP_ALPHA, BPoint(16,16));
            delete msg;
          } else {
             msg = new BMessage(B_SIMPLE_DATA);
             msg->AddRef("refs",theRef);
      
             if (setup->DragAction() != 0) msg->AddInt32("be:actions",setup->DragAction() );
           
             BMimeType k("image");          
             dragImage = new BBitmap(BRect(0,0,31,31),B_CMAP8);
             msg->AddString("source","Peek");
             if (k.GetIcon(dragImage,B_LARGE_ICON) == B_OK) DragMessage(msg,dragImage, B_OP_ALPHA, BPoint(16,16));
            delete msg;
          }  
   }
   
   
}