// send a notification event, return TRUE if processed
     bool SendClickEvent();
 
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 };
 
 #endif
 
             WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
 
 protected:
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 };
 
 class WXDLLEXPORT wxBitmapCheckBox: public wxCheckBox
             const wxValidator& validator = wxDefaultValidator,
             const wxString& name = wxCheckBoxNameStr);
 
-    virtual void SetValue(bool value);
-    virtual bool GetValue() const ;
-
     virtual void SetLabel(const wxBitmap& bitmap);
-
-protected:
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 #endif
     // _WX_CHECKBOX_H_
 
 protected:
     int     m_noStrings;
 
+    virtual wxSize DoGetBestSize();
     virtual void DoSetSize(int x, int y,
-            int width, int height,
-            int sizeFlags = wxSIZE_AUTO);
+                           int width, int height,
+                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
 
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifndef _WX_COMBOBOX_H_
 #define _WX_COMBOBOX_H_
 
 #ifdef __GNUG__
-#pragma interface "combobox.h"
+    #pragma interface "combobox.h"
 #endif
 
 #include "wx/choice.h"
 WXDLLEXPORT_DATA(extern const wxChar*) wxComboBoxNameStr;
 WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
 
-// Combobox item
+// ----------------------------------------------------------------------------
+// Combobox control
+// ----------------------------------------------------------------------------
+
 class WXDLLEXPORT wxComboBox: public wxChoice
 {
-  DECLARE_DYNAMIC_CLASS(wxComboBox)
-
- public:
-  inline wxComboBox(void) {}
-
-  inline wxComboBox(wxWindow *parent, wxWindowID id,
-           const wxString& value = wxEmptyString,
-           const wxPoint& pos = wxDefaultPosition,
-           const wxSize& size = wxDefaultSize,
-           int n = 0, const wxString choices[] = NULL,
-           long style = 0,
-           const wxValidator& validator = wxDefaultValidator,
-           const wxString& name = wxComboBoxNameStr)
-  {
-    Create(parent, id, value, pos, size, n, choices, style, validator, name);
-  }
-
-  bool Create(wxWindow *parent, wxWindowID id,
-           const wxString& value = wxEmptyString,
-           const wxPoint& pos = wxDefaultPosition,
-           const wxSize& size = wxDefaultSize,
-           int n = 0, const wxString choices[] = NULL,
-           long style = 0,
-           const wxValidator& validator = wxDefaultValidator,
-           const wxString& name = wxComboBoxNameStr);
-
-  // List functions: see wxChoice
-  
-  // Text field functions
-  virtual wxString GetValue(void) const ;
-  virtual void SetValue(const wxString& value);
-
-  // Clipboard operations
-  virtual void Copy(void);
-  virtual void Cut(void);
-  virtual void Paste(void);
-  virtual void SetInsertionPoint(long pos);
-  virtual void SetInsertionPointEnd(void);
-  virtual long GetInsertionPoint(void) const ;
-  virtual long GetLastPosition(void) const ;
-  virtual void Replace(long from, long to, const wxString& value);
-  virtual void Remove(long from, long to);
-  virtual void SetSelection(int n)
-  {
-    wxChoice::SetSelection(n);
-  }
-  virtual void SetSelection(long from, long to);
-  virtual void SetEditable(bool editable);
-
-  virtual bool MSWCommand(WXUINT param, WXWORD id);
+    DECLARE_DYNAMIC_CLASS(wxComboBox)
+
+public:
+    wxComboBox() { }
+
+    wxComboBox(wxWindow *parent, wxWindowID id,
+            const wxString& value = wxEmptyString,
+            const wxPoint& pos = wxDefaultPosition,
+            const wxSize& size = wxDefaultSize,
+            int n = 0, const wxString choices[] = NULL,
+            long style = 0,
+            const wxValidator& validator = wxDefaultValidator,
+            const wxString& name = wxComboBoxNameStr)
+    {
+        Create(parent, id, value, pos, size, n, choices, style, validator, name);
+    }
+
+    bool Create(wxWindow *parent, wxWindowID id,
+            const wxString& value = wxEmptyString,
+            const wxPoint& pos = wxDefaultPosition,
+            const wxSize& size = wxDefaultSize,
+            int n = 0, const wxString choices[] = NULL,
+            long style = 0,
+            const wxValidator& validator = wxDefaultValidator,
+            const wxString& name = wxComboBoxNameStr);
+
+    // List functions: see wxChoice
+
+    // Text field functions
+    wxString GetValue() const { return GetLabel(); }
+    virtual void SetValue(const wxString& value);
+
+    // Clipboard operations
+    virtual void Copy();
+    virtual void Cut();
+    virtual void Paste();
+    virtual void SetInsertionPoint(long pos);
+    virtual void SetInsertionPointEnd();
+    virtual long GetInsertionPoint() const;
+    virtual long GetLastPosition() const;
+    virtual void Replace(long from, long to, const wxString& value);
+    virtual void Remove(long from, long to);
+    virtual void SetSelection(int n) { wxChoice::SetSelection(n); }
+    virtual void SetSelection(long from, long to);
+    virtual void SetEditable(bool editable);
+
+    virtual bool MSWCommand(WXUINT param, WXWORD id);
+
+protected:
+    virtual void DoSetSize(int x, int y,
+                           int width, int height,
+                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif // wxUSE_COMBOBOX
 
    // For controls like radiobuttons which are really composite
    wxList           m_subControls;
 
+    virtual wxSize DoGetBestSize();
+
 private:
    DECLARE_EVENT_TABLE()
 };
 
 protected:
     int      m_rangeMax;
     int      m_gaugePos;
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
 
 protected:
     int      m_rangeMax;
     int      m_gaugePos;
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
 
     // control items
     wxListBoxItemsArray m_aItems;
 #endif
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
 
         wxBitmap *bitmap;
     } m_image;
 
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 };
 
 #endif
 
 class WXDLLEXPORT wxStaticBox : public wxControl
 {
 DECLARE_DYNAMIC_CLASS(wxStaticBox)
-        
+
 public:
     wxStaticBox() { }
 
     {
         Create(parent, id, label, pos, size, style, name);
     }
-    
+
     bool Create(wxWindow *parent, wxWindowID id,
         const wxString& label,
         const wxPoint& pos = wxDefaultPosition,
         const wxSize& size = wxDefaultSize,
         long style = 0,
         const wxString& name = wxStaticBoxNameStr);
-    
+
+    // implementation from now on
+    // --------------------------
+
     void OnEraseBackground(wxEraseEvent& event);
-    
+
     virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
-    
-    void SetLabel(const wxString& label);
 
     virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
                                 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
-    
+
     // overriden base class virtuals
     virtual bool AcceptsFocus() const { return FALSE; }
-    
+
 protected:
     virtual void DoSetSize(int x, int y,
                            int width, int height,
                            int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 
 private:
     DECLARE_EVENT_TABLE()
 
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifndef _WX_STATTEXT_H_
 
 public:
     wxStaticText() { }
-    
+
     wxStaticText(wxWindow *parent, wxWindowID id,
         const wxString& label,
         const wxPoint& pos = wxDefaultPosition,
     {
         Create(parent, id, label, pos, size, style, name);
     }
-    
+
     bool Create(wxWindow *parent, wxWindowID id,
         const wxString& label,
         const wxPoint& pos = wxDefaultPosition,
         const wxSize& size = wxDefaultSize,
         long style = 0,
         const wxString& name = wxStaticTextNameStr);
-    
+
     // accessors
     void SetLabel(const wxString& label);
-    
+
     // overriden base class virtuals
     virtual bool AcceptsFocus() const { return FALSE; }
-    
+
     // callbacks
     virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
                                 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
     virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
 
 protected:
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 };
 
 #endif
 
     wxTextCtrl(wxWindow *parent, wxWindowID id,
             const wxString& value = wxEmptyString,
             const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize, long style = 0,
+            const wxSize& size = wxDefaultSize,
+            long style = 0,
             const wxValidator& validator = wxDefaultValidator,
             const wxString& name = wxTextCtrlNameStr)
 #ifndef NO_TEXT_WINDOW_STREAM
     bool Create(wxWindow *parent, wxWindowID id,
             const wxString& value = wxEmptyString,
             const wxPoint& pos = wxDefaultPosition,
-            const wxSize& size = wxDefaultSize, long style = wxTE_PROCESS_TAB,
+            const wxSize& size = wxDefaultSize,
+            long style = 0,
             const wxValidator& validator = wxDefaultValidator,
             const wxString& name = wxTextCtrlNameStr);
 
     // accessors
     // ---------
-    virtual wxString GetValue() const ;
+
+    virtual wxString GetValue() const;
     virtual void SetValue(const wxString& value);
 
     virtual int GetLineLength(long lineNo) const;
     virtual void ShowPosition(long pos);
     virtual void Clear();
 
-    // callbacks
-    // ---------
-    void OnDropFiles(wxDropFilesEvent& event);
-    void OnChar(wxKeyEvent& event); // Process 'enter' if required
-
-    void OnCut(wxCommandEvent& event);
-    void OnCopy(wxCommandEvent& event);
-    void OnPaste(wxCommandEvent& event);
-    void OnUndo(wxCommandEvent& event);
-    void OnRedo(wxCommandEvent& event);
-
-    void OnUpdateCut(wxUpdateUIEvent& event);
-    void OnUpdateCopy(wxUpdateUIEvent& event);
-    void OnUpdatePaste(wxUpdateUIEvent& event);
-    void OnUpdateUndo(wxUpdateUIEvent& event);
-    void OnUpdateRedo(wxUpdateUIEvent& event);
+    // Implementation from now on
+    // --------------------------
 
-    // Implementation
-    // --------------
     virtual void Command(wxCommandEvent& event);
     virtual bool MSWCommand(WXUINT param, WXWORD id);
 
 
     virtual bool AcceptsFocus() const;
 
+    // callbacks
+    // ---------
+    void OnDropFiles(wxDropFilesEvent& event);
+    void OnChar(wxKeyEvent& event); // Process 'enter' if required
+
+    void OnCut(wxCommandEvent& event);
+    void OnCopy(wxCommandEvent& event);
+    void OnPaste(wxCommandEvent& event);
+    void OnUndo(wxCommandEvent& event);
+    void OnRedo(wxCommandEvent& event);
+
+    void OnUpdateCut(wxUpdateUIEvent& event);
+    void OnUpdateCopy(wxUpdateUIEvent& event);
+    void OnUpdatePaste(wxUpdateUIEvent& event);
+    void OnUpdateUndo(wxUpdateUIEvent& event);
+    void OnUpdateRedo(wxUpdateUIEvent& event);
+
 protected:
 #if wxUSE_RICHEDIT
     bool      m_isRich; // Are we using rich text edit to implement this?
     // limit is big enough)
     void AdjustSpaceLimit();
 
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 
 private:
     DECLARE_EVENT_TABLE()
 
                            int sizeFlags = wxSIZE_AUTO);
     virtual void DoSetClientSize(int width, int height);
 
+    // get the size which best suits the window: e.g., for a static text it
+    // will be the width and height of the text
+    virtual wxSize DoGetBestSize();
+
 #if wxUSE_TOOLTIPS
     virtual void DoSetToolTip( wxToolTip *tip );
 #endif // wxUSE_TOOLTIPS
 
 // size management including autosizing
 // ----------------------------------------------------------------------------
 
-void wxButton::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxButton::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(¤tX, ¤tY);
-    int x1 = x;
-    int y1 = y;
-    if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        x1 = currentX;
-    if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        y1 = currentY;
-
-    AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-    int actualWidth = width;
-    int actualHeight = height;
-    int ww, hh;
-    GetSize(&ww, &hh);
-
-    int current_width;
-    int cyf;
-    wxString buf = wxGetWindowText(GetHWND());
-    GetTextExtent(buf, ¤t_width, &cyf, NULL, NULL, &GetFont());
-
-    // If we're prepared to use the existing width, then...
-    if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
-    {
-        actualWidth = ww;
-    }
-    else if (width == -1)
-    {
-        int cx;
-        int cy;
-        wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
-        actualWidth = (int)(current_width + 3*cx) ;
-    }
+    wxString label = wxGetWindowText(GetHWND());
+    int wBtn;
+    GetTextExtent(label, &wBtn, NULL);
 
-    // If we're prepared to use the existing height, then...
-    if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
-    {
-        actualHeight = hh;
-    }
-    else if (height == -1)
-    {
-        actualHeight = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cyf);
-    }
+    int wChar, hChar;
+    wxGetCharSize(GetHWND(), &wChar, &hChar, &GetFont());
+
+    // add a margin - the button is wider than just its label
+    wBtn += 3*wChar;
+
+    // the button height is proportional to the height of the font used
+    int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
 
