1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/subwin.h
3 // Purpose: helper for implementing the controls with subwindows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSW_SUBWIN_H_
13 #define _WX_MSW_SUBWIN_H_
15 #include "wx/msw/private.h"
17 // ----------------------------------------------------------------------------
18 // wxSubwindows contains all HWNDs making part of a single wx control
19 // ----------------------------------------------------------------------------
21 class WXDLLIMPEXP_CORE wxSubwindows
24 // the number of subwindows can be specified either as parameter to ctor or
26 wxSubwindows(size_t n
= 0) { Init(); if ( n
) Create(n
); }
28 // allocate enough space for the given number of windows
31 wxASSERT_MSG( !m_hwnds
, _T("Create() called twice?") );
34 m_hwnds
= (HWND
*)calloc(n
, sizeof(HWND
));
35 m_ids
= new wxWindowIDRef
[n
];
38 // non-virtual dtor, this class is not supposed to be used polymorphically
41 for ( size_t n
= 0; n
< m_count
; n
++ )
44 ::DestroyWindow(m_hwnds
[n
]);
51 // get the number of subwindows
52 size_t GetCount() const { return m_count
; }
54 // access a given window
57 wxASSERT_MSG( n
< m_count
, _T("subwindow index out of range") );
62 HWND
operator[](size_t n
) const
64 return const_cast<wxSubwindows
*>(this)->Get(n
);
67 // initialize the given window: id will be stored in wxWindowIDRef ensuring
68 // that it is not reused while this object exists
69 void Set(size_t n
, HWND hwnd
, wxWindowID id
)
71 wxASSERT_MSG( n
< m_count
, _T("subwindow index out of range") );
77 // check if we have this window
78 bool HasWindow(HWND hwnd
)
80 for ( size_t n
= 0; n
< m_count
; n
++ )
82 if ( m_hwnds
[n
] == hwnd
)
90 // methods which are forwarded to all subwindows
91 // ---------------------------------------------
93 // show/hide everything
96 int sw
= show
? SW_SHOW
: SW_HIDE
;
97 for ( size_t n
= 0; n
< m_count
; n
++ )
100 ::ShowWindow(m_hwnds
[n
], sw
);
104 // enable/disable everything
105 void Enable(bool enable
)
107 for ( size_t n
= 0; n
< m_count
; n
++ )
110 ::EnableWindow(m_hwnds
[n
], enable
);
114 // set font for all windows
115 void SetFont(const wxFont
& font
)
117 HFONT hfont
= GetHfontOf(font
);
118 wxCHECK_RET( hfont
, _T("invalid font") );
120 for ( size_t n
= 0; n
< m_count
; n
++ )
124 ::SendMessage(m_hwnds
[n
], WM_SETFONT
, (WPARAM
)hfont
, 0);
126 // otherwise the window might not be redrawn correctly
127 ::InvalidateRect(m_hwnds
[n
], NULL
, FALSE
/* don't erase bg */);
132 // find the bounding box for all windows
133 wxRect
GetBoundingBox() const
136 for ( size_t n
= 0; n
< m_count
; n
++ )
142 ::GetWindowRect(m_hwnds
[n
], &rc
);
144 r
.Union(wxRectFromRECT(rc
));
158 // number of elements in m_hwnds array
161 // the HWNDs we contain
164 // the IDs of the windows
165 wxWindowIDRef
*m_ids
;
168 wxDECLARE_NO_COPY_CLASS(wxSubwindows
);
171 // convenient macro to forward a few methods which are usually propagated to
172 // subwindows to a wxSubwindows object
174 // parameters should be:
175 // - cname the name of the class implementing these methods
176 // - base the name of its base class
177 // - subwins the name of the member variable of type wxSubwindows *
178 #define WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(cname, base, subwins) \
179 bool cname::ContainsHWND(WXHWND hWnd) const \
181 return subwins && subwins->HasWindow((HWND)hWnd); \
184 bool cname::Show(bool show) \
186 if ( !base::Show(show) ) \
190 subwins->Show(show); \
195 bool cname::Enable(bool enable) \
197 if ( !base::Enable(enable) ) \
201 subwins->Enable(enable); \
206 bool cname::SetFont(const wxFont& font) \
208 if ( !base::SetFont(font) ) \
212 subwins->SetFont(font); \
218 #endif // _WX_MSW_SUBWIN_H_