% -----------------------------------------------------------------------------
 % 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
 
 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.
 
 
 
   // 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
 
     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;
 
     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
 
     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 );
 
     }
 
     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;
     {
         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)
             {
 
 {
     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 );
     }
 }
 
     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 )
                 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;
         }
 
 
     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);
     
     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 );
 
         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
 }
 
 // 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;