void wxCustomHeightListCtrl::AdjustView() { int posx, posy; GetViewStart(&posx, &posy); #ifdef __WXGTK__ // When decreasing scrollbar range, wxGTK does not seem to adjust child position // if viewport gets moved wxPoint old_view; GetViewStart(&old_view.x, &old_view.y); #endif SetScrollbars(0, m_lineHeight, 0, m_rows.size(), 0, posy); #ifdef __WXGTK__ wxPoint new_view; GetViewStart(&new_view.x, &new_view.y); int delta_y = m_lineHeight *(old_view.y - new_view.y); if (delta_y) { wxWindowList::compatibility_iterator iter = GetChildren().GetFirst(); while (iter) { wxWindow* child = iter->GetData(); wxPoint pos = child->GetPosition(); pos.y -= delta_y; child->SetPosition(pos); iter = iter->GetNext(); } } #endif }
void wxCustomHeightListCtrl::SetLineCount(int count) { if (count < m_lineCount) { std::set<int> selectedLines = m_selectedLines; m_selectedLines.clear(); for (std::set<int>::const_iterator iter = selectedLines.begin(); iter != selectedLines.end(); iter++) if (*iter < count) m_selectedLines.insert(*iter); } m_lineCount = count; if (m_focusedLine >= count) m_focusedLine = -1; int posx, posy; GetViewStart(&posx, &posy); #ifdef __WXGTK__ // When decreasing scrollbar range, wxGTK does not seem to adjust child position // if viewport gets moved wxPoint old_view; GetViewStart(&old_view.x, &old_view.y); #endif SetScrollbars(0, m_lineHeight, 0, m_lineCount, 0, posy); #ifdef __WXGTK__ wxPoint new_view; GetViewStart(&new_view.x, &new_view.y); int delta_y = m_lineHeight *(old_view.y - new_view.y); if (delta_y) { wxWindowList::compatibility_iterator iter = GetChildren().GetFirst(); while (iter) { wxWindow* child = iter->GetData(); wxPoint pos = child->GetPosition(); pos.y -= delta_y; child->SetPosition(pos); iter = iter->GetNext(); } } #endif Refresh(); }
int SpectDisplay::ScrollToFrame(int frame, int centre) {//=================================================== int scrollx, scrolly; int x, y; int scrolled = 0; GetClientSize(&x,&y); GetViewStart(&scrollx,&scrolly); scrolly *= SCROLLUNITS; if(centre) { Scroll(-1, int(((frame+0.5)*FRAME_HEIGHT*zoomy - y/2) /SCROLLUNITS)); return(1); } if(scrolly > frame * FRAME_HEIGHT * zoomy) { Scroll(-1, int((frame * FRAME_HEIGHT * zoomy) / SCROLLUNITS)); scrolled = 1; } else { if(((frame+1) * FRAME_HEIGHT * zoomy) > (scrolly + y)) { Scroll(-1, int(((frame+1)*FRAME_HEIGHT*zoomy - y) /SCROLLUNITS)+1); scrolled = 1; } } return(scrolled); } // end of SpectDisplay::ScrollToFrame
void CTimeBarDataViewCtrl::OnScroll(wxScrollWinEvent& /*event*/) { if (m_pSyncWnd != NULL) { m_pSyncWnd->Scroll(GetViewStart()); } }
/** * 現在開いているHTMLのスクロール位置を取得する */ void ThreadContentWindow::GetHtmlWindowScrollPos(wxPoint* p) { // 現在位置の取得 int x, y; GetViewStart(&x, &y); p->x = x; p->y = y; }
void BrushIconBox::EnsureVisible(BrushButton* btn) { int windowSizeX, windowSizeY; GetVirtualSize(&windowSizeX, &windowSizeY); int scrollUnitX; int scrollUnitY; GetScrollPixelsPerUnit(&scrollUnitX, &scrollUnitY); wxRect rect = btn->GetRect(); int y; CalcUnscrolledPosition(0, rect.y, nullptr, &y); int maxScrollPos = windowSizeY / scrollUnitY; int scrollPosY = std::min(maxScrollPos, (y / scrollUnitY)); int startScrollPosY; GetViewStart(nullptr, &startScrollPosY); int clientSizeX, clientSizeY; GetClientSize(&clientSizeX, &clientSizeY); int endScrollPosY = startScrollPosY + clientSizeY / scrollUnitY; if(scrollPosY < startScrollPosY || scrollPosY > endScrollPosY){ //only scroll if the button isnt visible Scroll(-1, scrollPosY); } }
/// Set up scrollbars, e.g. after a resize void InstanceCtrl::SetupScrollbars() { if (m_freezeCount) return; if (GetCount() == 0) { SetScrollbars(0, 0, 0, 0, 0, 0); return; } int pixelsPerUnit = 10; wxSize clientSize = GetClientSize(); int maxHeight = GetTotalHeight(); int unitsY = maxHeight / pixelsPerUnit; int startX, startY; GetViewStart(& startX, & startY); int maxtop = maxHeight - clientSize.y; if (maxtop % pixelsPerUnit) { maxtop = ((maxtop / pixelsPerUnit) + 1) * pixelsPerUnit; } int maxPositionY = (wxMax(maxtop , 0)) / pixelsPerUnit; // Move to previous scroll position if // possible SetScrollbars(0, pixelsPerUnit, 0, unitsY, 0, wxMin(maxPositionY, startY)); }
bool wxBasePlayerGameListCtrl::OnDragOver(wxCoord x, wxCoord y, const Player&) { // If they are within a few pixels from the top or bottom, scroll the // control. wxSize size = GetSize(); wxInt32 range = GetScrollRange(wxVERTICAL); wxInt32 pos = GetScrollPos(wxVERTICAL); wxInt32 vX, vY; GetViewStart(&vX, &vY); if( (4 > y) && (0 < pos)) { Scroll(vX, --vY); } else if( (size.y - 8 <= y) && (range - 1 > pos)) { Scroll(vX, ++vY); } else { wxInt32 index = HitTest(wxPoint(x, y)); // Also clears the selection if they are not over anything. SetSelectedItem(index); } return true; }
/// Get the overall rect of the given item bool InstanceCtrl::GetItemRect( VisualCoord item, wxRect& rect, bool view_relative ) { if (item.groupIndex < GetCount()) { int row, col; if (!GetRowCol(item, row, col)) return false; GroupVisual & gv = m_groups[item.groupIndex]; wxSize bsz = GetWindowBorderSize(); int x = col * (m_itemWidth + m_spacing) + m_spacing + bsz.GetWidth() / 2; int y = gv.y_position + gv.row_ys[row] + m_spacing; if (view_relative) { int startX, startY; int xppu, yppu; GetScrollPixelsPerUnit(& xppu, & yppu); GetViewStart(& startX, & startY); x = x - startX * xppu; y = y - startY * yppu; } rect.x = x; rect.y = y; rect.width = m_itemWidth; rect.height = GetItemHeight(item); return true; } return false; }
void InstanceCtrl::EnsureRectVisible ( wxRect rect ) { int ppuX, ppuY; GetScrollPixelsPerUnit(& ppuX, & ppuY); if (ppuY == 0) return; int startX, startY; GetViewStart(& startX, & startY); startX = 0; startY = startY * ppuY; int sx, sy; GetVirtualSize(& sx, & sy); sx = 0; if (ppuY != 0) sy = sy / ppuY; wxSize clientSize = GetClientSize(); if ((rect.y + rect.height) > (clientSize.y + startY)) { // Make it scroll so this item is at the bottom // of the window int y = rect.y - (clientSize.y - rect.height - m_spacing) ; SetScrollbars(ppuX, ppuY, sx, sy, 0, (int)(0.5 + y / ppuY)); } else if (rect.y < startY) { // Make it scroll so this item is at the top // of the window int y = rect.y ; SetScrollbars(ppuX, ppuY, sx, sy, 0, (int)(0.5 + y / ppuY)); } }
void WinEDA_DrawPanel::SetBoundaryBox(void) /******************************************/ { BASE_SCREEN * Screen = GetScreen();; wxPoint org; int ii, jj; Screen->m_SizeVisu = GetClientSize(); GetViewStart(&org.x, &org.y); GetScrollPixelsPerUnit(&ii, &jj); org.x *= ii; org.y *= jj; Screen->m_StartVisu = org; m_ClipBox.SetOrigin(org); m_ClipBox.SetSize(GetClientSize()); #ifdef WX_ZOOM m_ClipBox.m_Pos.x *= GetZoom(); m_ClipBox.m_Pos.y *= GetZoom(); m_ClipBox.m_Size.x *= GetZoom(); m_ClipBox.m_Size.y *= GetZoom(); #else m_ClipBox.m_Pos.x -= GetScreen()->m_StartVisu.x; m_ClipBox.m_Pos.y -= GetScreen()->m_StartVisu.y; #endif m_ScrollButt_unit = MIN( Screen->m_SizeVisu.x, Screen->m_SizeVisu.y ) / 4; if ( m_ScrollButt_unit < 2 ) m_ScrollButt_unit = 2; Screen->m_ScrollbarPos.x = GetScrollPos(wxHORIZONTAL); Screen->m_ScrollbarPos.y = GetScrollPos(wxVERTICAL); }
void GraphCanvas::OnMotion(wxMouseEvent& evt) { m_MouseX = evt.GetX() - m_BorderSize; m_MouseY = evt.GetY() - m_BorderSize; MouseToCanvas(m_MouseX, m_MouseY, &m_CanvasX, &m_CanvasY); if (evt.Dragging() && evt.LeftIsDown()) { int dx = m_LeftX - m_MouseX; int dy = m_LeftY - m_MouseY; if (m_HasDragged || abs(dx) > 5 || abs(dy) > 5) { if (!m_HasDragged) { m_HasDragged = true; SetCursor(m_HandCursor); } m_LeftX = m_MouseX; m_LeftY = m_MouseY; int viewx, viewy; GetViewStart(&viewx, &viewy); Scroll(viewx + dx, viewy + dy); } } else { //SetCursor(*wxSTANDARD_CURSOR); } evt.Skip(); }
/***************************************************** ** ** BasicWidget --- OnPaint ** ******************************************************/ void BasicWidget::OnPaint( wxPaintEvent &event ) { int vx, vy; wxPaintDC context( this ); PrepareDC( context ); wxRegionIterator upd( GetUpdateRegion()); if ( upd ) refreshRect = upd.GetRect(); while ( ++upd ) { refreshRect.Union( upd.GetRect() ); } GetViewStart( &vx, &vy ); if ( vx || vy ) { refreshRect.x += vx; refreshRect.y += vy; } assert( painter == 0 ); painter = new DcPainter( &context ); doPaint(); delete painter; painter = 0; }
/* * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line) * noUnitsX/noUnitsY: : no. units per scrollbar */ void wxScrolledWindow::SetScrollbars( int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int xPos, int yPos, bool noRefresh ) { int xs, ys; GetViewStart (& xs, & ys); int old_x = m_xScrollPixelsPerLine * xs; int old_y = m_yScrollPixelsPerLine * ys; m_xScrollPixelsPerLine = pixelsPerUnitX; m_yScrollPixelsPerLine = pixelsPerUnitY; m_hAdjust->value = m_xScrollPosition = xPos; m_vAdjust->value = m_yScrollPosition = yPos; // Setting hints here should arguably be deprecated, but without it // a sizer might override this manual scrollbar setting in old code. // m_targetWindow->SetVirtualSizeHints( noUnitsX * pixelsPerUnitX, noUnitsY * pixelsPerUnitY ); int w = noUnitsX * pixelsPerUnitX; int h = noUnitsY * pixelsPerUnitY; m_targetWindow->SetVirtualSize( w ? w : wxDefaultCoord, h ? h : wxDefaultCoord); if (!noRefresh) { int new_x = m_xScrollPixelsPerLine * m_xScrollPosition; int new_y = m_yScrollPixelsPerLine * m_yScrollPosition; m_targetWindow->ScrollWindow( old_x - new_x, old_y - new_y ); } }
virtual void OnLeftDown(wxMouseEvent& event) { GetViewStart(&m_viewX, &m_viewY); m_startPos = event.GetPosition(); SetCursor(m_handClosedCursor); m_handToolActive = true; }
void wxListBox::DoEnsureVisible(int n) { if ( !m_showScrollbarY ) { // nothing to do - everything is shown anyhow return; } int first; GetViewStart(0, &first); if ( first > n ) { // we need to scroll upwards, so make the current item appear on top // of the shown range Scroll(0, n); } else { int last = first + GetClientSize().y / GetLineHeight() - 1; if ( last < n ) { // scroll down: the current item appears at the bottom of the // range Scroll(0, n - (last - first)); } } }
hdMultiPosRect hdDrawingView::getVisibleArea() { int x, y, w, h; GetViewStart(&x, &y); GetClientSize(&w, &h); hdMultiPosRect visibleArea(x, y, w, h); return visibleArea; }
void ScrollZoomCanvas::ChangeOffset(wxPoint deltaOffset) { mOffset += deltaOffset; Scroll(-mOffset); wxPoint start = GetViewStart(); mOffset = -start - mOrigin; }
/** * リサイズ時のイベント */ void ThreadContentWindow::OnSize(wxSizeEvent& event) { // 現在位置の取得 int x, y; GetViewStart(&x, &y); wxHtmlWindow::OnSize(event); Scroll(x, y); event.Skip(false); }
/***************************************************** ** ** MyGrid --- OnMouseEvent ** ******************************************************/ void MyGrid::OnMouseEvent( wxMouseEvent &event ) { int x, y; const int offset = 3; GetViewStart( &x, &y ); if ( event.GetWheelRotation() < 0 ) y += offset; else y -= offset; Scroll( x, y ); }
wxRect wxImageBox::getPaintRect() { wxSize size = GetClientSize(); wxRect paintRect(0, 0, size.GetWidth(), size.GetHeight()); GetViewStart(&paintRect.x, &paintRect.y); int xu,yu; GetScrollPixelsPerUnit(&xu, &yu); paintRect.x *= xu; paintRect.y *= yu; return paintRect; }
void CtrlRegisterList::ensureVisible(int index) { //scroll vertically to keep a logical position visible int x, y; GetViewStart(&x, &y); int visibleOffset = floor(float(GetClientSize().y) / rowHeight) - 1; if (index < y) Scroll(x, index); else if (index > y + visibleOffset) Scroll(x, index - visibleOffset); }
void wxScrolledWindow::DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const { int xs, ys; GetViewStart (& xs, & ys); if ( xx ) *xx = x + xs * m_xScrollPixelsPerLine; if ( yy ) *yy = y + ys * m_yScrollPixelsPerLine; }
void wxCustomHeightListCtrl::SetLineHeight(int height) { m_lineHeight = height; int posx, posy; GetViewStart(&posx, &posy); SetScrollbars(0, m_lineHeight, 0, m_rows.size(), 0, posy); Refresh(); }
void wxLayoutWindow::ScrollToCursor() { //is always needed to make sure we know where the cursor is //if(IsDirty()) //RequestUpdate(m_llist->GetUpdateRect()); ResizeScrollbars(); int x0,y0,x1,y1, dx, dy; // Calculate where the top of the visible area is: GetViewStart(&x0,&y0); GetScrollPixelsPerUnit(&dx, &dy); x0 *= dx; y0 *= dy; WXLO_DEBUG(("ScrollToCursor: GetViewStart is %d/%d", x0, y0)); // Get the size of the visible window: GetClientSize(&x1, &y1); // Make sure that the scrollbars are at a position so that the cursor is // visible if we are editing WXLO_DEBUG(("m_ScrollToCursor = %d", (int) m_ScrollToCursor)); wxPoint cc = m_llist->GetCursorScreenPos(); // the cursor should be completely visible in both directions wxPoint cs(m_llist->GetCursorSize()); int nx = -1, ny = -1; if ( cc.x < x0 || cc.x >= x0 + x1 - cs.x ) { nx = cc.x - x1/2; if ( nx < 0 ) nx = 0; } if ( cc.y < y0 || cc.y >= y0 + y1 - cs.y ) { ny = cc.y - y1/2; if ( ny < 0) ny = 0; } if( nx != -1 || ny != -1 ) { // set new view start Scroll(nx == -1 ? -1 : (nx+dx-1)/dx, ny == -1 ? -1 : (ny+dy-1)/dy); // avoid recursion m_ScrollToCursor = false; RequestUpdate(); } }
void Canvas::set_zoom(int zoom, wxPoint center) { { /* Overpaint old image */ wxClientDC dc(this); wxPen pen( *wxLIGHT_GREY ); wxBrush brush( *wxLIGHT_GREY ); dc.SetPen( pen ); dc.SetBrush( brush ); dc.DrawRectangle( canvas_coords( wxRect(0, 0, contents->GetWidth(), contents->GetHeight())) ); } if ( center == wxDefaultPosition ) { int xl, yl, xs, ys, xr, yr; GetViewStart( &xl, &yl ); GetScrollPixelsPerUnit( &xr, &yr ); GetClientSize( &xs, &ys ); center.x = xl*xr + xs / 2; center.y = yl*yr + ys / 2; center = image_coords( wxRect( center, wxSize(1,1) ) ).GetTopLeft(); } if ( zoom < 0 ) { zoom_out_level = -zoom+1; zoom_in_level = 1; } else { zoom_out_level = 1; zoom_in_level = zoom+1; } if ( zcl ) zcl->zoom_changed( zoom ); wxSize new_size( contents->GetWidth(), contents->GetHeight() ); SetVirtualSize( canvas_coords( new_size ).GetSize() ); int xr, yr; GetScrollPixelsPerUnit( &xr, &yr ); wxRect viewport = get_visible_region(); /* Transform center to new scroll coordinates. */ wxPoint top_left = viewport.CenterIn( canvas_coords( wxRect( center, wxSize(1,1) ) ) ).GetTopLeft(); Scroll( top_left.x / xr, top_left.y / yr ); wxClientDC dc(this); DoPrepareDC( dc ); wxRect canvas_region = get_visible_region(); wxBitmap bitmap = zoomed_bitmap_for_canvas_region( canvas_region ); dc.DrawBitmap( bitmap, canvas_region.GetTopLeft() ); }
void BitmapViewer::OnMouseDown(wxMouseEvent& event) { wxPoint view_origin; GetViewStart(&view_origin.x, &view_origin.y); const wxPoint pos = event.GetPosition(); m_draggingPage = true; m_draggingLastMousePos = pos; CaptureMouse(); }
// Returns the current scroll position wxPoint wxShapeCanvas::GetCurrentPixelScrollPosition() { int pixelsPerUnitX, pixelsPerUnitY; GetScrollPixelsPerUnit(& pixelsPerUnitX, & pixelsPerUnitY); int posX, posY; GetViewStart(& posX, & posY); wxPoint pt(pixelsPerUnitX * posX, pixelsPerUnitY * posY); return pt; }
void wxListBox::UpdateScrollbars() { wxSize size = GetClientSize(); // is our height enough to show all items? int nLines = GetCount(); wxCoord lineHeight = GetLineHeight(); bool showScrollbarY = nLines*lineHeight > size.y; // check the width too if required wxCoord charWidth, maxWidth; bool showScrollbarX; if ( HasHorzScrollbar() ) { charWidth = GetCharWidth(); maxWidth = GetMaxWidth(); showScrollbarX = maxWidth > size.x; } else // never show it { charWidth = maxWidth = 0; showScrollbarX = false; } // what should be the scrollbar range now? int scrollRangeX = showScrollbarX ? (maxWidth + charWidth - 1) / charWidth + 2 // FIXME : 0; int scrollRangeY = showScrollbarY ? nLines + (size.y % lineHeight + lineHeight - 1) / lineHeight : 0; // reset scrollbars if something changed: either the visibility status // or the range of a scrollbar which is shown if ( (showScrollbarY != m_showScrollbarY) || (showScrollbarX != m_showScrollbarX) || (showScrollbarY && (scrollRangeY != m_scrollRangeY)) || (showScrollbarX && (scrollRangeX != m_scrollRangeX)) ) { int x, y; GetViewStart(&x, &y); SetScrollbars(charWidth, lineHeight, scrollRangeX, scrollRangeY, x, y); m_showScrollbarX = showScrollbarX; m_showScrollbarY = showScrollbarY; m_scrollRangeX = scrollRangeX; m_scrollRangeY = scrollRangeY; } }
/************************************************************** *** ** BasicWidget --- OnMouseMotion *** ***************************************************************/ void BasicWidget::OnMouseMotion( wxMouseEvent &event ) { int dx, dy, vx, vy; if ( dragMode ) { dx = event.m_x - mousex; dy = event.m_y - mousey; GetViewStart( &vx, &vy ); Scroll( vx - dx / scrollx, vy - dy / scrolly ); } mousex = event.m_x; mousey = event.m_y; }