]> git.saurik.com Git - wxWidgets.git/commitdiff
1. DoSetSize() simplified, DoGetBestSize() introduced
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 2 Jul 1999 22:02:05 +0000 (22:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 2 Jul 1999 22:02:05 +0000 (22:02 +0000)
2. code cleanup here and there
3. attempts to make static boxes behave better (i.e. stay below other controls)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

30 files changed:
include/wx/msw/button.h
include/wx/msw/checkbox.h
include/wx/msw/choice.h
include/wx/msw/combobox.h
include/wx/msw/control.h
include/wx/msw/gauge95.h
include/wx/msw/gaugemsw.h
include/wx/msw/listbox.h
include/wx/msw/statbmp.h
include/wx/msw/statbox.h
include/wx/msw/stattext.h
include/wx/msw/textctrl.h
include/wx/msw/window.h
src/msw/button.cpp
src/msw/checkbox.cpp
src/msw/choice.cpp
src/msw/combobox.cpp
src/msw/control.cpp
src/msw/frame.cpp
src/msw/gauge95.cpp
src/msw/gaugemsw.cpp
src/msw/listbox.cpp
src/msw/radiobox.cpp
src/msw/slider95.cpp
src/msw/slidrmsw.cpp
src/msw/statbmp.cpp
src/msw/statbox.cpp
src/msw/stattext.cpp
src/msw/textctrl.cpp
src/msw/window.cpp

index cd0e1df3859b49a4c080ffe5c2a96f3c03ee48bf..4d78ab2d4013e3290bcb529e17465c1828fa82e4 100644 (file)
@@ -63,9 +63,7 @@ protected:
     // 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
index 90e562511952d5ec14892d4fa1eac16a7084bf48..7bcd8ef308b9338dbd5dc75cfa970342297a9934 100644 (file)
@@ -53,9 +53,7 @@ public:
             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
@@ -82,15 +80,7 @@ public:
             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_
index 2870c78b71a41ae008ab35b358df6754f124ec0d..7cdfa9a577e53b2dfae672addec2453189c4be10 100644 (file)
@@ -73,9 +73,10 @@ public:
 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
index a44538e7ff5633615260b9e1c45b36de46c1b6b2..52e8a9d6dbc590f196f13645620716a216e89a47 100644 (file)
@@ -6,14 +6,14 @@
 // 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
index 446d49f3332e67b73a2a133de7a42bca81bfefc1..b4a280754370f332fee323589ed73ea833d8f1e7 100644 (file)
@@ -69,6 +69,8 @@ protected:
    // For controls like radiobuttons which are really composite
    wxList           m_subControls;
 
+    virtual wxSize DoGetBestSize();
+
 private:
    DECLARE_EVENT_TABLE()
 };
index 0bab3e716331fd4e18493598dc6e4178b533cc91..11e77bc685ed38c994afed7716ecd0685abbd619 100644 (file)
@@ -70,10 +70,6 @@ public:
 protected:
     int      m_rangeMax;
     int      m_gaugePos;
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
index 60e2fc1702b7b6fbc366db815c2a5fd886a556be..7f0a1f39f3881939ceb22255b7c774583a901a63 100644 (file)
@@ -70,10 +70,6 @@ public:
 protected:
     int      m_rangeMax;
     int      m_gaugePos;
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
index 0272e7e047ab927aa52039552db13a5a07c0d48d..03f08992db745bcd8618841a04aa78f3964b9df5 100644 (file)
@@ -133,10 +133,6 @@ protected:
     // control items
     wxListBoxItemsArray m_aItems;
 #endif
-
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
 };
 
 #endif
index 6c0669b806ad1a393d349d9840cc39af7899c083..4da9e6f89d9da8b30d86befb6421bd3467dd6660 100644 (file)
@@ -83,9 +83,7 @@ protected:
         wxBitmap *bitmap;
     } m_image;
 
-    virtual void DoSetSize(int x, int y,
-                           int width, int height,
-                           int sizeFlags = wxSIZE_AUTO);
+    virtual wxSize DoGetBestSize();
 };
 
 #endif
