1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
///////////////////////////////////////////////////////////////////////////////
// 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: subwin.h 30981 2004-12-13 01:02:32Z VZ $
// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
// 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);
}
}
// enable/disable everything
void Enable(bool enable)
{
for ( size_t n = 0; n < m_count; n++ )
{
::EnableWindow(m_hwnds[n], enable);
}
}
// 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);
// otherwise the window might not be redrawn correctly
::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */);
}
}
// 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)
};
// convenient macro to forward a few methods which are usually propagated to
// subwindows to a wxSubwindows object
//
// parameters should be:
// - cname the name of the class implementing these methods
// - base the name of its base class
// - subwins the name of the member variable of type wxSubwindows *
#define WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(cname, base, subwins) \
bool cname::ContainsHWND(WXHWND hWnd) const \
{ \
return subwins && subwins->HasWindow((HWND)hWnd); \
} \
\
bool cname::Show(bool show) \
{ \
if ( !base::Show(show) ) \
return false; \
\
if ( subwins ) \
subwins->Show(show); \
\
return true; \
} \
\
bool cname::Enable(bool enable) \
{ \
if ( !base::Enable(enable) ) \
return false; \
\
if ( subwins ) \
subwins->Enable(enable); \
\
return true; \
} \
\
bool cname::SetFont(const wxFont& font) \
{ \
if ( !base::SetFont(font) ) \
return false; \
\
if ( subwins ) \
subwins->SetFont(font); \
\
return true; \
}
#endif // _WX_MSW_SUBWIN_H_
|