From: Vadim Zeitlin Date: Sat, 11 Dec 2004 23:35:27 +0000 (+0000) Subject: helper class for implementing composite controls under MSW X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/19fdd4efb6fcd6514eb0145fd8251060ce221d08?ds=sidebyside helper class for implementing composite controls under MSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/subwin.h b/include/wx/msw/subwin.h new file mode 100644 index 0000000000..61620abff7 --- /dev/null +++ b/include/wx/msw/subwin.h @@ -0,0 +1,136 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/msw/subwin.h +// Purpose: helper for implementing the controls with subwindows +// Author: Vadim Zeitlin +// Modified by: +// Created: 2004-12-11 +// RCS-ID: $Id$ +// Copyright: (c) 2004 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_SUBWIN_H_ +#define _WX_MSW_SUBWIN_H_ + +#include "wx/msw/private.h" + +// ---------------------------------------------------------------------------- +// wxSubwindows contains all HWNDs making part of a single wx control +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxSubwindows +{ +public: + // the number of subwindows can be specified either as parameter to ctor or + // later in Create() + wxSubwindows(size_t n = 0) { Init(); if ( n ) Create(n); } + + // allocate enough space for the given number of windows + void Create(size_t n) + { + wxASSERT_MSG( !m_hwnds, _T("Create() called twice?") ); + + m_count = n; + m_hwnds = (HWND *)calloc(n, sizeof(HWND)); + } + + // non-virtual dtor, this class is not supposed to be used polymorphically + ~wxSubwindows() + { + for ( size_t n = 0; n < m_count; n++ ) + { + ::DestroyWindow(m_hwnds[n]); + } + + free(m_hwnds); + } + + // get the number of subwindows + size_t GetCount() const { return m_count; } + + // access a given window + HWND& Get(size_t n) + { + wxASSERT_MSG( n < m_count, _T("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); + } + + // check if we have this window + bool HasWindow(HWND hwnd) + { + for ( size_t n = 0; n < m_count; n++ ) + { + if ( m_hwnds[n] == hwnd ) + return true; + } + + return false; + } + + + // methods which are forwarded to all subwindows + // --------------------------------------------- + + // show/hide everything + void Show(bool show) + { + int sw = show ? SW_SHOW : SW_HIDE; + for ( size_t n = 0; n < m_count; n++ ) + { + ::ShowWindow(m_hwnds[n], sw); + } + } + + // set font for all windows + void SetFont(const wxFont& font) + { + HFONT hfont = GetHfontOf(font); + wxCHECK_RET( hfont, _T("invalid font") ); + + for ( size_t n = 0; n < m_count; n++ ) + { + ::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0); + } + } + + // find the bounding box for all windows + wxRect GetBoundingBox() const + { + wxRect r; + for ( size_t n = 0; n < m_count; n++ ) + { + RECT rc; + ::GetWindowRect(m_hwnds[n], &rc); + + r.Union(wxRectFromRECT(rc)); + } + + return r; + } + +private: + void Init() + { + m_count = 0; + m_hwnds = NULL; + } + + // number of elements in m_hwnds array + size_t m_count; + + // the HWNDs we contain + HWND *m_hwnds; + + + DECLARE_NO_COPY_CLASS(wxSubwindows) +}; + +#endif // _WX_MSW_SUBWIN_H_ +