index 361fc3608f7b3def97baf8155f975d531fbdb21d..87393c2f47a16a17339d8065ba5aa0d7ef5b571f 100644 (file)
@@ -24,7 +24,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxStaticBoxNameStr;
 class WXDLLEXPORT wxStaticBox : public wxControl
 {
 DECLARE_DYNAMIC_CLASS(wxStaticBox)
-        
+
 public:
     wxStaticBox() { }
 
@@ -37,30 +37,32 @@ public:
     {
         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()
index e59beeab30012cacabeba4a10048237e6b9aec2c..f21a4bd3b0873ac5300cb331e7013625ab2126ee 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     01/02/97
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifndef _WX_STATTEXT_H_
@@ -26,7 +26,7 @@ DECLARE_DYNAMIC_CLASS(wxStaticText)
 
 public:
     wxStaticText() { }
-    
+
     wxStaticText(wxWindow *parent, wxWindowID id,
         const wxString& label,
         const wxPoint& pos = wxDefaultPosition,
@@ -36,29 +36,27 @@ public:
     {
         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
index 40dbcad9e4d43656fecf3894e48218b7f0b2496d..af31bad26ff011eea8808d976ec2a8e94e4c19cb 100644 (file)
@@ -59,7 +59,8 @@ public:
     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
@@ -72,13 +73,15 @@ public:
     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;
@@ -148,25 +151,9 @@ public:
     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);
 
@@ -184,6 +171,23 @@ public:
 
     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?
@@ -195,9 +199,7 @@ protected:
     // 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()
index 0cfca8bfc5cd86b60c45d4b071afae97ec592f2e..33f358e879b411ce583da7566b24e2f6af30cd29 100644 (file)
@@ -399,6 +399,10 @@ protected:
                            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
index 1d8bbaf9902dac003a6316938b9cce64e5ae3e68..1a34a34d0e659c360d2be3fddb9c2bbfdfc31abf 100644 (file)
@@ -113,55 +113,28 @@ wxButton::~wxButton()
 // size management including autosizing
 // ----------------------------------------------------------------------------
 
-void wxButton::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxButton::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(&currentX, &currentY);
-    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, &current_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();
index 89f0c52cca36848e9b2b288210c7cad89d26187b..e8d646892ccca312a106bfb68fcaefd37c78221e 100644 (file)
@@ -6,39 +6,59 @@
 // 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
@@ -48,126 +68,102 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
            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(&currentX, &currentY);
-  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, &current_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
@@ -177,20 +173,20 @@ void wxCheckBox::SetValue(bool val)
 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
@@ -217,6 +213,10 @@ void wxCheckBox::Command (wxCommandEvent & event)
   ProcessCommand (event);
 }
 
+// ----------------------------------------------------------------------------
+// wxBitmapCheckBox
+// ----------------------------------------------------------------------------
+
 bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *label,
            const wxPoint& pos,
            const wxSize& size, long style,
@@ -231,10 +231,10 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
   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;
@@ -254,7 +254,7 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
   if (!(GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS))
   {
     Ctl3dSubclassCtl(wx_button);
-         m_useCtl3D = TRUE;
+    m_useCtl3D = TRUE;
   }
 #endif
 
@@ -263,53 +263,14 @@ bool wxBitmapCheckBox::Create(wxWindow *parent, wxWindowID id, const wxBitmap *l
   // 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(&currentX, &currentY);
-
-  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);
-}
-
-
index 3f349227d3d863b8ed88c5aed305ab92b5d1120c..6bcec7b964a08ad19b9ebe563a95af2a1095dc44 100644 (file)
@@ -123,19 +123,19 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
 
 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;
 }
@@ -143,12 +143,12 @@ void wxChoice::Clear(void)
 
 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
@@ -159,14 +159,14 @@ 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
@@ -176,99 +176,60 @@ int wxChoice::FindString(const wxString& s) const
 
 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(&currentX, &currentY);
-
-  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,
index f7eff22ed65d83f750eafb613e36fc41101b9eee..7104620710ec301f820186d4a536fb4e63c2a093 100644 (file)
@@ -146,11 +146,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
   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.
@@ -177,43 +172,43 @@ void wxComboBox::SetValue(const wxString& value)
       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);
