EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
     EVT_MENU(Minimal_About, MyFrame::OnAbout)
 
-    EVT_BUTTON(-1, MyFrame::OnTest)
+    EVT_MENU(Minimal_Test, MyFrame::OnTest)
 
     EVT_PAINT(MyFrame::OnPaint)
 END_EVENT_TABLE()
     wxMenu *menuFile = new wxMenu(wxMENU_TEAROFF);
 
     menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog");
+    menuFile->Append(Minimal_Test, "&Test...\tCtrl-T", "Test");
     menuFile->AppendSeparator();
     menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
 
     wxMessageBox(msg, "About Minimal", wxOK | wxICON_INFORMATION, this);
 }
 
+struct Foo
+{
+    Foo(int n_) { n = n_; }
+
+    int n;
+};
+
+WX_DECLARE_LIST(Foo, FooList);
+
+#include <wx/listimpl.cpp>
+
+WX_DEFINE_LIST(FooList);
+
+int FooSort(const Foo **item1, const Foo **item2)
+{
+    return (*item2)->n - (*item1)->n;
+}
+
+void ShowList(const FooList& list)
+{
+    wxString msg, str;
+    msg = "The list elements: (";
+    for ( FooList::Node *node = list.GetFirst(); node; node = node->GetNext() )
+    {
+        if ( !!str )
+            msg += ", ";
+        str.Printf("%d", node->GetData()->n);
+        msg += str;
+    }
+
+    msg += ')';
+
+    wxMessageBox(msg, "List contents", wxOK | wxICON_INFORMATION);
+}
+
 void MyFrame::OnTest(wxCommandEvent& event)
 {
+    FooList list;
+    list.Append(new Foo(12));
+    list.Append(new Foo(3));
+    list.Append(new Foo(1));
+    list.Append(new Foo(7));
+    list.Append(new Foo(4));
+    ShowList(list);
+    list.Sort(FooSort);
+    ShowList(list);
 }
 
 void MyFrame::OnPaint(wxPaintEvent& event)
 
 // static wxGifReaderIter* iter;
 wxPalette *wxCopyPalette(const wxPalette *cmap);
 
-wxPNGReader::wxPNGReader(void)
+wxPNGReader::wxPNGReader()
 {
   filetype = 0;
   RawImage = NULL;      //  Image data
   Palette = NULL;
 }
 
-wxBitmap* wxPNGReader::GetBitmap(void)
+wxBitmap* wxPNGReader::GetBitmap()
 {
     wxBitmap *bitmap = new wxBitmap;
     if ( InstantiateBitmap(bitmap) )
   return newCmap;
 }
 
