2004-12-11 18:35:27 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 <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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxSubwindows
|
2004-12-11 18:35:27 -05:00
|
|
|
{
|
|
|
|
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));
|
2008-01-06 20:54:33 -05:00
|
|
|
m_ids = new wxWindowIDRef[n];
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// non-virtual dtor, this class is not supposed to be used polymorphically
|
|
|
|
~wxSubwindows()
|
|
|
|
{
|
|
|
|
for ( size_t n = 0; n < m_count; n++ )
|
|
|
|
{
|
2008-01-07 13:43:23 -05:00
|
|
|
if ( m_hwnds[n] )
|
|
|
|
::DestroyWindow(m_hwnds[n]);
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
free(m_hwnds);
|
2008-01-06 20:54:33 -05:00
|
|
|
delete [] m_ids;
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) const
|
|
|
|
{
|
|
|
|
return wx_const_cast(wxSubwindows *, this)->Get(n);
|
|
|
|
}
|
|
|
|
|
2008-01-06 20:54:33 -05:00
|
|
|
// initialize the given window: id will be stored in wxWindowIDRef ensuring
|
|
|
|
// that it is not reused while this object exists
|
|
|
|
void Set(size_t n, HWND hwnd, wxWindowID id)
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( n < m_count, _T("subwindow index out of range") );
|
|
|
|
|
|
|
|
m_hwnds[n] = hwnd;
|
|
|
|
m_ids[n] = id;
|
|
|
|
}
|
|
|
|
|
2004-12-11 18:35:27 -05:00
|
|
|
// 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++ )
|
|
|
|
{
|
2008-01-07 13:43:23 -05:00
|
|
|
if ( m_hwnds[n] )
|
|
|
|
::ShowWindow(m_hwnds[n], sw);
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-12 16:43:45 -05:00
|
|
|
// enable/disable everything
|
|
|
|
void Enable(bool enable)
|
|
|
|
{
|
|
|
|
for ( size_t n = 0; n < m_count; n++ )
|
|
|
|
{
|
2008-01-07 13:43:23 -05:00
|
|
|
if ( m_hwnds[n] )
|
|
|
|
::EnableWindow(m_hwnds[n], enable);
|
2004-12-12 16:43:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-11 18:35:27 -05:00
|
|
|
// 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++ )
|
|
|
|
{
|
2008-01-07 13:43:23 -05:00
|
|
|
if ( m_hwnds[n] )
|
|
|
|
{
|
|
|
|
::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0);
|
2004-12-12 20:02:32 -05:00
|
|
|
|
2008-01-07 13:43:23 -05:00
|
|
|
// otherwise the window might not be redrawn correctly
|
|
|
|
::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */);
|
|
|
|
}
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the bounding box for all windows
|
|
|
|
wxRect GetBoundingBox() const
|
|
|
|
{
|
|
|
|
wxRect r;
|
|
|
|
for ( size_t n = 0; n < m_count; n++ )
|
|
|
|
{
|
2008-01-07 13:43:23 -05:00
|
|
|
if ( m_hwnds[n] )
|
|
|
|
{
|
|
|
|
RECT rc;
|
2004-12-11 18:35:27 -05:00
|
|
|
|
2008-01-07 13:43:23 -05:00
|
|
|
::GetWindowRect(m_hwnds[n], &rc);
|
|
|
|
|
|
|
|
r.Union(wxRectFromRECT(rc));
|
|
|
|
}
|
2004-12-11 18:35:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2008-01-06 20:54:33 -05:00
|
|
|
// the IDs of the windows
|
|
|
|
wxWindowIDRef *m_ids;
|
|
|
|
|
2004-12-11 18:35:27 -05:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxSubwindows)
|
|
|
|
};
|
|
|
|
|
2004-12-12 20:02:32 -05:00
|
|
|
// 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; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-11 18:35:27 -05:00
|
|
|
#endif // _WX_MSW_SUBWIN_H_
|
|
|
|
|