From cf3da716f65a419cddc25bdb70ccd7cbe4a3afa7 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 14 Jan 2000 20:29:01 +0000 Subject: [PATCH] image to bitmap rewrite, ViewStart() renamed GetViewStart() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5392 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/outptstr.tex | 2 +- docs/latex/wx/scrolwin.tex | 4 +- docs/latex/wx/window.tex | 2 +- include/wx/generic/scrolwin.h | 5 ++- samples/image/image.cpp | 8 +++- src/common/image.cpp | 85 ++++++++++++++++++----------------- src/generic/listctrl.cpp | 41 +++++++++-------- src/generic/scrolwin.cpp | 37 +++++++-------- 8 files changed, 95 insertions(+), 89 deletions(-) diff --git a/docs/latex/wx/outptstr.tex b/docs/latex/wx/outptstr.tex index 6fec17cdfe..02da47fd2d 100644 --- a/docs/latex/wx/outptstr.tex +++ b/docs/latex/wx/outptstr.tex @@ -72,7 +72,7 @@ by one of the two streams. % ----------------------------------------------------------------------------- % wxCountingOutputStream % ----------------------------------------------------------------------------- -\section{\class{wxCountOutputStream}}\label{wxcountingoutputstream} +\section{\class{wxCountingOutputStream}}\label{wxcountingoutputstream} wxCountingOutputStream is specialized output stream which does not write any data anyway, instead it counts how many bytes would get written if this were a normal stream. This diff --git a/docs/latex/wx/scrolwin.tex b/docs/latex/wx/scrolwin.tex index ef24da24c9..1bdf47ea15 100644 --- a/docs/latex/wx/scrolwin.tex +++ b/docs/latex/wx/scrolwin.tex @@ -351,9 +351,9 @@ adjusting the scrollbars appropriately. Call this function to tell wxScrolledWindow to perform the actually scrolling on a different window (not on itself). -\membersection{wxScrolledWindow::ViewStart}\label{wxscrolledwindowviewstart} +\membersection{wxScrolledWindow::GetViewStart}\label{wxscrolledwindowgetviewstart} -\constfunc{void}{ViewStart}{\param{int* }{x}, \param{int* }{ y}} +\constfunc{void}{GetViewStart}{\param{int* }{x}, \param{int* }{ y}} Get the position at which the visible portion of the window starts. diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 98d2acabf5..d4774806bb 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -1405,7 +1405,7 @@ void MyWindow::OnPaint(wxPaintEvent\& event) // Find Out where the window is scrolled to int vbX,vbY; // Top left corner of client - ViewStart(&vbX,&vbY); + GetViewStart(&vbX,&vbY); int vX,vY,vW,vH; // Dimensions of client area in pixels wxRegionIterator upd(GetUpdateRegion()); // get the update rect list diff --git a/include/wx/generic/scrolwin.h b/include/wx/generic/scrolwin.h index 13c5a2d9f5..ce7a477fec 100644 --- a/include/wx/generic/scrolwin.h +++ b/include/wx/generic/scrolwin.h @@ -80,7 +80,10 @@ public: virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); // Get the view start - virtual void ViewStart(int *x, int *y) const; + virtual void GetViewStart(int *x, int *y) const; + // Compatibility + void ViewStart(int *x, int *y) const + { GetViewStart( x, y ); } // Actual size in pixels when scrolling is taken into account virtual void GetVirtualSize(int *x, int *y) const; diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 335f548f83..1e683274ad 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -115,8 +115,10 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, wxMemoryDC dc; dc.SelectObject( bitmap ); dc.SetBrush( wxBrush( "orange", wxSOLID ) ); - dc.SetPen( *wxWHITE_PEN ); + dc.SetPen( *wxBLACK_PEN ); dc.DrawRectangle( 0, 0, 100, 100 ); + dc.SetBrush( *wxWHITE_BRUSH ); + dc.DrawRectangle( 20, 20, 60, 60 ); dc.SelectObject( wxNullBitmap ); // try to find the directory with our images @@ -209,8 +211,10 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawText( "Drawn directly", 150, 10 ); dc.SetBrush( wxBrush( "orange", wxSOLID ) ); - dc.SetPen( *wxWHITE_PEN ); + dc.SetPen( *wxBLACK_PEN ); dc.DrawRectangle( 150, 30, 100, 100 ); + dc.SetBrush( *wxWHITE_BRUSH ); + dc.DrawRectangle( 170, 50, 60, 60 ); if (my_anti && my_anti->Ok()) dc.DrawBitmap( *my_anti, 280, 30 ); diff --git a/src/common/image.cpp b/src/common/image.cpp index 627e7ab6ad..dc5fdf6c48 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1634,19 +1634,36 @@ wxImage::wxImage( const wxBitmap &bitmap ) } int bpp = -1; + int red_shift_right = 0; + int green_shift_right = 0; + int blue_shift_right = 0; + int red_shift_left = 0; + int green_shift_left = 0; + int blue_shift_left = 0; + bool use_shift = FALSE; + if (bitmap.GetPixmap()) { GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() ); if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); bpp = visual->depth; - if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; + if (bpp == 16) bpp = visual->red_prec + visual->green_prec + visual->blue_prec; + red_shift_right = visual->red_shift; + red_shift_left = 8-visual->red_prec; + green_shift_right = visual->green_shift; + green_shift_left = 8-visual->green_prec; + blue_shift_right = visual->blue_shift; + blue_shift_left = 8-visual->blue_prec; + + use_shift = (visual->type == GDK_VISUAL_TRUE_COLOR) || (visual->type == GDK_VISUAL_DIRECT_COLOR); } if (bitmap.GetBitmap()) { bpp = 1; } + GdkColormap *cmap = gtk_widget_get_default_colormap(); long pos = 0; @@ -1654,54 +1671,38 @@ wxImage::wxImage( const wxBitmap &bitmap ) { for (int i = 0; i < bitmap.GetWidth(); i++) { - wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j ); - if (bpp == 1) - { - if (pixel == 0) - { - data[pos] = 0; + wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j ); + if (bpp == 1) + { + if (pixel == 0) + { + data[pos] = 0; data[pos+1] = 0; data[pos+2] = 0; - } - else - { - data[pos] = 255; + } + else + { + data[pos] = 255; data[pos+1] = 255; data[pos+2] = 255; - } - } else if (bpp <= 8) + } + } + else if (use_shift) { - data[pos] = cmap->colors[pixel].red >> 8; - data[pos+1] = cmap->colors[pixel].green >> 8; - data[pos+2] = cmap->colors[pixel].blue >> 8; - } else if (bpp == 15) + data[pos] = (pixel >> red_shift_right) << red_shift_left; + data[pos+1] = (pixel >> green_shift_right) << green_shift_left; + data[pos+2] = (pixel >> blue_shift_right) << blue_shift_left; + } + else if (cmap->colors) { -#if (wxBYTE_ORDER == wxBIG_ENDIAN) - // ? -#endif - data[pos] = (pixel >> 7) & 0xf8; - data[pos+1] = (pixel >> 2) & 0xf8; - data[pos+2] = (pixel << 3) & 0xf8; - } else if (bpp == 16) - { -#if (wxBYTE_ORDER == wxBIG_ENDIAN) - // ? -#endif - data[pos] = (pixel >> 8) & 0xf8; - data[pos+1] = (pixel >> 3) & 0xfc; - data[pos+2] = (pixel << 3) & 0xf8; - } else + data[pos] = cmap->colors[pixel].red >> 8; + data[pos+1] = cmap->colors[pixel].green >> 8; + data[pos+2] = cmap->colors[pixel].blue >> 8; + } + else { -#if (wxBYTE_ORDER == wxBIG_ENDIAN) - data[pos] = (pixel) & 0xff; // Red - data[pos+1] = (pixel >> 8) & 0xff; // Green - data[pos+2] = (pixel >> 16) & 0xff; // Blue -#else - data[pos] = (pixel >> 16) & 0xff; - data[pos+1] = (pixel >> 8) & 0xff; - data[pos+2] = pixel & 0xff; -#endif - } + wxFAIL_MSG( wxT("Image conversion failed. Unknown visual type.") ); + } if (gdk_image_mask) { diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 98060e7927..43b025202c 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -1530,29 +1530,32 @@ void wxListMainWindow::MoveToFocus() { if (!m_current) return; - int x = 0; - int y = 0; - int w = 0; - int h = 0; - m_current->GetExtent( x, y, w, h ); - - int w_p = 0; - int h_p = 0; - GetClientSize( &w_p, &h_p ); + int item_x = 0; + int item_y = 0; + int item_w = 0; + int item_h = 0; + m_current->GetExtent( item_x, item_y, item_w, item_h ); + + int client_w = 0; + int client_h = 0; + GetClientSize( &client_w, &client_h ); + + int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL ); + int view_y = m_yScroll*GetScrollPos( wxVERTICAL ); if (m_mode & wxLC_REPORT) { - int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); - if ((y > y_s) && (y+h < y_s+h_p)) return; - if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); } - if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); } + if (item_y-5 < view_y ) + Scroll( -1, (item_y-5)/m_yScroll ); + if (item_y+item_h+5 > view_y+client_h) + Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll ); } else { - int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); - if ((x > x_s) && (x+w < x_s+w_p)) return; - if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); } - if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); } + if (item_x-view_x < 5) + Scroll( (item_x-5)/m_xScroll, -1 ); + if (item_x+item_w-5 > view_x+client_w) + Scroll( (item_x+item_w-client_w+15)/m_xScroll, -1 ); } } @@ -1561,12 +1564,12 @@ void wxListMainWindow::OnArrowChar( wxListLineData *newCurrent, bool shiftDown ) if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE ); wxListLineData *oldCurrent = m_current; m_current = newCurrent; - MoveToFocus(); if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); RefreshLine( m_current ); RefreshLine( oldCurrent ); FocusLine( m_current ); UnfocusLine( oldCurrent ); + MoveToFocus(); } void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) @@ -1722,11 +1725,11 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) m_current->ReverseHilight(); wxNode *node = m_lines.Member( m_current )->Next(); if (node) m_current = (wxListLineData*)node->Data(); - MoveToFocus(); RefreshLine( oldCurrent ); RefreshLine( m_current ); UnfocusLine( oldCurrent ); FocusLine( m_current ); + MoveToFocus(); } break; } diff --git a/src/generic/scrolwin.cpp b/src/generic/scrolwin.cpp index 3ae5a62889..4e3db4bf49 100644 --- a/src/generic/scrolwin.cpp +++ b/src/generic/scrolwin.cpp @@ -351,14 +351,14 @@ void wxScrolledWindow::AdjustScrollbars() if (m_xScrollLines > 0) { - // Calculate page size i.e. number of scroll units you get on the - // current client window + // Calculate page size i.e. number of scroll units you get on the + // current client window int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); if (noPagePositions < 1) noPagePositions = 1; // Correct position if greater than extent of canvas minus - // the visible portion of it or if below zero - m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition); + // the visible portion of it or if below zero + m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition); m_xScrollPosition = wxMax( 0, m_xScrollPosition ); SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); @@ -373,13 +373,13 @@ void wxScrolledWindow::AdjustScrollbars() if (m_yScrollLines > 0) { - // Calculate page size i.e. number of scroll units you get on the - // current client window + // Calculate page size i.e. number of scroll units you get on the + // current client window int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); if (noPagePositions < 1) noPagePositions = 1; // Correct position if greater than extent of canvas minus - // the visible portion of it or if below zero + // the visible portion of it or if below zero m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); m_yScrollPosition = wxMax( 0, m_yScrollPosition ); @@ -495,46 +495,41 @@ void wxScrolledWindow::Scroll( int x_pos, int y_pos ) int old_x = m_xScrollPosition; m_xScrollPosition = x_pos; - // Calculate page size i.e. number of scroll units you get on the - // current client window + // Calculate page size i.e. number of scroll units you get on the + // current client window int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); if (noPagePositions < 1) noPagePositions = 1; // Correct position if greater than extent of canvas minus - // the visible portion of it or if below zero + // the visible portion of it or if below zero m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition ); m_xScrollPosition = wxMax( 0, m_xScrollPosition ); m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE ); - m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); + m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 ); } if (y_pos != -1) { int old_y = m_yScrollPosition; m_yScrollPosition = y_pos; - // Calculate page size i.e. number of scroll units you get on the - // current client window + // Calculate page size i.e. number of scroll units you get on the + // current client window int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); if (noPagePositions < 1) noPagePositions = 1; // Correct position if greater than extent of canvas minus - // the visible portion of it or if below zero + // the visible portion of it or if below zero m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition ); m_yScrollPosition = wxMax( 0, m_yScrollPosition ); m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE ); - m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); + m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine ); } -#ifdef __WXMSW__ -// ::UpdateWindow ((HWND) GetHWND()); -#else -// Refresh(); -#endif #ifdef __WXMAC__ m_targetWindow->MacUpdateImmediately() ; #endif @@ -555,7 +550,7 @@ void wxScrolledWindow::GetVirtualSize (int *x, int *y) const } // Where the current view starts from -void wxScrolledWindow::ViewStart (int *x, int *y) const +void wxScrolledWindow::GetViewStart (int *x, int *y) const { if ( x ) *x = m_xScrollPosition; -- 2.45.2