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 WXDLLEXPORT 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
));
37 // non-virtual dtor, this class is not supposed to be used polymorphically
40 for ( size_t n
= 0; n
< m_count
; n
++ )
42 ::DestroyWindow(m_hwnds
[n
]);
48 // get the number of subwindows
49 size_t GetCount() const { return m_count
; }
51 // access a given window
54 wxASSERT_MSG( n
< m_count
, _T("subwindow index out of range") );
59 HWND
& operator[](size_t n
) { return Get(n
); }
60 HWND
operator[](size_t n
) const
62 return wx_const_cast(wxSubwindows
*, this)->Get(n
);
65 // check if we have this window
66 bool HasWindow(HWND hwnd
)
68 for ( size_t n
= 0; n
< m_count
; n
++ )
70 if ( m_hwnds
[n
] == hwnd
)
78 // methods which are forwarded to all subwindows
79 // ---------------------------------------------
81 // show/hide everything
84 int sw
= show ? SW_SHOW
: SW_HIDE
;
85 for ( size_t n
= 0; n
< m_count
; n
++ )
87 ::ShowWindow(m_hwnds
[n
], sw
);
91 // enable/disable everything
92 void Enable(bool enable
)
94 for ( size_t n
= 0; n
< m_count
; n
++ )
96 ::EnableWindow(m_hwnds
[n
], enable
);
100 // set font for all windows
101 void SetFont(const wxFont
& font
)
103 HFONT hfont
= GetHfontOf(font
);
104 wxCHECK_RET( hfont
, _T("invalid font") );
106 for ( size_t n
= 0; n
< m_count
; n
++ )
108 ::SendMessage(m_hwnds
[n
], WM_SETFONT
, (WPARAM
)hfont
, 0);
112 // find the bounding box for all windows
113 wxRect
GetBoundingBox() const
116 for ( size_t n
= 0; n
< m_count
; n
++ )
119 ::GetWindowRect(m_hwnds
[n
], &rc
);
121 r
.Union(wxRectFromRECT(rc
));
134 // number of elements in m_hwnds array
137 // the HWNDs we contain
141 DECLARE_NO_COPY_CLASS(wxSubwindows
)
144 #endif // _WX_MSW_SUBWIN_H_