-    MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE);
+    return wxSize(wBtn, hBtn);
 }
 
+// ----------------------------------------------------------------------------
+// set this button as the default one in its panel
+// ----------------------------------------------------------------------------
+
 void wxButton::SetDefault()
 {
     wxWindow *parent = GetParent();
 
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:    wxWindows license
+// Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
 #ifdef __GNUG__
-#pragma implementation "checkbox.h"
+    #pragma implementation "checkbox.h"
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
 #ifndef WX_PRECOMP
-#include "wx/checkbox.h"
-#include "wx/brush.h"
+    #include "wx/checkbox.h"
+    #include "wx/brush.h"
 #endif
 
 #include "wx/msw/private.h"
 
+// ----------------------------------------------------------------------------
+// macros
+// ----------------------------------------------------------------------------
+
 #if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
-IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
+    IMPLEMENT_DYNAMIC_CLASS(wxCheckBox, wxControl)
+    IMPLEMENT_DYNAMIC_CLASS(wxBitmapCheckBox, wxCheckBox)
 #endif
 
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxCheckBox
+// ----------------------------------------------------------------------------
+
 bool wxCheckBox::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
 {
-  wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
-  event.SetInt(GetValue());
-  event.SetEventObject(this);
-  ProcessCommand(event);
-  return TRUE;
+    wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, m_windowId);
+    event.SetInt(GetValue());
+    event.SetEventObject(this);
+    ProcessCommand(event);
+    return TRUE;
 }
 
 // Single check box item
            const wxValidator& validator,
            const wxString& name)
 {
-  SetName(name);
-  SetValidator(validator);
-  if (parent) parent->AddChild(this);
-
-  SetBackgroundColour(parent->GetBackgroundColour()) ;
-  SetForegroundColour(parent->GetForegroundColour()) ;
-
-  m_windowStyle = style;
-
-  wxString Label = label;
-  if (Label == _T(""))
-    Label = _T(" "); // Apparently needed or checkbox won't show
-
-       if ( id == -1 )
-               m_windowId = NewControlId();
-       else
-               m_windowId = id;
-
-  int x = pos.x;
-  int y = pos.y;
-  int width = size.x;
-  int height = size.y;
-
-  long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
-  if ( style & wxALIGN_RIGHT )
-    msStyle |= BS_LEFTTEXT;
-
-  // We perhaps have different concepts of 3D here - a 3D border,
-  // versus a 3D button.
-  // So we only wish to give a border if this is specified
-  // in the style.
-  bool want3D;
-  WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
-
-  // Even with extended styles, need to combine with WS_BORDER
-  // for them to look right.
-/*
-  if ( want3D || wxStyleHasBorder(m_windowStyle) )
-    msStyle |= WS_BORDER;
-*/
-
-  m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label,
-                                  msStyle,
-                                  0, 0, 0, 0,
-                                  (HWND)parent->GetHWND(), (HMENU)m_windowId,
-                                  wxGetInstance(), NULL);
+    SetName(name);
+    SetValidator(validator);
+    if (parent) parent->AddChild(this);
+
+    SetBackgroundColour(parent->GetBackgroundColour()) ;
+    SetForegroundColour(parent->GetForegroundColour()) ;
+
+    m_windowStyle = style;
+
+    wxString Label = label;
+    if (Label == _T(""))
+        Label = _T(" "); // Apparently needed or checkbox won't show
+
+    if ( id == -1 )
+        m_windowId = NewControlId();
+    else
+        m_windowId = id;
+
+    int x = pos.x;
+    int y = pos.y;
+    int width = size.x;
+    int height = size.y;
+
+    long msStyle = BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
+    if ( style & wxALIGN_RIGHT )
+        msStyle |= BS_LEFTTEXT;
+
+    // We perhaps have different concepts of 3D here - a 3D border,
+    // versus a 3D button.
+    // So we only wish to give a border if this is specified
+    // in the style.
+    bool want3D;
+    WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
+
+    // Even with extended styles, need to combine with WS_BORDER
+    // for them to look right.
+    /*
+       if ( want3D || wxStyleHasBorder(m_windowStyle) )
+       msStyle |= WS_BORDER;
+     */
+
+    m_hWnd = (WXHWND)CreateWindowEx(exStyle, _T("BUTTON"), Label,
+            msStyle,
+            0, 0, 0, 0,
+            (HWND)parent->GetHWND(), (HMENU)m_windowId,
+            wxGetInstance(), NULL);
 
 #if wxUSE_CTL3D
