1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/subwin.h
3 // Purpose: helper for implementing the controls with subwindows
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_MSW_SUBWIN_H_
12 #define _WX_MSW_SUBWIN_H_
14 #include "wx/msw/private.h"
16 // ----------------------------------------------------------------------------
17 // wxSubwindows contains all HWNDs making part of a single wx control
18 // ----------------------------------------------------------------------------
20 class WXDLLIMPEXP_CORE wxSubwindows
23 // the number of subwindows can be specified either as parameter to ctor or
25 wxSubwindows(size_t n
= 0) { Init(); if ( n
) Create(n
); }
27 // allocate enough space for the given number of windows
30 wxASSERT_MSG( !m_hwnds
, wxT("Create() called twice?") );
33 m_hwnds
= (HWND
*)calloc(n
, sizeof(HWND
));
34 m_ids
= new wxWindowIDRef
[n
];
37 // non-virtual dtor, this class is not supposed to be used polymorphically
40 for ( size_t n
= 0; n
< m_count
; n
++ )
43 ::DestroyWindow(m_hwnds
[n
]);
50 // get the number of subwindows
51 size_t GetCount() const { return m_count
; }
53 // access a given window
56 wxASSERT_MSG( n
< m_count
, wxT("subwindow index out of range") );
61 HWND
operator[](size_t n
) const
63 return const_cast<wxSubwindows
*>(this)->Get(n
);
66 // initialize the given window: id will be stored in wxWindowIDRef ensuring
67 // that it is not reused while this object exists
68 void Set(size_t n
, HWND hwnd
, wxWindowID id
)
70 wxASSERT_MSG( n
< m_count
, wxT("subwindow index out of range") );
76 // check if we have this window
77 bool HasWindow(HWND hwnd
)
79 for ( size_t n
= 0; n
< m_count
; n
++ )
81 if ( m_hwnds
[n
] == hwnd
)
89 // methods which are forwarded to all subwindows
90 // ---------------------------------------------
92 // show/hide everything
95 int sw
= show
? SW_SHOW
: SW_HIDE
;
96 for ( size_t n
= 0; n
< m_count
; n
++ )
99 ::ShowWindow(m_hwnds
[n
], sw
);
103 // enable/disable everything
104 void Enable(bool enable
)
106 for ( size_t n
= 0; n
< m_count
; n
++ )
109 ::EnableWindow(m_hwnds
[n
], enable
);
113 // set font for all windows
114 void SetFont(const wxFont
& font
)
116 HFONT hfont
= GetHfontOf(font
);
117 wxCHECK_RET( hfont
, wxT("invalid font") );
119 for ( size_t n
= 0; n
< m_count
; n
++ )
123 ::SendMessage(m_hwnds
[n
], WM_SETFONT
, (WPARAM
)hfont
, 0);
125 // otherwise the window might not be redrawn correctly
126 ::InvalidateRect(m_hwnds
[n
], NULL
, FALSE
/* don't erase bg */);
131 // find the bounding box for all windows
132 wxRect
GetBoundingBox() const
135 for ( size_t n
= 0; n
< m_count
; n
++ )
141 ::GetWindowRect(m_hwnds
[n
], &rc
);
143 r
.Union(wxRectFromRECT(rc
));
157 // number of elements in m_hwnds array
160 // the HWNDs we contain
163 // the IDs of the windows
164 wxWindowIDRef
*m_ids
;
167 wxDECLARE_NO_COPY_CLASS(wxSubwindows
);
170 // convenient macro to forward a few methods which are usually propagated to
171 // subwindows to a wxSubwindows object
173 // parameters should be:
174 // - cname the name of the class implementing these methods
175 // - base the name of its base class
176 // - subwins the name of the member variable of type wxSubwindows *
177 #define WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(cname, base, subwins) \
178 bool cname::ContainsHWND(WXHWND hWnd) const \
180 return subwins && subwins->HasWindow((HWND)hWnd); \
183 bool cname::Show(bool show) \
185 if ( !base::Show(show) ) \
189 subwins->Show(show); \
194 bool cname::Enable(bool enable) \
196 if ( !base::Enable(enable) ) \
200 subwins->Enable(enable); \
205 bool cname::SetFont(const wxFont& font) \
207 if ( !base::SetFont(font) ) \
211 subwins->SetFont(font); \
217 #endif // _WX_MSW_SUBWIN_H_