]>
Commit | Line | Data |
---|---|---|
2d61b48d VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: common/choiccmn.cpp | |
3 | // Purpose: common (to all ports) wxChoice functions | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 26.07.99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows team | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
a3015c54 | 21 | #pragma implementation "choiccmn.h" |
2d61b48d VZ |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/choice.h" | |
33 | #include "wx/log.h" | |
34 | #endif | |
35 | ||
36 | // ============================================================================ | |
37 | // implementation | |
38 | // ============================================================================ | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // events | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | void wxChoiceBase::Command(wxCommandEvent &event) | |
45 | { | |
46 | SetSelection(event.GetInt()); | |
47 | (void)ProcessEvent(event); | |
48 | } | |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // string selection management | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | wxString wxChoiceBase::GetStringSelection() const | |
55 | { | |
56 | int sel = GetSelection(); | |
57 | wxString str; | |
e90c1d2a | 58 | wxCHECK_MSG( sel != wxNOT_FOUND, str, T("no selection, hence no string") ); |
2d61b48d VZ |
59 | |
60 | str = GetString(sel); | |
61 | return str; | |
62 | } | |
63 | ||
64 | bool wxChoiceBase::SetStringSelection(const wxString& sel) | |
65 | { | |
66 | int selIndex = FindString(sel); | |
67 | wxCHECK_MSG( selIndex != wxNOT_FOUND, FALSE, | |
e90c1d2a | 68 | T("can't set selection to string not in the control") ); |
2d61b48d VZ |
69 | |
70 | SetSelection(selIndex); | |
71 | ||
72 | return TRUE; | |
73 | } | |
74 | ||
75 | // ---------------------------------------------------------------------------- | |
76 | // client data | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | void wxChoiceBase::SetClientObject(int n, wxClientData *data) | |
80 | { | |
81 | wxASSERT_MSG( m_clientDataItemsType != ClientData_Void, | |
e90c1d2a | 82 | T("can't have both object and void client data") ); |
2d61b48d VZ |
83 | |
84 | wxClientData *clientDataOld = DoGetClientObject(n); | |
85 | if ( clientDataOld ) | |
86 | delete clientDataOld; | |
87 | ||
88 | DoSetClientObject(n, data); | |
89 | m_clientDataItemsType = ClientData_Object; | |
90 | } | |
91 | ||
92 | wxClientData *wxChoiceBase::GetClientObject(int n) const | |
93 | { | |
94 | wxASSERT_MSG( m_clientDataItemsType == ClientData_Object, | |
e90c1d2a | 95 | T("this window doesn't have object client data") ); |
2d61b48d VZ |
96 | |
97 | return DoGetClientObject(n); | |
98 | } | |
99 | ||
100 | void wxChoiceBase::SetClientData(int n, void *data) | |
101 | { | |
102 | wxASSERT_MSG( m_clientDataItemsType != ClientData_Object, | |
e90c1d2a | 103 | T("can't have both object and void client data") ); |
2d61b48d VZ |
104 | |
105 | DoSetClientData(n, data); | |
106 | m_clientDataItemsType = ClientData_Void; | |
107 | } | |
108 | ||
109 | void *wxChoiceBase::GetClientData(int n) const | |
110 | { | |
111 | wxASSERT_MSG( m_clientDataItemsType == ClientData_Void, | |
e90c1d2a | 112 | T("this window doesn't have void client data") ); |
2d61b48d VZ |
113 | |
114 | return DoGetClientData(n); | |
115 | } | |
116 | ||
117 |