-  if (want3D)
-  {
-    Ctl3dSubclassCtl((HWND)m_hWnd);
-    m_useCtl3D = TRUE;
-  }
+    if (want3D)
+    {
+        Ctl3dSubclassCtl(GetHwnd());
+        m_useCtl3D = TRUE;
+    }
 #endif
 
-  // Subclass again for purposes of dialog editing mode
-  SubclassWin(m_hWnd);
-  
-  SetFont(parent->GetFont());
+    // Subclass again for purposes of dialog editing mode
+    SubclassWin(m_hWnd);
 
-  SetSize(x, y, width, height);
+    SetFont(parent->GetFont());
 
-  return TRUE;
+    SetSize(x, y, width, height);
+
+    return TRUE;
 }
 
 void wxCheckBox::SetLabel(const wxString& label)
 {
-  SetWindowText((HWND)GetHWND(), label);
+  SetWindowText(GetHwnd(), label);
 }
 
-void wxCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxCheckBox::DoGetBestSize()
 {
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
+    int wCheckbox, hCheckbox;
 
-  int current_width, cyf;
-  HWND button = (HWND) GetHWND();
+    wxString str = wxGetWindowText(GetHWND());
 
-  int nLen = GetWindowTextLength(button);
-  wxString str;
-  GetWindowText(button, str.GetWriteBuf(nLen), nLen);
-  str.UngetWriteBuf();
+    if ( !str.IsEmpty() )
+    {
+        GetTextExtent(str, &wCheckbox, &hCheckbox);
+        wCheckbox += RADIO_SIZE;
 
-  if ( !str.IsEmpty() )
-  {
-    GetTextExtent(str, ¤t_width, &cyf, NULL, NULL, & this->GetFont());
-    if (w1 < 0)
-      w1 = (int)(current_width + RADIO_SIZE);
-    if (h1 < 0)
+        if ( hCheckbox < RADIO_SIZE )
+            hCheckbox = RADIO_SIZE;
+    }
+    else
     {
-      h1 = (int)(cyf);
-      if (h1 < RADIO_SIZE)
-        h1 = RADIO_SIZE;
+        wCheckbox = RADIO_SIZE;
+        hCheckbox = RADIO_SIZE;
     }
-  }
-  else
-  {
-    if (w1 < 0)
-      w1 = RADIO_SIZE;
-    if (h1 < 0)
-      h1 = RADIO_SIZE;
-  }
 
-  MoveWindow(button, x1, y1, w1, h1, TRUE);
+    return wxSize(wCheckbox, hCheckbox);
 }
 
 void wxCheckBox::SetValue(bool val)
 {
-  SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0);
+    SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
 }
 
 #ifndef BST_CHECKED
 bool wxCheckBox::GetValue() const
 {
 #ifdef __WIN32__
-  return (SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0) == BST_CHECKED);
+  return (SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
 #else
-  return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003);
+  return ((0x003 & SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x003);
 #endif
 }
 
 WXHBRUSH wxCheckBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
-                       WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+                                WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 {
 #if wxUSE_CTL3D
   if ( m_useCtl3D )
   {
     HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
-      
+
       return (WXHBRUSH) hbrush;
   }
 #endif
   ProcessCommand (event);
 }
 
+// ----------------------------------------------------------------------------
+// wxBitmapCheckBox
+// ----------------------------------------------------------------------------
+
 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
            const wxPoint& pos,
            const wxSize& size, long style,
   SetForegroundColour(parent->GetForegroundColour()) ;
   m_windowStyle = style;
 
-       if ( id == -1 )
-               m_windowId = NewControlId();
-       else
-               m_windowId = id;
+  if ( id == -1 )
+      m_windowId = NewControlId();
+  else
+      m_windowId = id;
 
   int x = pos.x;
   int y = pos.y;
   if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
   {
     Ctl3dSubclassCtl(wx_button);
-         m_useCtl3D = TRUE;
+    m_useCtl3D = TRUE;
   }
 #endif
 
   // Subclass again for purposes of dialog editing mode
   SubclassWin((WXHWND)wx_button);
 
-//  SetFont(parent->GetFont());
-
   SetSize(x, y, width, height);
 
   ShowWindow(wx_button, SW_SHOW);
+
   return TRUE;
 }
 
 void wxBitmapCheckBox::SetLabel(const wxBitmap& bitmap)
 {
+    wxFAIL_MSG("not implemented");
 }
-
-void wxBitmapCheckBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  HWND button = (HWND) GetHWND();
-/*
-    if (w1<0)
-      w1 = checkWidth + FB_MARGIN ;
-    if (h1<0)
-      h1 = checkHeight + FB_MARGIN ;
-*/
-  MoveWindow(button, x1, y1, w1, h1, TRUE);
-}
-
-void wxBitmapCheckBox::SetValue(bool val)
-{
-  SendMessage((HWND) GetHWND(), BM_SETCHECK, val, 0);
-}
-
-bool wxBitmapCheckBox::GetValue() const
-{
-  return ((0x003 & SendMessage((HWND) GetHWND(), BM_GETCHECK, 0, 0)) == 0x003);
-}
-
-
 
 
 void wxChoice::Append(const wxString& item)
 {
-  SendMessage((HWND) GetHWND(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item);
+  SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)(const wxChar *)item);
 
   m_noStrings ++;
 }
 
 void wxChoice::Delete(int n)
 {
-  m_noStrings = (int)SendMessage((HWND) GetHWND(), CB_DELETESTRING, n, 0);
+  m_noStrings = (int)SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
 }
 
 void wxChoice::Clear(void)
 {
-  SendMessage((HWND) GetHWND(), CB_RESETCONTENT, 0, 0);
+  SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
 
   m_noStrings = 0;
 }
 
 int wxChoice::GetSelection(void) const
 {
-  return (int)SendMessage((HWND) GetHWND(), CB_GETCURSEL, 0, 0);
+  return (int)SendMessage(GetHwnd(), CB_GETCURSEL, 0, 0);
 }
 
 void wxChoice::SetSelection(int n)
 {
-  SendMessage((HWND) GetHWND(), CB_SETCURSEL, n, 0);
+  SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
 }
 
 int wxChoice::FindString(const wxString& s) const
   char buf[512];
   for (int i = 0; i < Number(); i++)
   {
-    int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf);
+    int len = (int)SendMessage(GetHwnd(), CB_GETLBTEXT, i, (LPARAM)(LPSTR)buf);
     buf[len] = 0;
     if (strcmp(buf, (const char *)s) == 0)
       return i;
   }
   return -1;
 #else
