image to bitmap rewrite,

ViewStart() renamed GetViewStart()


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5392 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2000-01-14 20:29:01 +00:00
parent 27259273e4
commit cf3da716f6
8 changed files with 96 additions and 90 deletions

View File

@@ -72,7 +72,7 @@ by one of the two streams.
% ----------------------------------------------------------------------------- % -----------------------------------------------------------------------------
% wxCountingOutputStream % wxCountingOutputStream
% ----------------------------------------------------------------------------- % -----------------------------------------------------------------------------
\section{\class{wxCountOutputStream}}\label{wxcountingoutputstream} \section{\class{wxCountingOutputStream}}\label{wxcountingoutputstream}
wxCountingOutputStream is specialized output stream which does not write any data anyway, 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 instead it counts how many bytes would get written if this were a normal stream. This

View File

@@ -351,9 +351,9 @@ adjusting the scrollbars appropriately.
Call this function to tell wxScrolledWindow to perform the actually scrolling on Call this function to tell wxScrolledWindow to perform the actually scrolling on
a different window (not on itself). 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. Get the position at which the visible portion of the window starts.

View File

@@ -1405,7 +1405,7 @@ void MyWindow::OnPaint(wxPaintEvent\& event)
// Find Out where the window is scrolled to // Find Out where the window is scrolled to
int vbX,vbY; // Top left corner of client 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 int vX,vY,vW,vH; // Dimensions of client area in pixels
wxRegionIterator upd(GetUpdateRegion()); // get the update rect list wxRegionIterator upd(GetUpdateRegion()); // get the update rect list

View File

@@ -80,7 +80,10 @@ public:
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
// Get the view start // 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 // Actual size in pixels when scrolling is taken into account
virtual void GetVirtualSize(int *x, int *y) const; virtual void GetVirtualSize(int *x, int *y) const;

View File

@@ -115,8 +115,10 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
wxMemoryDC dc; wxMemoryDC dc;
dc.SelectObject( bitmap ); dc.SelectObject( bitmap );
dc.SetBrush( wxBrush( "orange", wxSOLID ) ); dc.SetBrush( wxBrush( "orange", wxSOLID ) );
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxBLACK_PEN );
dc.DrawRectangle( 0, 0, 100, 100 ); dc.DrawRectangle( 0, 0, 100, 100 );
dc.SetBrush( *wxWHITE_BRUSH );
dc.DrawRectangle( 20, 20, 60, 60 );
dc.SelectObject( wxNullBitmap ); dc.SelectObject( wxNullBitmap );
// try to find the directory with our images // 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.DrawText( "Drawn directly", 150, 10 );
dc.SetBrush( wxBrush( "orange", wxSOLID ) ); dc.SetBrush( wxBrush( "orange", wxSOLID ) );
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxBLACK_PEN );
dc.DrawRectangle( 150, 30, 100, 100 ); dc.DrawRectangle( 150, 30, 100, 100 );
dc.SetBrush( *wxWHITE_BRUSH );
dc.DrawRectangle( 170, 50, 60, 60 );
if (my_anti && my_anti->Ok()) if (my_anti && my_anti->Ok())
dc.DrawBitmap( *my_anti, 280, 30 ); dc.DrawBitmap( *my_anti, 280, 30 );

View File

