]> git.saurik.com Git - wxWidgets.git/blob - src/common/btncmn.cpp
simplify code so it always returns the same object
[wxWidgets.git] / src / common / btncmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/btncmn.cpp
3 // Purpose: implementation of wxButtonBase
4 // Author: Vadim Zeitlin
5 // Created: 2007-04-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_BUTTON
27
28 #ifndef WX_PRECOMP
29 #include "wx/button.h"
30 #include "wx/toplevel.h"
31 #endif //WX_PRECOMP
32
33 extern WXDLLEXPORT_DATA(const char) wxButtonNameStr[] = "button";
34
35 // ----------------------------------------------------------------------------
36 // XTI
37 // ----------------------------------------------------------------------------
38
39 wxDEFINE_FLAGS( wxButtonStyle )
40 wxBEGIN_FLAGS( wxButtonStyle )
41 // new style border flags, we put them first to
42 // use them for streaming out
43 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
44 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
45 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
46 wxFLAGS_MEMBER(wxBORDER_RAISED)
47 wxFLAGS_MEMBER(wxBORDER_STATIC)
48 wxFLAGS_MEMBER(wxBORDER_NONE)
49
50 // old style border flags
51 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
52 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
53 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
54 wxFLAGS_MEMBER(wxRAISED_BORDER)
55 wxFLAGS_MEMBER(wxSTATIC_BORDER)
56 wxFLAGS_MEMBER(wxBORDER)
57
58 // standard window styles
59 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
60 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
61 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
62 wxFLAGS_MEMBER(wxWANTS_CHARS)
63 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
64 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
65 wxFLAGS_MEMBER(wxVSCROLL)
66 wxFLAGS_MEMBER(wxHSCROLL)
67
68 wxFLAGS_MEMBER(wxBU_LEFT)
69 wxFLAGS_MEMBER(wxBU_RIGHT)
70 wxFLAGS_MEMBER(wxBU_TOP)
71 wxFLAGS_MEMBER(wxBU_BOTTOM)
72 wxFLAGS_MEMBER(wxBU_EXACTFIT)
73 wxEND_FLAGS( wxButtonStyle )
74
75 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxButton, wxControl, "wx/button.h")
76
77 wxBEGIN_PROPERTIES_TABLE(wxButton)
78 wxEVENT_PROPERTY( Click, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent )
79
80 wxPROPERTY( Font, wxFont, SetFont, GetFont, wxEMPTY_PARAMETER_VALUE, \
81 0 /*flags*/, wxT("The font associated with the button label"), wxT("group"))
82 wxPROPERTY( Label, wxString, SetLabel, GetLabel, wxString(), \
83 0 /*flags*/, wxT("The button label"), wxT("group") )
84
85 wxPROPERTY_FLAGS( WindowStyle, wxButtonStyle, long, SetWindowStyleFlag, \
86 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
87 wxT("The button style"), wxT("group")) // style
88 wxEND_PROPERTIES_TABLE()
89
90 wxEMPTY_HANDLERS_TABLE(wxButton)
91
92 wxCONSTRUCTOR_6( wxButton, wxWindow*, Parent, wxWindowID, Id, wxString, \
93 Label, wxPoint, Position, wxSize, Size, long, WindowStyle )
94
95
96 // ============================================================================
97 // implementation
98 // ============================================================================
99
100 wxWindow *wxButtonBase::SetDefault()
101 {
102 wxTopLevelWindow * const
103 tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
104
105 wxCHECK_MSG( tlw, NULL, wxT("button without top level window?") );
106
107 return tlw->SetDefaultItem(this);
108 }
109
110 void wxAnyButtonBase::SetBitmapPosition(wxDirection dir)
111 {
112 wxASSERT_MSG( !(dir & ~wxDIRECTION_MASK), "non-direction flag used" );
113 wxASSERT_MSG( !!(dir & wxLEFT) +
114 !!(dir & wxRIGHT) +
115 !!(dir & wxTOP) +
116 !!(dir & wxBOTTOM) == 1,
117 "exactly one direction flag must be set" );
118
119 DoSetBitmapPosition(dir);
120
121 }
122 #endif // wxUSE_BUTTON