- int pos = (int)SendMessage((HWND) GetHWND(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s);
+ int pos = (int)SendMessage(GetHwnd(), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)(LPSTR)(const wxChar *)s);
  if (pos == LB_ERR)
    return -1;
  else
 
 wxString wxChoice::GetString(int n) const
 {
-  int len = (int)SendMessage((HWND) GetHWND(), CB_GETLBTEXT, n, (long)wxBuffer);
-  wxBuffer[len] = 0;
-  return wxString(wxBuffer);
-}
-
-void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  // If we're prepared to use the existing size, then...
-  if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-  {
-    GetSize(&w1, &h1);
-  }
+    size_t len = (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0);
+    wxString str;
+    if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n,
+                       (LPARAM)str.GetWriteBuf(len)) == CB_ERR )
+    {
+        wxLogLastError("SendMessage(CB_GETLBTEXT)");
+    }
 
-  int cx; // button font dimensions
-  int cy;
-  wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
+    str.UngetWriteBuf();
 
-  int control_width, control_height;
+    return str;
+}
 
-  // Ignore height parameter because height doesn't
-  // mean 'initially displayed' height, it refers to the
-  // drop-down menu as well. The wxWindows interpretation
-  // is different; also, getting the size returns the
-  // _displayed_ size (NOT the drop down menu size)
-  // so setting-getting-setting size would not work.
-  h1 = -1;
+void wxChoice::DoSetSize(int x, int y,
+                         int width, int height,
+                         int sizeFlags)
+{
+    // Ignore height parameter because height doesn't mean 'initially
+    // displayed' height, it refers to the drop-down menu as well. The
+    // wxWindows interpretation is different; also, getting the size returns
+    // the _displayed_ size (NOT the drop down menu size) so
+    // setting-getting-setting size would not work.
+    wxControl::DoSetSize(x, y, width, -1, sizeFlags);
+}
 
-  // Deal with default size (using -1 values)
-  if (width <= 0)
-  {
-    // Find the longest string
-    if (m_noStrings == 0)
-    {
-      control_width = 100;
-    }
-    else
+wxSize wxChoice::DoGetBestSize()
+{
+    // find the widest string
+    int wLine;
+    int wChoice = 0;
+    for ( int i = 0; i < m_noStrings; i++ )
     {
-      int len, ht;
-      int longest = 0;
-      int i;
-      for (i = 0; i < m_noStrings; i++)
-      {
         wxString str(GetString(i));
-        GetTextExtent(str, &len, &ht, NULL, NULL, & this->GetFont());
-        if ( len > longest)
-            longest = len;
-      }
-
-      control_width = longest + cx*5;
+        GetTextExtent(str, &wLine, NULL);
+        if ( wLine > wChoice )
+            wChoice = wLine;
     }
-  }
-  else
-  {
-    // If non-default width...
-    control_width = w1;
-  }
 
+    // give it some reasonable default value if there are no strings in the
+    // list
+    if ( wChoice == 0 )
+        wChoice = 100;
 
-  // Choice drop-down list depends on number of items (limited to 10)
-  if (h1 <= 0)
-  {
-    if (m_noStrings == 0)
-        h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*10;
-    else
-        h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*(wxMin(10, m_noStrings) + 1);
-  }
-
-  control_height = h1;
+    // the combobox should be larger than the widest string
+    int cx, cy;
+    wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
 
-  // Calculations may have made text size too small
-  if (control_height <= 0)
-    control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
+    wChoice += 5*cx;
 
-  if (control_width <= 0)
-    control_width = 100;
+    // Choice drop-down list depends on number of items (limited to 10)
+    size_t nStrings = m_noStrings == 0 ? 10 : wxMin(10, m_noStrings) + 1;
+    int hChoice = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*nStrings;
 
-  MoveWindow((HWND)GetHWND(), x1, y1,
-             control_width, control_height, TRUE);
+    return wxSize(wChoice, hChoice);
 }
 
 WXHBRUSH wxChoice::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
 
   return TRUE;
 }
 
-wxString wxComboBox::GetValue() const
-{
-  return wxGetWindowText(GetHWND());
-}
-
 void wxComboBox::SetValue(const wxString& value)
 {
   // If newlines are denoted by just 10, must stick 13 in front.
       j ++;
     }
     tmp[j] = 0;
-    SetWindowText((HWND) GetHWND(), tmp);
+    SetWindowText(GetHwnd(), tmp);
     delete[] tmp;
   }
   else
