]> git.saurik.com Git - wxWidgets.git/blob - src/common/choiccmn.cpp
Applied #15375 to stop event-sending in generic wxSpinCtrl ctor (eco)
[wxWidgets.git] / src / common / choiccmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/choiccmn.cpp
3 // Purpose: common (to all ports) wxChoice functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 26.07.99
7 // Copyright: (c) wxWidgets team
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_CHOICE
27
28 #include "wx/choice.h"
29
30 #include "wx/private/textmeasure.h"
31
32 #ifndef WX_PRECOMP
33 #endif
34
35 const char wxChoiceNameStr[] = "choice";
36
37
38 wxDEFINE_FLAGS( wxChoiceStyle )
39 wxBEGIN_FLAGS( wxChoiceStyle )
40 // new style border flags, we put them first to
41 // use them for streaming out
42 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
43 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
44 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
45 wxFLAGS_MEMBER(wxBORDER_RAISED)
46 wxFLAGS_MEMBER(wxBORDER_STATIC)
47 wxFLAGS_MEMBER(wxBORDER_NONE)
48
49 // old style border flags
50 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
51 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
52 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
53 wxFLAGS_MEMBER(wxRAISED_BORDER)
54 wxFLAGS_MEMBER(wxSTATIC_BORDER)
55 wxFLAGS_MEMBER(wxBORDER)
56
57 // standard window styles
58 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
59 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
60 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
61 wxFLAGS_MEMBER(wxWANTS_CHARS)
62 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
63 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
64 wxFLAGS_MEMBER(wxVSCROLL)
65 wxFLAGS_MEMBER(wxHSCROLL)
66
67 wxEND_FLAGS( wxChoiceStyle )
68
69 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxChoice, wxControl, "wx/choice.h")
70
71 wxBEGIN_PROPERTIES_TABLE(wxChoice)
72 wxEVENT_PROPERTY( Select, wxEVT_CHOICE, wxCommandEvent )
73
74 wxPROPERTY( Font, wxFont, SetFont, GetFont , wxEMPTY_PARAMETER_VALUE, \
75 0 /*flags*/, wxT("Helpstring"), wxT("group"))
76 wxPROPERTY_COLLECTION( Choices, wxArrayString, wxString, AppendString, \
77 GetStrings, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
78 wxPROPERTY( Selection,int, SetSelection, GetSelection, wxEMPTY_PARAMETER_VALUE, \
79 0 /*flags*/, wxT("Helpstring"), wxT("group"))
80
81 /*
82 TODO PROPERTIES
83 selection (long)
84 content (list)
85 item
86 */
87
88 wxPROPERTY_FLAGS( WindowStyle, wxChoiceStyle, long, SetWindowStyleFlag, \
89 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
90 wxT("Helpstring"), wxT("group")) // style
91 wxEND_PROPERTIES_TABLE()
92
93 wxEMPTY_HANDLERS_TABLE(wxChoice)
94
95 wxCONSTRUCTOR_4( wxChoice, wxWindow*, Parent, wxWindowID, Id, \
96 wxPoint, Position, wxSize, Size )
97
98 // ============================================================================
99 // implementation
100 // ============================================================================
101
102 wxChoiceBase::~wxChoiceBase()
103 {
104 // this destructor is required for Darwin
105 }
106
107 wxSize wxChoiceBase::DoGetBestSize() const
108 {
109 // a reasonable width for an empty choice list
110 wxSize best(80, -1);
111
112 const unsigned int nItems = GetCount();
113 if ( nItems > 0 )
114 {
115 wxTextMeasure txm(this);
116 best.x = txm.GetLargestStringExtent(GetStrings()).x;
117 }
118
119 return best;
120 }
121
122 // ----------------------------------------------------------------------------
123 // misc
124 // ----------------------------------------------------------------------------
125
126 void wxChoiceBase::Command(wxCommandEvent& event)
127 {
128 SetSelection(event.GetInt());
129 (void)GetEventHandler()->ProcessEvent(event);
130 }
131
132 #endif // wxUSE_CHOICE