X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7249080588e30b4740adc138e793ffa0ead4b5ef..d298f18ffb4bd0bd758b10f34c9e01cd119d1365:/include/wx/msw/subwin.h diff --git a/include/wx/msw/subwin.h b/include/wx/msw/subwin.h index cf149b7382..90be4841a1 100644 --- a/include/wx/msw/subwin.h +++ b/include/wx/msw/subwin.h @@ -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 @@ -28,10 +28,11 @@ public: // allocate enough space for the given number of windows void Create(size_t n) { - wxASSERT_MSG( !m_hwnds, _T("Create() called twice?") ); + wxASSERT_MSG( !m_hwnds, wxT("Create() called twice?") ); 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 @@ -51,15 +54,24 @@ public: // access a given window HWND& Get(size_t n) { - wxASSERT_MSG( n < m_count, _T("subwindow index out of range") ); + wxASSERT_MSG( n < m_count, wxT("subwindow index out of range") ); 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(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, wxT("subwindow index out of range") ); + + m_hwnds[n] = hwnd; + m_ids[n] = id; } // check if we have this window @@ -84,7 +96,8 @@ 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); } } @@ -93,7 +106,8 @@ public: { for ( size_t n = 0; n < m_count; n++ ) { - ::EnableWindow(m_hwnds[n], enable); + if ( m_hwnds[n] ) + ::EnableWindow(m_hwnds[n], enable); } } @@ -101,14 +115,17 @@ public: void SetFont(const wxFont& font) { HFONT hfont = GetHfontOf(font); - wxCHECK_RET( hfont, _T("invalid font") ); + wxCHECK_RET( hfont, wxT("invalid font") ); 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 */); + // otherwise the window might not be redrawn correctly + ::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */); + } } } @@ -118,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; @@ -140,8 +161,11 @@ private: // the HWNDs we contain HWND *m_hwnds; + // the IDs of the windows + wxWindowIDRef *m_ids; + - DECLARE_NO_COPY_CLASS(wxSubwindows) + wxDECLARE_NO_COPY_CLASS(wxSubwindows); }; // convenient macro to forward a few methods which are usually propagated to