-    SetWindowText((HWND) GetHWND(), (const wxChar *)value);
+    SetWindowText(GetHwnd(), value);
 }
 
 // Clipboard operations
 void wxComboBox::Copy()
 {
-  HWND hWnd = (HWND) GetHWND();
+  HWND hWnd = GetHwnd();
   SendMessage(hWnd, WM_COPY, 0, 0L);
 }
 
 void wxComboBox::Cut()
 {
-  HWND hWnd = (HWND) GetHWND();
+  HWND hWnd = GetHwnd();
   SendMessage(hWnd, WM_CUT, 0, 0L);
 }
 
 void wxComboBox::Paste()
 {
-  HWND hWnd = (HWND) GetHWND();
+  HWND hWnd = GetHwnd();
   SendMessage(hWnd, WM_PASTE, 0, 0L);
 }
 
 void wxComboBox::SetEditable(bool editable)
 {
   // Can't implement in MSW?
-//  HWND hWnd = (HWND) GetHWND();
+//  HWND hWnd = GetHwnd();
 //  SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
 }
 
 void wxComboBox::SetInsertionPoint(long pos)
 {
 /*
-  HWND hWnd = (HWND) GetHWND();
+  HWND hWnd = GetHwnd();
 #ifdef __WIN32__
   SendMessage(hWnd, EM_SETSEL, pos, pos);
   SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
 long wxComboBox::GetInsertionPoint() const
 {
 /*
-  DWORD Pos=(DWORD)SendMessage((HWND) GetHWND(), EM_GETSEL, 0, 0L);
+  DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
   return Pos&0xFFFF;
 */
   return 0;
 long wxComboBox::GetLastPosition() const
 {
 /*
-    HWND hWnd = (HWND) GetHWND();
+    HWND hWnd = GetHwnd();
 
     // Will always return a number > 0 (according to docs)
     int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
 
     // This gets the char index for the _beginning_ of the last line
     int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
-    
+
     // Get number of characters in the last line. We'll add this to the character
     // index for the last line, 1st position.
     int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
 void wxComboBox::Replace(long from, long to, const wxString& value)
 {
 #if wxUSE_CLIPBOARD
-    HWND hWnd = (HWND) GetHWND();
+    HWND hWnd = GetHwnd();
     long fromChar = from;
     long toChar = to;
-    
+
     // Set selection and remove it
 #ifdef __WIN32__
     SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
 
 void wxComboBox::Remove(long from, long to)
 {
-    HWND hWnd = (HWND) GetHWND();
+    HWND hWnd = GetHwnd();
     long fromChar = from;
     long toChar = to;
-    
+
     // Cut all selected text
 #ifdef __WIN32__
     SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
 
 void wxComboBox::SetSelection(long from, long to)
 {
-    HWND hWnd = (HWND) GetHWND();
+    HWND hWnd = GetHwnd();
     long fromChar = from;
     long toChar = to;
     // if from and to are both -1, it means
       fromChar = 0;
       toChar = -1;
     }
-    
+
 #ifdef __WIN32__
     SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
 //    SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
 #endif
 }
 
+void wxComboBox::DoSetSize(int x, int y,
+                           int width, int height,
+                           int sizeFlags)
+{
+    wxControl::DoSetSize(x, y, width, height, sizeFlags);
+
+    // VZ: for unknown (to me) reasons, if we don't do this, the combobox
+    //     somehow is hidden by the static boxes, although static boxes do
+    //     put themselves at the very end of Z-order.
+    if ( !::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
+                         SWP_NOMOVE | SWP_NOSIZE) )
+    {
+        wxLogLastError(_T("SetWindowPos"));
+    }
+}
+
 #endif
  // wxUSE_COMBOBOX
 
 
     m_isBeingDeleted = TRUE;
 }
 
+wxSize wxControl::DoGetBestSize()
+{
+    return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
+}
+
 bool wxControl::ProcessCommand(wxCommandEvent& event)
 {
 #if WXWIN_COMPATIBILITY
 
 
 void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
-  int currentX, currentY;
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
+    wxWindow::DoSetSize(x, y, width, height, sizeFlags);
 
-  GetPosition(¤tX, ¤tY);
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  int ww,hh ;
-  GetSize(&ww,&hh) ;
-  if (width == -1) w1 = ww ;
-  if (height==-1) h1 = hh ;
-
-  MoveWindow(GetHwnd(), x1, y1, w1, h1, (BOOL)TRUE);
-
-  wxSizeEvent event(wxSize(width, height), m_windowId);
-  event.SetEventObject( this );
-  GetEventHandler()->ProcessEvent(event);
+    wxSizeEvent event(wxSize(width, height), m_windowId);
+    event.SetEventObject( this );
+    GetEventHandler()->ProcessEvent(event);
 }
 
 bool wxFrame::Show(bool show)
 
   m_windowStyle = style;
 
   if ( id == -1 )
-       m_windowId = (int)NewControlId();
+      m_windowId = (int)NewControlId();
   else
-       m_windowId = id;
+      m_windowId = id;
 
   int x = pos.x;
   int y = pos.y;
   return TRUE;
 }
 
-void wxGauge95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  // If we're prepared to use the existing size, then...
-  if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-  {
-    GetSize(&w1, &h1);
-  }
-
-  // Deal with default size (using -1 values)
-  if (w1<=0)
-    w1 = DEFAULT_ITEM_WIDTH;
-
-  if (h1<=0)
-    h1 = DEFAULT_ITEM_HEIGHT;
-
-  MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
-}
-
 void wxGauge95::SetShadowWidth(int w)
 {
 }
 
   SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0);
   SendMessage(wx_button, ZYZG_SETRANGE, range, 0);
 
-  SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
-  SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
+  SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
+  SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
 
   SetFont(parent->GetFont());
 
     height = 50;
   SetSize(x, y, width, height);
 
-  ShowWindow((HWND) GetHWND(), SW_SHOW);
+  ShowWindow(GetHwnd(), SW_SHOW);
 
   return TRUE;
 }
 
-void wxGaugeMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  // If we're prepared to use the existing size, then...
-  if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-  {
-    GetSize(&w1, &h1);
-  }
-
-  // Deal with default size (using -1 values)
-  if (w1<=0)
-    w1 = DEFAULT_ITEM_WIDTH;
-
-  if (h1<=0)
-    h1 = DEFAULT_ITEM_HEIGHT;
-
-  MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
-}
-
 void wxGaugeMSW::SetShadowWidth(int w)
 {
-  SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0);
+  SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0);
 }
 
 void wxGaugeMSW::SetBezelFace(int w)
 {
-  SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0);
+  SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0);
 }
 
 void wxGaugeMSW::SetRange(int r)
 {
   m_rangeMax = r;
 
-  SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0);
+  SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0);
 }
 
 void wxGaugeMSW::SetValue(int pos)
 {
   m_gaugePos = pos;
 
-  SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0);
+  SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0);
 }
 
 int wxGaugeMSW::GetShadowWidth(void) const
 {
-  return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0);
+  return (int) SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0);
 }
 
 int wxGaugeMSW::GetBezelFace(void) const
 {
-  return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0);
+  return (int) SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0);
 }
 
 int wxGaugeMSW::GetRange(void) const
 {
-  return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0);
+  return (int) SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0);
 }
 
 int wxGaugeMSW::GetValue(void) const
 {
-  return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0);
+  return (int) SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0);
 }
 
 bool wxGaugeMSW::SetForegroundColour(const wxColour& col)
     if ( !wxControl::SetForegroundColour(col) )
         return FALSE;
 
-    SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
+    SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
 
     return TRUE;
 }
     if ( !wxControl::SetBackgroundColour(col) )
         return FALSE;
 
-    SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
+    SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue()));
 
     return TRUE;
 }
 
     return result;
 }
 
-void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-    int currentX, currentY;
-    GetPosition(¤tX, ¤tY);
-
-    int x1 = x;
-    int y1 = y;
-    int w1 = width;
-    int h1 = height;
-
-    if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        x1 = currentX;
-    if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        y1 = currentY;
-
-    AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-    // If we're prepared to use the existing size, then...
-    if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-    {
-        GetSize(&w1, &h1);
-    }
-
-    int cx; // button font dimensions
-    int cy;
-
-    wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
-
-    float control_width, control_height, control_x, control_y;
-
-    // Deal with default size (using -1 values)
-    if (w1<=0)
-        w1 = DEFAULT_ITEM_WIDTH;
-
-    if (h1<=0)
-        h1 = DEFAULT_ITEM_HEIGHT;
-
-    control_x = (float)x1;
-    control_y = (float)y1;
-    control_width = (float)w1;
-    control_height = (float)h1;
-
-    // Calculations may have made size too small
-    if (control_height <= 0)
-        control_height = (float)DEFAULT_ITEM_HEIGHT;
-
-    if (control_width <= 0)
-        control_width = (float)DEFAULT_ITEM_WIDTH;
-
-    MoveWindow(GetHwnd(),
-               (int)control_x, (int)control_y,
-               (int)control_width, (int)control_height,
-               TRUE);
-
-}
-
-// Windows-specific code to set the horizontal extent of
-// the listbox, if necessary. If s is non-NULL, it's
-// used to calculate the horizontal extent.
+// Windows-specific code to set the horizontal extent of the listbox, if
+// necessary. If s is non-NULL, it's used to calculate the horizontal extent.
 // Otherwise, all strings are used.
 void wxListBox::SetHorizontalExtent(const wxString& s)
 {
 
 // Restored old code.
 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-  int xx = x;
-  int yy = y;
-
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    xx = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    yy = currentY;
-
-  wxChar buf[400];
-
-  int y_offset = yy;
-  int x_offset = xx;
-  int current_width, cyf;
-
-  int cx1,cy1;
-  wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
-  // Attempt to have a look coherent with other platforms:
-  // We compute the biggest toggle dim, then we align all
-  // items according this value.
-  int maxWidth =  -1;
-  int maxHeight = -1;
-
-  int i;
-  for (i = 0 ; i < m_noItems; i++)
-  {
-    int eachWidth;
-    int eachHeight;
-    if (m_radioWidth[i]<0)
-    {
-      // It's a labelled toggle
-      GetWindowText((HWND) m_radioButtons[i], buf, 300);
-      GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont());
-      eachWidth = (int)(current_width + RADIO_SIZE);
-      eachHeight = (int)((3*cyf)/2);
-    }
-    else
+    int currentX, currentY;
+    GetPosition(¤tX, ¤tY);
+    int xx = x;
+    int yy = y;
+
+    if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        xx = currentX;
+    if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
+        yy = currentY;
+
+    wxString buf;
+
+    int y_offset = yy;
+    int x_offset = xx;
+    int current_width, cyf;
+
+    int cx1,cy1;
+    wxGetCharSize(m_hWnd, &cx1, &cy1, & GetFont());
+
+    // Attempt to have a look coherent with other platforms: We compute the
+    // biggest toggle dim, then we align all items according this value.
+    int maxWidth =  -1;
+    int maxHeight = -1;
+
+    int i;
+    for (i = 0 ; i < m_noItems; i++)
     {
-      eachWidth = m_radioWidth[i];
-      eachHeight = m_radioHeight[i];
+        int eachWidth;
+        int eachHeight;
+        if (m_radioWidth[i]<0)
+        {
+            // It's a labelled toggle
+            buf = wxGetWindowText(m_radioButtons[i]);
+            GetTextExtent(buf, ¤t_width, &cyf);
+            eachWidth = (int)(current_width + RADIO_SIZE);
+            eachHeight = (int)((3*cyf)/2);
+        }
+        else
+        {
+            eachWidth = m_radioWidth[i];
+            eachHeight = m_radioHeight[i];
+        }
+
+        if (maxWidth<eachWidth)
+            maxWidth = eachWidth;
+        if (maxHeight<eachHeight)
+            maxHeight = eachHeight;
     }
-    if (maxWidth<eachWidth) maxWidth = eachWidth;
-    if (maxHeight<eachHeight) maxHeight = eachHeight;
-  }
 
-  if (m_hWnd)
-  {
-    int totWidth;
-    int totHeight;
+    if (m_hWnd)
+    {
+        int totWidth;
+        int totHeight;
 
-    int nbHor = GetNumHor(),
+        int nbHor = GetNumHor(),
         nbVer = GetNumVer();
 
-    // this formula works, but I don't know why.
-    // Please, be sure what you do if you modify it!!
-    if (m_radioWidth[0]<0)
-      totHeight = (nbVer * maxHeight) + cy1/2;
-    else
-      totHeight = nbVer * (maxHeight+cy1/2);
-    totWidth  = nbHor * (maxWidth+cx1);
+        // this formula works, but I don't know why.
+        // Please, be sure what you do if you modify it!!
+        if (m_radioWidth[0]<0)
+            totHeight = (nbVer * maxHeight) + cy1/2;
+        else
+            totHeight = nbVer * (maxHeight+cy1/2);
+        totWidth  = nbHor * (maxWidth+cx1);
 
-#if (!CTL3D)
-    // Requires a bigger group box in plain Windows
-    MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+(3*cy1)/2,TRUE);
-#else
-    MoveWindow((HWND) m_hWnd,x_offset,y_offset,totWidth+cx1,totHeight+cy1,TRUE);
+        int extraHeight = cy1;
+
+#if !CTL3D
+        // Requires a bigger group box in plain Windows
+        extraHeight *= 3;
+        extraHeight /= 2;
 #endif
-    x_offset += cx1;
-    y_offset += cy1;
-  }
+
+        MoveWindow(GetHwnd(), x_offset, y_offset,
+                totWidth+cx1, totHeight+extraHeight,
+                TRUE);
+
+        x_offset += cx1;
+        y_offset += cy1;
+    }
 
 #if (!CTL3D)
-  y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
-                            // JACS 2/12/93. CTL3D draws group label quite high.
+    y_offset += (int)(cy1/2); // Fudge factor since buttons overlapped label
+    // JACS 2/12/93. CTL3D draws group label quite high.
 #endif
-  int startX = x_offset;
-  int startY = y_offset;
+    int startX = x_offset;
+    int startY = y_offset;
 
-  for ( i = 0 ; i < m_noItems; i++)
-  {
-    // Bidimensional radio adjustment
-    if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
+    for ( i = 0 ; i < m_noItems; i++)
     {
-      if (m_windowStyle & wxRA_VERTICAL)
-      {
-        y_offset = startY;
-        x_offset += maxWidth + cx1;
-      }
-      else
-      {
-        x_offset = startX;
-        y_offset += maxHeight;
-        if (m_radioWidth[0]>0)
-          y_offset += cy1/2;
-      }
-    }
-    int eachWidth;
-    int eachHeight;
-    if (m_radioWidth[i]<0)
-    {
-      // It's a labeled item
-      GetWindowText((HWND) m_radioButtons[i], buf, 300);
-      GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL, & GetFont());
-
-      // How do we find out radio button bitmap size!!
-      // By adjusting them carefully, manually :-)
-      eachWidth = (int)(current_width + RADIO_SIZE);
-      eachHeight = (int)((3*cyf)/2);
-    }
-    else
-    {
-      eachWidth = m_radioWidth[i];
-      eachHeight = m_radioHeight[i];
-    }
+        // Bidimensional radio adjustment
+        if (i&&((i%m_majorDim)==0)) // Why is this omitted for i = 0?
+        {
+            if (m_windowStyle & wxRA_VERTICAL)
+            {
+                y_offset = startY;
+                x_offset += maxWidth + cx1;
+            }
+            else
+            {
+                x_offset = startX;
+                y_offset += maxHeight;
+                if (m_radioWidth[0]>0)
+                    y_offset += cy1/2;
+            }
+        }
+        int eachWidth;
+        int eachHeight;
+        if (m_radioWidth[i]<0)
+        {
+            // It's a labeled item
+            buf = wxGetWindowText(m_radioButtons[i]);
+            GetTextExtent(buf, ¤t_width, &cyf);
+
+            // How do we find out radio button bitmap size!!
+            // By adjusting them carefully, manually :-)
+            eachWidth = (int)(current_width + RADIO_SIZE);
+            eachHeight = (int)((3*cyf)/2);
+        }
+        else
+        {
+            eachWidth = m_radioWidth[i];
+            eachHeight = m_radioHeight[i];
+        }
 
-    MoveWindow((HWND) m_radioButtons[i],x_offset,y_offset,eachWidth,eachHeight,TRUE);
-    if (m_windowStyle & wxRA_SPECIFY_ROWS)
-    {
-      y_offset += maxHeight;
-      if (m_radioWidth[0]>0)
-        y_offset += cy1/2;
+        MoveWindow((HWND)m_radioButtons[i], x_offset, y_offset,
+                   eachWidth, eachHeight,
+                   TRUE);
+
+        if (m_windowStyle & wxRA_SPECIFY_ROWS)
+        {
+            y_offset += maxHeight;
+            if (m_radioWidth[0]>0)
+                y_offset += cy1/2;
+        }
+        else
+            x_offset += maxWidth + cx1;
     }
-    else
-      x_offset += maxWidth + cx1;
-  }
 }
 
-
 void wxRadioBox::GetSize(int *width, int *height) const
 {
     RECT rect;
 
 
 int wxSlider95::GetValue() const
 {
-  return ::SendMessage((HWND) GetHWND(), TBM_GETPOS, 0, 0);
+  return ::SendMessage(GetHwnd(), TBM_GETPOS, 0, 0);
 }
 
 void wxSlider95::SetValue(int value)
 {
-  ::SendMessage((HWND) GetHWND(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
+  ::SendMessage(GetHwnd(), TBM_SETPOS, (WPARAM)TRUE, (LPARAM)value);
   if (m_staticValue)
   {
     wxSprintf(wxBuffer, _T("%d"), value);
   *y = point.y;
 }
 
+// TODO one day, make sense of all this horros and replace it with a readable
+//      DoGetBestSize()
 void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
   int x1 = x;
     if (slider_length < 100)
       slider_length = 100;
 
-    MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE);
+    MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
     x_offset += slider_length + cx;
 
     MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
             w1 = 200;
         if ( h1 < 0 )
             h1 = 20;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
   else
     if (slider_length < 100)
       slider_length = 100;
 
-    MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE);
+    MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
     y_offset += slider_length;
 
     MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
             w1 = 20;
         if ( h1 < 0 )
             h1 = 200;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
 }
   m_rangeMin = minValue;
   m_rangeMax = maxValue;
 
-  ::SendMessage((HWND) GetHWND(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
+  ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
 
   wxChar buf[40];
   if ( m_staticMin )
 void wxSlider95::SetTickFreq(int n, int pos)
 {
   m_tickFreq = n;
-  ::SendMessage( (HWND) GetHWND(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
+  ::SendMessage( GetHwnd(), TBM_SETTICFREQ, (WPARAM) n, (LPARAM) pos );
 }
 
 void wxSlider95::SetPageSize(int pageSize)
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
+  ::SendMessage( GetHwnd(), TBM_SETPAGESIZE, (WPARAM) 0, (LPARAM) pageSize );
   m_pageSize = pageSize;
 }
 
 
 void wxSlider95::ClearSel()
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
+  ::SendMessage( GetHwnd(), TBM_CLEARSEL, (WPARAM) TRUE, (LPARAM) 0 );
 }
 
 void wxSlider95::ClearTicks()
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
+  ::SendMessage( GetHwnd(), TBM_CLEARTICS, (WPARAM) TRUE, (LPARAM) 0 );
 }
 
 void wxSlider95::SetLineSize(int lineSize)
 {
   m_lineSize = lineSize;
-  ::SendMessage( (HWND) GetHWND(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
+  ::SendMessage( GetHwnd(), TBM_SETLINESIZE, (WPARAM) 0, (LPARAM) lineSize );
 }
 
 int wxSlider95::GetLineSize() const
 {
-  return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 );
+  return (int) ::SendMessage( GetHwnd(), TBM_GETLINESIZE, (WPARAM) 0, (LPARAM) 0 );
 }
 
 int wxSlider95::GetSelEnd() const
 {
-  return (int) ::SendMessage( (HWND) GetHWND(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 );
+  return (int) ::SendMessage( GetHwnd(), TBM_SETSELEND, (WPARAM) 0, (LPARAM) 0 );
 }
 
 int wxSlider95::GetSelStart() const
 {
-  return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 );
+  return (int) ::SendMessage( GetHwnd(), TBM_GETSELSTART, (WPARAM) 0, (LPARAM) 0 );
 }
 
 void wxSlider95::SetSelection(int minPos, int maxPos)
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
+  ::SendMessage( GetHwnd(), TBM_SETSEL, (WPARAM) TRUE, (LPARAM) MAKELONG( minPos, maxPos) );
 }
 
 void wxSlider95::SetThumbLength(int len)
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
+  ::SendMessage( GetHwnd(), TBM_SETTHUMBLENGTH, (WPARAM) len, (LPARAM) 0 );
 }
 
 int wxSlider95::GetThumbLength() const
 {
-  return (int) ::SendMessage( (HWND) GetHWND(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 );
+  return (int) ::SendMessage( GetHwnd(), TBM_GETTHUMBLENGTH, (WPARAM) 0, (LPARAM) 0 );
 }
 
 void wxSlider95::SetTick(int tickPos)
 {
-  ::SendMessage( (HWND) GetHWND(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
+  ::SendMessage( GetHwnd(), TBM_SETTIC, (WPARAM) 0, (LPARAM) tickPos );
 }
 
 bool wxSlider95::ContainsHWND(WXHWND hWnd) const
 
 
 int wxSliderMSW::GetValue() const
 {
-  return ::GetScrollPos((HWND) GetHWND(), SB_CTL);
+  return ::GetScrollPos(GetHwnd(), SB_CTL);
 }
 
 void wxSliderMSW::SetValue(int value)
 {
-  ::SetScrollPos((HWND) GetHWND(), SB_CTL, value, TRUE);
+  ::SetScrollPos(GetHwnd(), SB_CTL, value, TRUE);
   if (m_staticValue)
   {
     wxSprintf(wxBuffer, _T("%d"), value);
   *y = point.y;
 }
 
+// TODO one day, make sense of all this horros and replace it with a readable
+//      DoGetBestSize()
 void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
   int x1 = x;
     if (slider_length < 100)
       slider_length = 100;
 
-    MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_length, slider_height, TRUE);
+    MoveWindow(GetHwnd(), x_offset, y_offset, slider_length, slider_height, TRUE);
     x_offset += slider_length + cx;
 
     MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
             w1 = 200;
         if ( h1 < 0 )
             h1 = 20;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
   else
     if (slider_length < 100)
       slider_length = 100;
 
-    MoveWindow((HWND) GetHWND(), x_offset, y_offset, slider_width, slider_length, TRUE);
+    MoveWindow(GetHwnd(), x_offset, y_offset, slider_width, slider_length, TRUE);
     y_offset += slider_length;
 
     MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE);
             w1 = 20;
         if ( h1 < 0 )
             h1 = 200;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
 }
   m_rangeMin = minValue;
   m_rangeMax = maxValue;
 
-  ::SetScrollRange((HWND) GetHWND(), SB_CTL, m_rangeMin, m_rangeMax, TRUE);
+  ::SetScrollRange(GetHwnd(), SB_CTL, m_rangeMin, m_rangeMax, TRUE);
   wxChar buf[40];
   if ( m_staticMin )
   {
 
     m_image.icon = NULL;
 }
 
-void wxStaticBitmap::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxStaticBitmap::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(¤tX, ¤tY);
-    int x1 = x;
-    int y1 = y;
-
-    if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        x1 = currentX;
-    if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        y1 = currentY;
-
-    AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-    int actualWidth = width;
-    int actualHeight = height;
-
-    int ww, hh;
-    GetSize(&ww, &hh);
-
-    // If we're prepared to use the existing width, then...
-    if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
-        actualWidth = ww;
-    else
-        actualWidth = width;
-
-    // If we're prepared to use the existing height, then...
-    if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
-        actualHeight = hh;
-    else
-        actualHeight = height;
-
-    MoveWindow((HWND) GetHWND(), x1, y1, actualWidth, actualHeight, TRUE);
+    // reuse the current size (as wxWindow does) instead of using some
+    // arbitrary default size (as wxControl, our immediate base class, does)
+    return wxWindow::DoGetBestSize();
 }
 
 void wxStaticBitmap::SetBitmap(const wxBitmap& bitmap)
 
   return TRUE;
 }
 
-void wxStaticBox::SetLabel(const wxString& label)
+wxSize wxStaticBox::DoGetBestSize()
 {
-  SetWindowText((HWND)m_hWnd, (const wxChar *)label);
-}
-
-void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
+    int cx, cy;
+    wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
 
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
+    int wBox;
+    GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
 
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
-
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  // If we're prepared to use the existing size, then...
-  if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-  {
-    GetSize(&w1, &h1);
-  }
+    wBox += 3*cx;
+    int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
 
-  int current_width;
-
-  int cx;
-  int cy;
-  int cyf;
-
-  wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
+    return wxSize(wBox, hBox);
+}
 
-  GetTextExtent(wxGetWindowText(m_hWnd), ¤t_width, &cyf,
-                NULL,NULL, & this->GetFont());
-  if ( w1 < 0 )
-   w1 = current_width + 3*cx;
-  if ( h1 < 0 )
-    h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf);
+void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+{
+    wxControl::DoSetSize(x, y, width, height, sizeFlags);
 
-  MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE);
+    // the static box should always be on the bottom of the Z-order, otherwise
+    // it may hide controls which are positioned inside it
+    if ( !::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0,
+                         SWP_NOMOVE | SWP_NOSIZE) )
+    {
+        wxLogLastError(_T("SetWindowPos"));
+    }
 }
 
 WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
 
         RECT rect;
 
-        ::GetClientRect((HWND) GetHWND(), &rect);
+        ::GetClientRect(GetHwnd(), &rect);
         ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
         ::DeleteObject(hBrush);
         ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
 
 long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 {
-    if (nMsg == WM_NCHITTEST)
+    if ( 0 )//nMsg == WM_NCHITTEST)
     {
         int xPos = LOWORD(lParam);  // horizontal position of cursor
         int yPos = HIWORD(lParam);  // vertical position of cursor
 
   return TRUE;
 }
 
-void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxStaticText::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(¤tX, ¤tY);
-
-    int x1 = x;
-    int y1 = y;
-
-    if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        x1 = currentX;
-    if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-        y1 = currentY;
-
-    AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-    int actualWidth = width;
-    int actualHeight = height;
-
     wxString text(wxGetWindowText(GetHWND()));
 
     int widthTextMax = 0, widthLine,
         }
     }
 
-    int ww, hh;
-    GetSize(&ww, &hh);
-
-    // If we're prepared to use the existing width, then...
-    if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))
-    {
-        actualWidth = ww;
-    }
-    else if (width == -1)
-    {
-        actualWidth = widthTextMax;
-    }
-    
-    // If we're prepared to use the existing height, then...
-    if (height == -1 && ((sizeFlags & wxSIZE_AUTO_HEIGHT) != wxSIZE_AUTO_HEIGHT))
-    {
-        actualHeight = hh;
-    }
-    else if (height == -1)
-    {
-        actualHeight = heightTextTotal;
-    }
-    
-    MoveWindow(GetHwnd(), x1, y1, actualWidth, actualHeight, TRUE);
+    return wxSize(widthTextMax, heightTextTotal);
 }
 
 void wxStaticText::SetLabel(const wxString& label)
 {
     SetWindowText(GetHwnd(), label);
 
+    // adjust the size of the window to fit to the label (this behaviour is
+    // backward compatible and generally makes sense but we might want to still
+    // provide the user a way to disable it) (VZ)
     DoSetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH | wxSIZE_AUTO_HEIGHT);
 }
 
 
   AdjustSpaceLimit();
 }
 
-void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxTextCtrl::DoGetBestSize()
 {
-  int currentX, currentY;
-  GetPosition(¤tX, ¤tY);
-  int x1 = x;
-  int y1 = y;
-  int w1 = width;
-  int h1 = height;
+    int cx, cy;
+    wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
 
-  if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    x1 = currentX;
-  if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
-    y1 = currentY;
+    int wText = DEFAULT_ITEM_WIDTH;
+    int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
 
-  AdjustForParentClientOrigin(x1, y1, sizeFlags);
-
-  int cx; // button font dimensions
-  int cy;
-
-  wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
-
-  int control_width, control_height, control_x, control_y;
-
-  // If we're prepared to use the existing size, then...
-  if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
-  {
-    GetSize(&w1, &h1);
-  }
-
-  // Deal with default size (using -1 values)
-  if (w1<=0)
-    w1 = DEFAULT_ITEM_WIDTH;
-
-  control_x = x1;
-  control_y = y1;
-  control_width = w1;
-  control_height = h1;
-
-  // Calculations may have made text size too small
-  if (control_height <= 0)
-    control_height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
-
-  if (control_width <= 0)
-    control_width = DEFAULT_ITEM_WIDTH;
-
-  MoveWindow(GetHwnd(), (int)control_x, (int)control_y,
-                              (int)control_width, (int)control_height, TRUE);
+    return wxSize(wText, hText);
 }
 
 // Clipboard operations
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
     long charIndex = XYToPosition(0, lineNo);
-    HWND hWnd = GetHwnd();
-    int len = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0);
+    int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
     return len;
 }
 
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
-    HWND hWnd = GetHwnd();
-    *(WORD *)wxBuffer = 512;
-    int noChars = (int)SendMessage(hWnd, EM_GETLINE, (WPARAM)lineNo, (LPARAM)wxBuffer);
-    wxBuffer[noChars] = 0;
-  return wxString(wxBuffer);
+    size_t len = (size_t)GetLineLength(lineNo);
+    char *buf = (char *)malloc(len);
+    *(WORD *)buf = len;
+    int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
+    buf[noChars] = 0;
+
+    wxString str(buf);
+
+    free(buf);
+
+    return str;
 }
 
 bool wxTextCtrl::CanCopy() const
 
         *y = rect.bottom;
 }
 
+// set the size of the window: if the dimensions are positive, just use them,
+// but if any of them is equal to -1, it means that we must find the value for
+// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
+// which case -1 is a valid value for x and y)
+//
+// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
+// the width/height to best suit our contents, otherwise we reuse the current
+// width/height
 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
+    // get the current size and position...
     int currentX, currentY;
     GetPosition(¤tX, ¤tY);
     int currentW,currentH;
     GetSize(¤tW, ¤tH);
 
-    if ( x == currentX && y == currentY && width == currentW && height == currentH )
+    // ... and don't do anything (avoiding flicker) if it's already ok
+    if ( x == currentX && y == currentY &&
+         width == currentW && height == currentH )
+    {
         return;
+    }
 
-    int actualWidth = width;
-    int actualHeight = height;
-    int actualX = x;
-    int actualY = y;
     if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
-        actualX = currentX;
+        x = currentX;
     if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
-        actualY = currentY;
+        y = currentY;
 
-    AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
+    AdjustForParentClientOrigin(x, y, sizeFlags);
 
+    wxSize size(-1, -1);
     if ( width == -1 )
-        actualWidth = currentW;
+    {
+        if ( sizeFlags && wxSIZE_AUTO_WIDTH )
+        {
+            size = DoGetBestSize();
+            width = size.x;
+        }
+        else
+        {
+            // just take the current one
+            width = currentW;
+        }
+    }
+
     if ( height == -1 )
-        actualHeight = currentH;
+    {
+        if ( sizeFlags && wxSIZE_AUTO_HEIGHT )
+        {
+            if ( size.x == -1 )
+            {
+                size= DoGetBestSize();
+            }
+            //else: already called DoGetBestSize() above
 
-    HWND hWnd = GetHwnd();
-    if ( hWnd )
-        MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE);
+            height = size.y;
+        }
+        else
+        {
+            // just take the current one
+            height = currentH;
+        }
+    }
+
+    if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
+    {
+        wxLogLastError("MoveWindow");
+    }
+}
+
+// for a generic window there is no natural best size - just use the current one
+wxSize wxWindow::DoGetBestSize()
+{
+    return GetSize();
 }
 
 void wxWindow::DoSetClientSize(int width, int height)
 
     SIZE sizeRect;
     TEXTMETRIC tm;
-    GetTextExtentPoint(dc, (const wxChar *)string, (int)string.Length(), &sizeRect);
+    GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
     GetTextMetrics(dc, &tm);
 
     if ( fontToUse && fnt && hfontOld )