#pragma hdrstop
#endif
+#if wxUSE_BUTTON
+
#ifndef WX_PRECOMP
#include "wx/button.h"
#include "wx/brush.h"
const wxValidator& validator,
const wxString& name)
{
- if ( !CreateBase(parent, id, pos, size, style, validator, name) )
+ if ( !CreateControl(parent, id, pos, size, style, validator, name) )
return FALSE;
- parent->AddChild((wxButton *)this);
-
- m_backgroundColour = parent->GetBackgroundColour();
- m_foregroundColour = parent->GetForegroundColour();
+ return MSWCreateControl(_T("BUTTON"), label, pos, size, style);
+}
+wxButton::~wxButton()
+{
+}
- m_hWnd = (WXHWND)CreateWindowEx
- (
- MakeExtendedStyle(m_windowStyle),
- wxT("BUTTON"),
- label,
- WS_VISIBLE | WS_TABSTOP | WS_CHILD,
- 0, 0, 0, 0,
- GetWinHwnd(parent),
- (HMENU)m_windowId,
- wxGetInstance(),
- NULL
- );
+// ----------------------------------------------------------------------------
+// flags
+// ----------------------------------------------------------------------------
- // Subclass again for purposes of dialog editing mode
- SubclassWin(m_hWnd);
+WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const
+{
+ // buttons never have an external border, they draw their own one
+ WXDWORD msStyle = wxControl::MSWGetStyle
+ (
+ (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle
+ );
- SetFont(parent->GetFont());
+ // we must use WS_CLIPSIBLINGS with the buttons or they would draw over
+ // each other in any resizeable dialog which has more than one button in
+ // the bottom
+ msStyle |= WS_CLIPSIBLINGS;
- SetSize(pos.x, pos.y, size.x, size.y);
+#ifdef __WIN32__
+ // don't use "else if" here: weird as it is, but you may combine wxBU_LEFT
+ // and wxBU_RIGHT to get BS_CENTER!
+ if ( style & wxBU_LEFT )
+ msStyle |= BS_LEFT;
+ if ( style & wxBU_RIGHT )
+ msStyle |= BS_RIGHT;
+ if ( style & wxBU_TOP )
+ msStyle |= BS_TOP;
+ if ( style & wxBU_BOTTOM )
+ msStyle |= BS_BOTTOM;
+#endif // __WIN32__
- return TRUE;
-}
-
-wxButton::~wxButton()
-{
- wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
- if ( panel )
- {
- if ( panel->GetDefaultItem() == this )
- {
- // don't leave the panel with invalid default item
- panel->SetDefaultItem(NULL);
- }
- }
+ return msStyle;
}
// ----------------------------------------------------------------------------
}
/* static */
-wxSize wxButton::GetDefaultSize()
+wxSize wxButtonBase::GetDefaultSize()
{
static wxSize s_sizeBtn;
if ( s_sizeBtn.x == 0 )
{
wxScreenDC dc;
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+ dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
// the size of a standard button in the dialog units is 50x14,
// translate this to pixels
void wxButton::SetDefault()
{
wxWindow *parent = GetParent();
- wxButton *btnOldDefault = NULL;
- wxPanel *panel = wxDynamicCast(parent, wxPanel);
- if ( panel )
+ wxButton *btnOldDefault;
+ if ( parent )
{
- btnOldDefault = panel->GetDefaultItem();
- panel->SetDefaultItem(this);
- }
+ wxWindow *winOldDefault = parent->SetDefaultItem(this);
+ btnOldDefault = wxDynamicCast(winOldDefault, wxButton);
- if ( parent )
+ ::SendMessage(GetWinHwnd(parent), DM_SETDEFID, m_windowId, 0L);
+ }
+ else // is a button without parent really normal?
{
- SendMessage(GetWinHwnd(parent), DM_SETDEFID, m_windowId, 0L);
+ btnOldDefault = NULL;
}
- if ( btnOldDefault )
+ if ( btnOldDefault && btnOldDefault != this )
{
// remove the BS_DEFPUSHBUTTON style from the other button
long style = GetWindowLong(GetHwndOf(btnOldDefault), GWL_STYLE);
// event/message handlers
// ----------------------------------------------------------------------------
-bool wxButton::MSWCommand(WXUINT param, WXWORD id)
+bool wxButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
bool processed = FALSE;
switch ( param )
{
- case 1: // means that the message came from an accelerator
- case BN_CLICKED:
+ case 1: // message came from an accelerator
+ case BN_CLICKED: // normal buttons send this
+ case BN_DOUBLECLICKED: // owner-drawn ones also send this
processed = SendClickEvent();
break;
}
// let the default processign take place too
}
+ else if ( nMsg == WM_LBUTTONDBLCLK )
+ {
+ // emulate a click event to force an owner-drawn button to change its
+ // appearance - without this, it won't do it
+ (void)wxControl::MSWWindowProc(WM_LBUTTONDOWN, wParam, lParam);
+
+ // and conitnue with processing the message normally as well
+ }
// let the base class do all real processing
return wxControl::MSWWindowProc(nMsg, wParam, lParam);
}
#endif // __WIN32__
+
+#endif // wxUSE_BUTTON
+