]> git.saurik.com Git - wxWidgets.git/blob - src/common/radiocmn.cpp
set error to GSOCK_TIMEOUT if the socket timed out (modified and extended patch 1303554)
[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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_RADIOBOX
28
29 #ifndef WX_PRECOMP
30 #include "wx/radiobox.h"
31 #endif //WX_PRECOMP
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 int wxRadioBoxBase::FindString(const wxString& s) const
38 {
39 int count = GetCount();
40 for ( int n = 0; n < count; n++ )
41 {
42 if ( GetString(n) == s )
43 return n;
44 }
45
46 return wxNOT_FOUND;
47 }
48
49 int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
50 {
51 int count = GetCount(),
52 numCols = GetColumnCount(),
53 numRows = GetRowCount();
54
55 bool horz = (style & wxRA_SPECIFY_COLS) != 0;
56
57 switch ( dir )
58 {
59 case wxUP:
60 if ( horz )
61 {
62 item -= numCols;
63 }
64 else // vertical layout
65 {
66 if ( !item-- )
67 item = count - 1;
68 }
69 break;
70
71 case wxLEFT:
72 if ( horz )
73 {
74 if ( !item-- )
75 item = count - 1;
76 }
77 else // vertical layout
78 {
79 item -= numRows;
80 }
81 break;
82
83 case wxDOWN:
84 if ( horz )
85 {
86 item += numCols;
87 }
88 else // vertical layout
89 {
90 if ( ++item == count )
91 item = 0;
92 }
93 break;
94
95 case wxRIGHT:
96 if ( horz )
97 {
98 if ( ++item == count )
99 item = 0;
100 }
101 else // vertical layout
102 {
103 item += numRows;
104 }
105 break;
106
107 default:
108 wxFAIL_MSG( _T("unexpected wxDirection value") );
109 return wxNOT_FOUND;
110 }
111
112 // ensure that the item is in range [0..count)
113 if ( item < 0 )
114 {
115 // first map the item to the one in the same column but in the last row
116 item += count;
117
118 // now there are 2 cases: either it is the first item of the last row
119 // in which case we need to wrap again and get to the last item or we
120 // can just go to the previous item
121 if ( item % (horz ? numCols : numRows) )
122 item--;
123 else
124 item = count - 1;
125 }
126 else if ( item >= count )
127 {
128 // same logic as above
129 item -= count;
130
131 // ... except that we need to check if this is not the last item, not
132 // the first one
133 if ( (item + 1) % (horz ? numCols : numRows) )
134 item++;
135 else
136 item = 0;
137 }
138
139 wxASSERT_MSG( item < count && item >= 0,
140 _T("logic error in wxRadioBox::GetNextItem()") );
141
142 return item;
143 }
144
145 #if WXWIN_COMPATIBILITY_2_4
146
147 // these functions are deprecated and don't do anything
148 int wxRadioBoxBase::GetNumberOfRowsOrCols() const
149 {
150 return 1;
151 }
152
153 void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n))
154 {
155 }
156
157 #endif // WXWIN_COMPATIBILITY_2_4
158
159 #if WXWIN_COMPATIBILITY_2_2
160
161 int wxRadioBoxBase::Number() const
162 {
163 return GetCount();
164 }
165
166 wxString wxRadioBoxBase::GetLabel(int n) const
167 {
168 return GetString(n);
169 }
170
171 void wxRadioBoxBase::SetLabel(int n, const wxString& label)
172 {
173 SetString(n, label);
174 }
175
176 #endif // WXWIN_COMPATIBILITY_2_2
177
178 #endif // wxUSE_RADIOBOX
179