]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/msw/subwin.h
rename wxRendererNative::DrawRadioButton() to DrawOptionButton() to avoid conflict...
[wxWidgets.git] / include / wx / msw / subwin.h
index 61620abff732cb266873dfc5f3962b849fe6aad9..27f5f714cc170a1b7b6eebbcbf11d4b819232c93 100644 (file)
@@ -18,7 +18,7 @@
 // wxSubwindows contains all HWNDs making part of a single wx control
 // ----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxSubwindows
+class WXDLLIMPEXP_CORE wxSubwindows
 {
 public:
     // the number of subwindows can be specified either as parameter to ctor or
@@ -32,6 +32,7 @@ public:
 
         m_count = n;
         m_hwnds = (HWND *)calloc(n, sizeof(HWND));
+        m_ids = new wxWindowIDRef[n];
     }
 
     // non-virtual dtor, this class is not supposed to be used polymorphically
@@ -39,10 +40,12 @@ public:
     {
         for ( size_t n = 0; n < m_count; n++ )
         {
-            ::DestroyWindow(m_hwnds[n]);
+            if ( m_hwnds[n] )
+                ::DestroyWindow(m_hwnds[n]);
         }
 
         free(m_hwnds);
+        delete [] m_ids;
     }
 
     // get the number of subwindows
@@ -56,10 +59,19 @@ public:
         return m_hwnds[n];
     }
 
-    HWND& operator[](size_t n) { return Get(n); }
     HWND operator[](size_t n) const
     {
-        return wx_const_cast(wxSubwindows *, this)->Get(n);
+        return const_cast<wxSubwindows *>(this)->Get(n);
+    }
+
+    // initialize the given window: id will be stored in wxWindowIDRef ensuring
+    // that it is not reused while this object exists
+    void Set(size_t n, HWND hwnd, wxWindowID id)
+    {
+        wxASSERT_MSG( n < m_count, _T("subwindow index out of range") );
+
+        m_hwnds[n] = hwnd;
+        m_ids[n] = id;
     }
 
     // check if we have this window
@@ -84,7 +96,18 @@ public:
         int sw = show ? SW_SHOW : SW_HIDE;
         for ( size_t n = 0; n < m_count; n++ )
         {
-            ::ShowWindow(m_hwnds[n], sw);
+            if ( m_hwnds[n] )
+                ::ShowWindow(m_hwnds[n], sw);
+        }
+    }
+
+    // enable/disable everything
+    void Enable(bool enable)
+    {
+        for ( size_t n = 0; n < m_count; n++ )
+        {
+            if ( m_hwnds[n] )
+                ::EnableWindow(m_hwnds[n], enable);
         }
     }
 
@@ -96,7 +119,13 @@ public:
 
         for ( size_t n = 0; n < m_count; n++ )
         {
-            ::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0);
+            if ( m_hwnds[n] )
+            {
+                ::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0);
+
+                // otherwise the window might not be redrawn correctly
+                ::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */);
+            }
         }
     }
 
@@ -106,10 +135,14 @@ public:
         wxRect r;
         for ( size_t n = 0; n < m_count; n++ )
         {
-            RECT rc;
-            ::GetWindowRect(m_hwnds[n], &rc);
+            if ( m_hwnds[n] )
+            {
+                RECT rc;
+
+                ::GetWindowRect(m_hwnds[n], &rc);
 
-            r.Union(wxRectFromRECT(rc));
+                r.Union(wxRectFromRECT(rc));
+            }
         }
 
         return r;
@@ -128,9 +161,59 @@ private:
     // the HWNDs we contain
     HWND *m_hwnds;
 
+    // the IDs of the windows
+    wxWindowIDRef *m_ids;
+
 
     DECLARE_NO_COPY_CLASS(wxSubwindows)
 };
 
+// convenient macro to forward a few methods which are usually propagated to
+// subwindows to a wxSubwindows object
+//
+// parameters should be:
+//  - cname the name of the class implementing these methods
+//  - base the name of its base class
+//  - subwins the name of the member variable of type wxSubwindows *
+#define WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(cname, base, subwins)            \
+    bool cname::ContainsHWND(WXHWND hWnd) const                               \
+    {                                                                         \
+        return subwins && subwins->HasWindow((HWND)hWnd);                     \
+    }                                                                         \
+                                                                              \
+    bool cname::Show(bool show)                                               \
+    {                                                                         \
+        if ( !base::Show(show) )                                              \
+            return false;                                                     \
+                                                                              \
+        if ( subwins )                                                        \
+            subwins->Show(show);                                              \
+                                                                              \
+        return true;                                                          \
+    }                                                                         \
+                                                                              \
+    bool cname::Enable(bool enable)                                           \
+    {                                                                         \
+        if ( !base::Enable(enable) )                                          \
+            return false;                                                     \
+                                                                              \
+        if ( subwins )                                                        \
+            subwins->Enable(enable);                                          \
+                                                                              \
+        return true;                                                          \
+    }                                                                         \
+                                                                              \
+    bool cname::SetFont(const wxFont& font)                                   \
+    {                                                                         \
+        if ( !base::SetFont(font) )                                           \
+            return false;                                                     \
+                                                                              \
+        if ( subwins )                                                        \
+            subwins->SetFont(font);                                           \
+                                                                              \
+        return true;                                                          \
+    }
+
+
 #endif // _WX_MSW_SUBWIN_H_