@@ -236,7 +231,7 @@ void wxComboBox::SetInsertionPointEnd()
 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;
@@ -245,14 +240,14 @@ long wxComboBox::GetInsertionPoint() const
 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);
@@ -265,10 +260,10 @@ long wxComboBox::GetLastPosition() const
 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);
@@ -287,10 +282,10 @@ void wxComboBox::Replace(long from, long to, const wxString& value)
 
 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);
@@ -302,7 +297,7 @@ void wxComboBox::Remove(long from, long to)
 
 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
@@ -313,7 +308,7 @@ void wxComboBox::SetSelection(long from, long to)
       fromChar = 0;
       toChar = -1;
     }
-    
+
 #ifdef __WIN32__
     SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
 //    SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
@@ -323,6 +318,22 @@ void wxComboBox::SetSelection(long from, long to)
 #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
 
index 7f609f7bd6b00841a116122225fa38a01e81a4a3..b8ccc635511b9163b45cec00c72c2a64a899043f 100644 (file)
@@ -58,6 +58,11 @@ wxControl::~wxControl()
     m_isBeingDeleted = TRUE;
 }
 
+wxSize wxControl::DoGetBestSize()
+{
+    return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
+}
+
 bool wxControl::ProcessCommand(wxCommandEvent& event)
 {
 #if WXWIN_COMPATIBILITY
index 82d435e254251ba93ba0b0e248d8645e0a38e4a8..91ccc08d19b86a0d5a013c519853c66bbe94b1c8 100644 (file)
@@ -241,28 +241,11 @@ void wxFrame::DoGetPosition(int *x, int *y) const
 
 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(&currentX, &currentY);
-  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)
index e5c09362e280fdd46791e162b5a345356fd22d32..ade3fdca7ce4924ee623022fbb892fb1f40c773c 100644 (file)
@@ -58,9 +58,9 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
   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;
@@ -108,38 +108,6 @@ bool wxGauge95::Create(wxWindow *parent, wxWindowID id,
   return TRUE;
 }
 
-void wxGauge95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-  int currentX, currentY;
-  GetPosition(&currentX, &currentY);
-  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)
 {
 }
index 138ac9eaf7300566b16601c80f3f64655b4e75fa..1af85748f9d9c671216f3f28b33a198f9e1ddcd3 100644 (file)
@@ -126,8 +126,8 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id,
   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());
 
@@ -137,85 +137,53 @@ bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id,
     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(&currentX, &currentY);
-  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)
@@ -223,7 +191,7 @@ 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;
 }
@@ -233,7 +201,7 @@ bool wxGaugeMSW::SetBackgroundColour(const wxColour& col)
     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;
 }
index 6ef3532c9f7a507a380261cb5b5488a5197a5256..b14384f8cffcb482d82dba25acc709798c8e5b70 100644 (file)
@@ -518,65 +518,8 @@ wxString wxListBox::GetString(int N) const
     return result;
 }
 
-void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
-    int currentX, currentY;
-    GetPosition(&currentX, &currentY);
-
-    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)
 {
index ebd76b52bb16acbc46be9d0252a43da1bc2459c4..f0ab1b8a2db7fd0ce84459705699278549e5f8e2 100644 (file)
@@ -351,135 +351,146 @@ wxString wxRadioBox::GetString(int N) const
 // Restored old code.
 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
 {
-  int currentX, currentY;
-  GetPosition(&currentX, &currentY);
-  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, &current_width, &cyf,NULL,NULL, & GetFont());
-      eachWidth = (int)(current_width + RADIO_SIZE);
-      eachHeight = (int)((3*cyf)/2);
-    }
-    else
+    int currentX, currentY;
+    GetPosition(&currentX, &currentY);
+    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, &current_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, &current_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, &current_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;
index 7bfe7c1a797cd11cb673cad21aff98e11c72156e..ad622b84fdf3a26efddc29622580ba48e900c225 100644 (file)
@@ -277,12 +277,12 @@ wxSlider95::~wxSlider95()
 
 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);
@@ -344,6 +344,8 @@ void wxSlider95::GetPosition(int *x, int *y) const
   *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;
@@ -413,7 +415,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
     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);