-wxMask *wxPNGReader::CreateMask(void)
+wxMask *wxPNGReader::CreateMask()
 {
     HBITMAP hBitmap = ::CreateBitmap(GetWidth(), GetHeight(), 1, 1, NULL);
 
 
 bool wxPNGReader::ReadFile(wxChar * ImageFileName)
 {
-  int number_passes;
+    int number_passes;
 
-  if (ImageFileName)
-   wxStrcpy(filename, ImageFileName);
+    if (ImageFileName)
+        wxStrcpy(filename, ImageFileName);
 
-  FILE *fp;
-  png_struct *png_ptr;
-   png_info *info_ptr;
-  wxPNGReaderIter iter(this);
+    FILE *fp;
+    png_struct *png_ptr;
+    png_info *info_ptr;
 
-  /* open the file */
-  fp = fopen(wxConvFile.cWX2MB(filename), "rb");
-  if (!fp)
-    return FALSE;
+    /* open the file */
+    fp = fopen(wxConvFile.cWX2MB(filename), "rb");
+    if (!fp)
+        return FALSE;
 
-  /* allocate the necessary structures */
-  png_ptr = new (png_struct);
-  if (!png_ptr)
-  {
-    fclose(fp);
-    return FALSE;
-  }
+    /* allocate the necessary structures */
+    png_ptr = new (png_struct);
+    if (!png_ptr)
+    {
+        fclose(fp);
+        return FALSE;
+    }
 
-  info_ptr = new (png_info);
-  if (!info_ptr)
-  {
-    fclose(fp);
-    delete(png_ptr);
-    return FALSE;
-  }
-  /* set error handling */
-  if (setjmp(png_ptr->jmpbuf))
-  {
-    png_read_destroy(png_ptr, info_ptr, (png_info *)0);
-    fclose(fp);
-    delete(png_ptr);
-    delete(info_ptr);
+    info_ptr = new (png_info);
+    if (!info_ptr)
+    {
+        fclose(fp);
+        delete(png_ptr);
+        return FALSE;
+    }
+    /* set error handling */
+    if (setjmp(png_ptr->jmpbuf))
+    {
+        png_read_destroy(png_ptr, info_ptr, (png_info *)0);
+        fclose(fp);
+        delete(png_ptr);
+        delete(info_ptr);
 
-    /* If we get here, we had a problem reading the file */
-    return FALSE;
-  }
-        //png_set_error(ima_png_error, NULL);
+        /* If we get here, we had a problem reading the file */
+        return FALSE;
+    }
+    //png_set_error(ima_png_error, NULL);
 
-  /* initialize the structures, info first for error handling */
-  png_info_init(info_ptr);
-  png_read_init(png_ptr);
+    /* initialize the structures, info first for error handling */
+    png_info_init(info_ptr);
+    png_read_init(png_ptr);
 
-  /* set up the input control */
-  png_init_io(png_ptr, fp);
+    /* set up the input control */
+    png_init_io(png_ptr, fp);
 
-  /* read the file information */
-  png_read_info(png_ptr, info_ptr);
+    /* read the file information */
+    png_read_info(png_ptr, info_ptr);
 
-  /* allocate the memory to hold the image using the fields
-    of png_info. */
-  png_color_16 my_background={ 0, 31, 127, 255, 0 };
+    /* allocate the memory to hold the image using the fields
+       of png_info. */
+    png_color_16 my_background={ 0, 31, 127, 255, 0 };
 
-  if (info_ptr->valid & PNG_INFO_bKGD)
+    if (info_ptr->valid & PNG_INFO_bKGD)
     {
-    png_set_background(png_ptr, &(info_ptr->background),
-      PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+        png_set_background(png_ptr, &(info_ptr->background),
+                PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
         if ( info_ptr->num_palette > 0 )
             bgindex = info_ptr->background.index;
     }
-  else   {
-    png_set_background(png_ptr, &my_background,
-      PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+    else   {
+        png_set_background(png_ptr, &my_background,
+                PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
 
         // Added by JACS: guesswork!
         if ( info_ptr->num_trans != 0 )
             bgindex = info_ptr->num_trans - 1 ;
-   }
+    }
 
-  /* tell libpng to strip 16 bit depth files down to 8 bits */
-  if (info_ptr->bit_depth == 16)
-    png_set_strip_16(png_ptr);
+    /* tell libpng to strip 16 bit depth files down to 8 bits */
+    if (info_ptr->bit_depth == 16)
+        png_set_strip_16(png_ptr);
 
-  int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
-  Create(info_ptr->width, info_ptr->height, pixel_depth,
-    info_ptr->color_type);
+    int pixel_depth=(info_ptr->pixel_depth<24) ? info_ptr->pixel_depth: 24;
+    Create(info_ptr->width, info_ptr->height, pixel_depth,
+            info_ptr->color_type);
 
-  if (info_ptr->num_palette>0)
+    if (info_ptr->num_palette>0)
     {
-      SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
+        SetPalette((int)info_ptr->num_palette, (rgb_color_struct*)info_ptr->palette);
     }
 
-  int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
- //  printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
-//  printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
+    int row_stride = info_ptr->width * ((pixel_depth+7)>>3);
+    //  printf("P = %d D = %d RS= %d ", info_ptr->num_palette, info_ptr->pixel_depth,row_stride);
+    //  printf("CT = %d TRS = %d BD= %d ", info_ptr->color_type, info_ptr->valid & PNG_INFO_tRNS,info_ptr->bit_depth);
 
-  byte *row_pointers = new byte[row_stride];
+    byte *row_pointers = new byte[row_stride];
 
-  /* turn on interlace handling */
-  if (info_ptr->interlace_type)
-    number_passes = png_set_interlace_handling(png_ptr);
-  else
-    number_passes = 1;
-//  printf("NP = %d ", number_passes);
+    /* turn on interlace handling */
+    if (info_ptr->interlace_type)
+        number_passes = png_set_interlace_handling(png_ptr);
+    else
+        number_passes = 1;
+    //  printf("NP = %d ", number_passes);
+
+    // don't use the object to prevent warnings from VC++ about "unportable
+    // interaction between setjmp and C++ object destruction" (this is a correct
+    // warning, of course!)
+    wxPNGReaderIter *iter = new wxPNGReaderIter(this);
+    for (int pass=0; pass< number_passes; pass++)
+    {
+        iter->upset();
+        int y=0;
+        do  {
+            //(unsigned char *)iter.GetRow();
+            if (info_ptr->interlace_type)  {
+                if (pass>0)
+                    iter->GetRow(row_pointers, row_stride);
+                png_read_row(png_ptr, row_pointers, NULL);
+            }
+            else
+                png_read_row(png_ptr, row_pointers, NULL);
 
-  for (int pass=0; pass< number_passes; pass++) {
-  iter.upset();
-  int y=0;
-  do  {
-//    (unsigned char *)iter.GetRow();
-    if (info_ptr->interlace_type)  {
-     if (pass>0)
-      iter.GetRow(row_pointers, row_stride);
-     png_read_row(png_ptr, row_pointers, NULL);
+            iter->SetRow(row_pointers, row_stride);
+            y++;
+        } while(iter->PrevRow());
+        //  printf("Y=%d ",y);
     }
-    else
-     png_read_row(png_ptr, row_pointers, NULL);
 
-    iter.SetRow(row_pointers, row_stride);
-    y++;
-  } while(iter.PrevRow());
-//  printf("Y=%d ",y);
-  }
-  delete[] row_pointers;
+    delete iter;
+    delete[] row_pointers;
 
-  /* read the rest of the file, getting any additional chunks
-    in info_ptr */
-  png_read_end(png_ptr, info_ptr);
+    /* read the rest of the file, getting any additional chunks
+       in info_ptr */
+    png_read_end(png_ptr, info_ptr);
 
-  /* clean up after the read, and free any memory allocated */
-  png_read_destroy(png_ptr, info_ptr, (png_info *)0);
+    /* clean up after the read, and free any memory allocated */
+    png_read_destroy(png_ptr, info_ptr, (png_info *)0);
 
-  /* free the structures */
-  delete(png_ptr);
-  delete(info_ptr);
+    /* free the structures */
+    delete(png_ptr);
+    delete(info_ptr);
 
-  /* close the file */
-  fclose(fp);
+    /* close the file */
+    fclose(fp);
 
-  /* that's it */
-  return TRUE;
+    /* that's it */
+    return TRUE;
 }