@@ -1634,19 +1634,36 @@ wxImage::wxImage( const wxBitmap &bitmap )
} }
int bpp = -1; 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()) if (bitmap.GetPixmap())
{ {
GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() ); GdkVisual *visual = gdk_window_get_visual( bitmap.GetPixmap() );
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent ); if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
bpp = visual->depth; 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()) if (bitmap.GetBitmap())
{ {
bpp = 1; bpp = 1;
} }
GdkColormap *cmap = gtk_widget_get_default_colormap(); GdkColormap *cmap = gtk_widget_get_default_colormap();
long pos = 0; long pos = 0;
@@ -1654,54 +1671,38 @@ wxImage::wxImage( const wxBitmap &bitmap )
{ {
for (int i = 0; i < bitmap.GetWidth(); i++) for (int i = 0; i < bitmap.GetWidth(); i++)
{ {
wxInt32 pixel = gdk_image_get_pixel( gdk_image, i, j ); wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j );
if (bpp == 1) if (bpp == 1)
{ {
if (pixel == 0) if (pixel == 0)
{ {
data[pos] = 0; data[pos] = 0;
data[pos+1] = 0; data[pos+1] = 0;
data[pos+2] = 0; data[pos+2] = 0;
} }
else else
{ {
data[pos] = 255; data[pos] = 255;
data[pos+1] = 255; data[pos+1] = 255;
data[pos+2] = 255; data[pos+2] = 255;
} }
} else if (bpp <= 8)
{
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)
{
#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
{
#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
} }
else if (use_shift)
{
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)
{
data[pos] = cmap->colors[pixel].red >> 8;
data[pos+1] = cmap->colors[pixel].green >> 8;
data[pos+2] = cmap->colors[pixel].blue >> 8;
}
else
{
wxFAIL_MSG( wxT("Image conversion failed. Unknown visual type.") );
}
if (gdk_image_mask) if (gdk_image_mask)
{ {

View File

@@ -1530,29 +1530,32 @@ void wxListMainWindow::MoveToFocus()
{ {
if (!m_current) return; if (!m_current) return;
int x = 0; int item_x = 0;
int y = 0; int item_y = 0;
int w = 0; int item_w = 0;
int h = 0; int item_h = 0;
m_current->GetExtent( x, y, w, h ); m_current->GetExtent( item_x, item_y, item_w, item_h );
int w_p = 0; int client_w = 0;
int h_p = 0; int client_h = 0;
GetClientSize( &w_p, &h_p ); GetClientSize( &client_w, &client_h );
int view_x = m_xScroll*GetScrollPos( wxHORIZONTAL );
int view_y = m_yScroll*GetScrollPos( wxVERTICAL );
if (m_mode & wxLC_REPORT) if (m_mode & wxLC_REPORT)
{ {
int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); if (item_y-5 < view_y )
if ((y > y_s) && (y+h < y_s+h_p)) return; Scroll( -1, (item_y-5)/m_yScroll );
if (y-y_s < 5) { Scroll( -1, (y-5-h_p/2)/m_yScroll ); } if (item_y+item_h+5 > view_y+client_h)
if (y+h+5 > y_s+h_p) { Scroll( -1, (y+h-h_p/2+h+15)/m_yScroll); } Scroll( -1, (item_y+item_h-client_h+15)/m_yScroll );
} }
else else
{ {
int x_s = m_xScroll*GetScrollPos( wxHORIZONTAL ); if (item_x-view_x < 5)
if ((x > x_s) && (x+w < x_s+w_p)) return; Scroll( (item_x-5)/m_xScroll, -1 );
if (x-x_s < 5) { Scroll( (x-5)/m_xScroll, -1 ); } if (item_x+item_w-5 > view_x+client_w)
if (x+w-5 > x_s+w_p) { Scroll( (x+w-w_p+15)/m_xScroll, -1 ); } 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 ); if ((m_mode & wxLC_SINGLE_SEL) || (m_usedKeys == FALSE)) m_current->Hilight( FALSE );
wxListLineData *oldCurrent = m_current; wxListLineData *oldCurrent = m_current;
m_current = newCurrent; m_current = newCurrent;
MoveToFocus();
if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE ); if (shiftDown || (m_mode & wxLC_SINGLE_SEL)) m_current->Hilight( TRUE );
RefreshLine( m_current ); RefreshLine( m_current );
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
FocusLine( m_current ); FocusLine( m_current );
UnfocusLine( oldCurrent ); UnfocusLine( oldCurrent );
MoveToFocus();
} }
void wxListMainWindow::OnKeyDown( wxKeyEvent &event ) void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
@@ -1722,11 +1725,11 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
m_current->ReverseHilight(); m_current->ReverseHilight();
wxNode *node = m_lines.Member( m_current )->Next(); wxNode *node = m_lines.Member( m_current )->Next();
if (node) m_current = (wxListLineData*)node->Data(); if (node) m_current = (wxListLineData*)node->Data();
MoveToFocus();
RefreshLine( oldCurrent ); RefreshLine( oldCurrent );
RefreshLine( m_current ); RefreshLine( m_current );
UnfocusLine( oldCurrent ); UnfocusLine( oldCurrent );
FocusLine( m_current ); FocusLine( m_current );
MoveToFocus();
} }
break; break;
} }

View File

@@ -351,14 +351,14 @@ void wxScrolledWindow::AdjustScrollbars()
if (m_xScrollLines > 0) if (m_xScrollLines > 0)
{ {
// Calculate page size i.e. number of scroll units you get on the // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) noPagePositions = 1; if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus // 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 = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition);
m_xScrollPosition = wxMax( 0, m_xScrollPosition ); m_xScrollPosition = wxMax( 0, m_xScrollPosition );
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines); SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
@@ -373,13 +373,13 @@ void wxScrolledWindow::AdjustScrollbars()
if (m_yScrollLines > 0) if (m_yScrollLines > 0)
{ {
// Calculate page size i.e. number of scroll units you get on the // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) noPagePositions = 1; if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus // 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 = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
m_yScrollPosition = wxMax( 0, 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; int old_x = m_xScrollPosition;
m_xScrollPosition = x_pos; m_xScrollPosition = x_pos;
// Calculate page size i.e. number of scroll units you get on the // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) noPagePositions = 1; if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus // 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 = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
m_xScrollPosition = wxMax( 0, m_xScrollPosition ); m_xScrollPosition = wxMax( 0, m_xScrollPosition );
m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE ); 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) if (y_pos != -1)
{ {
int old_y = m_yScrollPosition; int old_y = m_yScrollPosition;
m_yScrollPosition = y_pos; m_yScrollPosition = y_pos;
// Calculate page size i.e. number of scroll units you get on the // Calculate page size i.e. number of scroll units you get on the
// current client window // current client window
int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 ); int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1) noPagePositions = 1; if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus // 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 = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
m_yScrollPosition = wxMax( 0, m_yScrollPosition ); m_yScrollPosition = wxMax( 0, m_yScrollPosition );
m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE ); 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__ #ifdef __WXMAC__
m_targetWindow->MacUpdateImmediately() ; m_targetWindow->MacUpdateImmediately() ;
#endif #endif
@@ -555,7 +550,7 @@ void wxScrolledWindow::GetVirtualSize (int *x, int *y) const
} }
// Where the current view starts from // Where the current view starts from
void wxScrolledWindow::ViewStart (int *x, int *y) const void wxScrolledWindow::GetViewStart (int *x, int *y) const
{ {
if ( x ) if ( x )
*x = m_xScrollPosition; *x = m_xScrollPosition;