@@ -430,7 +432,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
             w1 = 200;
         if ( h1 < 0 )
             h1 = 20;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
   else
@@ -479,7 +481,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
     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);
@@ -496,7 +498,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags)
             w1 = 20;
         if ( h1 < 0 )
             h1 = 200;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
 }
@@ -506,7 +508,7 @@ void wxSlider95::SetRange(int minValue, int maxValue)
   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 )
@@ -545,12 +547,12 @@ WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
 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;
 }
 
@@ -561,53 +563,53 @@ int wxSlider95::GetPageSize() const
 
 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
index fb14495286bc5b45c575d6a3845379ac46503dc7..18f85538ea4c72501f3b8fd917eed528e20347c1 100644 (file)
@@ -248,12 +248,12 @@ wxSliderMSW::~wxSliderMSW()
 
 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);
@@ -315,6 +315,8 @@ void wxSliderMSW::GetPosition(int *x, int *y) const
   *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;
@@ -379,7 +381,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
     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);
@@ -391,7 +393,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
             w1 = 200;
         if ( h1 < 0 )
             h1 = 20;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
   else
@@ -435,7 +437,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
     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);
@@ -447,7 +449,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
             w1 = 20;
         if ( h1 < 0 )
             h1 = 200;
-        MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE);
+        MoveWindow(GetHwnd(), x1, y1, w1, h1, TRUE);
     }
   }
 }
@@ -457,7 +459,7 @@ void wxSliderMSW::SetRange(int minValue, int maxValue)
   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 )
   {
index c22387c146c932fd2c23b2de7cb5f427bde22341..200e920bd85e28294c65ca7880f58ea12495d825 100644 (file)
@@ -140,39 +140,11 @@ void wxStaticBitmap::Free()
     m_image.icon = NULL;
 }
 
-void wxStaticBitmap::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxStaticBitmap::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(&currentX, &currentY);
-    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)
index 6ca6074e54a9fdcdcc33e99a471fa941ec08b9e9..686762f3bde51f4c60229058ec74552e6fccf11b 100644 (file)
@@ -99,50 +99,31 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
   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(&currentX, &currentY);
+    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), &current_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,
@@ -202,7 +183,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
 
         RECT rect;
 
-        ::GetClientRect((HWND) GetHWND(), &rect);
+        ::GetClientRect(GetHwnd(), &rect);
         ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
         ::DeleteObject(hBrush);
         ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
@@ -215,7 +196,7 @@ void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
 
 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
index da9906d9881f95fa5d42527de4c3c2b930f0b68f..31c7c0141b653a463ab145b0437edecc8effc42c 100644 (file)
@@ -94,24 +94,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
   return TRUE;
 }
 
-void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxStaticText::DoGetBestSize()
 {
-    int currentX, currentY;
-    GetPosition(&currentX, &currentY);
-
-    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,
@@ -138,36 +122,16 @@ void wxStaticText::DoSetSize(int x, int y, int width, int height, int sizeFlags)
         }
     }
 
-    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);
 }
 
index 97dfca82bdc28f4dd4b4c354f7de3ad07ecd125a..9fdb36b9efb813a89313b0f2596e2c9879599e8f 100644 (file)
@@ -336,53 +336,15 @@ void wxTextCtrl::SetValue(const wxString& value)
   AdjustSpaceLimit();
 }
 
-void wxTextCtrl::DoSetSize(int x, int y, int width, int height, int sizeFlags)
+wxSize wxTextCtrl::DoGetBestSize()
 {
-  int currentX, currentY;
-  GetPosition(&currentX, &currentY);
-  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
@@ -759,18 +721,23 @@ void wxTextCtrl::ShowPosition(long pos)
 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
index dd54ee8e9b469e6a5d1608c7d716c7ddd94267f0..c7a84bd1f82af4bc6cfae14620c6470ab92d4533 100644 (file)
@@ -1172,35 +1172,80 @@ void wxWindow::DoGetClientSize(int *x, int *y) 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(&currentX, &currentY);
     int currentW,currentH;
     GetSize(&currentW, &currentH);
 
-    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)
@@ -1316,7 +1361,7 @@ void wxWindow::GetTextExtent(const wxString& string,
 
     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 )