]> git.saurik.com Git - wxWidgets.git/blob - src/common/radiocmn.cpp
include wx/setup.h and check to make sure it's not the configure created
[wxWidgets.git] / src / common / radiocmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/radiocmn.cpp
3 // Purpose: wxRadioBox methods common to all ports
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 03.06.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "radioboxbase.h"
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 #if wxUSE_RADIOBOX
32
33 #ifndef WX_PRECOMP
34 #include "wx/radiobox.h"
35 #endif //WX_PRECOMP
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 int wxRadioBoxBase::FindString(const wxString& s) const
42 {
43 int count = GetCount();
44 for ( int n = 0; n < count; n++ )
45 {
46 if ( GetString(n) == s )
47 return n;
48 }
49
50 return wxNOT_FOUND;
51 }
52
53 int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
54 {
55 int count = GetCount(),
56 numCols = GetColumnCount(),
57 numRows = GetRowCount();
58
59 bool horz = (style & wxRA_SPECIFY_COLS) != 0;
60
61 switch ( dir )
62 {
63 case wxUP:
64 if ( horz )
65 {
66 item -= numCols;
67 }
68 else // vertical layout
69 {
70 if ( !item-- )
71 item = count - 1;
72 }
73 break;
74
75 case wxLEFT:
76 if ( horz )
77 {
78 if ( !item-- )
79 item = count - 1;
80 }
81 else // vertical layout
82 {
83 item -= numRows;
84 }
85 break;
86
87 case wxDOWN:
88 if ( horz )
89 {
90 item += numCols;
91 }
92 else // vertical layout
93 {
94 if ( ++item == count )
95 item = 0;
96 }
97 break;
98
99 case wxRIGHT:
100 if ( horz )
101 {
102 if ( ++item == count )
103 item = 0;
104 }
105 else // vertical layout
106 {
107 item += numRows;
108 }
109 break;
110
111 default:
112 wxFAIL_MSG( _T("unexpected wxDirection value") );
113 return wxNOT_FOUND;
114 }
115
116 // ensure that the item is in range [0..count)
117 if ( item < 0 )
118 {
119 // first map the item to the one in the same column but in the last row
120 item += count;
121
122 // now there are 2 cases: either it is the first item of the last row
123 // in which case we need to wrap again and get to the last item or we
124 // can just go to the previous item
125 if ( item % (horz ? numCols : numRows) )
126 item--;
127 else
128 item = count - 1;
129 }
130 else if ( item >= count )
131 {
132 // same logic as above
133 item -= count;
134
135 // ... except that we need to check if this is not the last item, not
136 // the first one
137 if ( (item + 1) % (horz ? numCols : numRows) )
138 item++;
139 else
140 item = 0;
141 }
142
143 wxASSERT_MSG( item < count && item >= 0,
144 _T("logic error in wxRadioBox::GetNextItem()") );
145
146 return item;
147 }
148
149 #if WXWIN_COMPATIBILITY_2_4
150
151 // these functions are deprecated and don't do anything
152 int wxRadioBoxBase::GetNumberOfRowsOrCols() const
153 {
154 return 1;
155 }
156
157 void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n))
158 {
159 }
160
161 #endif // WXWIN_COMPATIBILITY_2_4
162
163 #if WXWIN_COMPATIBILITY_2_2
164
165 int wxRadioBoxBase::Number() const
166 {
167 return GetCount();
168 }
169
170 wxString wxRadioBoxBase::GetLabel(int n) const
171 {
172 return GetString(n);
173 }
174
175 void wxRadioBoxBase::SetLabel(int n, const wxString& label)
176 {
177 SetString(n, label);
178 }
179
180 #endif // WXWIN_COMPATIBILITY_2_2
181
182 #endif // wxUSE_RADIOBOX
183