]> git.saurik.com Git - wxWidgets.git/blob - src/common/radiocmn.cpp
filename correction
[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::GetNextItem(int item, wxDirection dir, long style) const
38 {
39 int count = GetCount(),
40 numCols = GetColumnCount(),
41 numRows = GetRowCount();
42
43 bool horz = (style & wxRA_SPECIFY_COLS) != 0;
44
45 switch ( dir )
46 {
47 case wxUP:
48 if ( horz )
49 {
50 item -= numCols;
51 }
52 else // vertical layout
53 {
54 if ( !item-- )
55 item = count - 1;
56 }
57 break;
58
59 case wxLEFT:
60 if ( horz )
61 {
62 if ( !item-- )
63 item = count - 1;
64 }
65 else // vertical layout
66 {
67 item -= numRows;
68 }
69 break;
70
71 case wxDOWN:
72 if ( horz )
73 {
74 item += numCols;
75 }
76 else // vertical layout
77 {
78 if ( ++item == count )
79 item = 0;
80 }
81 break;
82
83 case wxRIGHT:
84 if ( horz )
85 {
86 if ( ++item == count )
87 item = 0;
88 }
89 else // vertical layout
90 {
91 item += numRows;
92 }
93 break;
94
95 default:
96 wxFAIL_MSG( _T("unexpected wxDirection value") );
97 return wxNOT_FOUND;
98 }
99
100 // ensure that the item is in range [0..count)
101 if ( item < 0 )
102 {
103 // first map the item to the one in the same column but in the last row
104 item += count;
105
106 // now there are 2 cases: either it is the first item of the last row
107 // in which case we need to wrap again and get to the last item or we
108 // can just go to the previous item
109 if ( item % (horz ? numCols : numRows) )
110 item--;
111 else
112 item = count - 1;
113 }
114 else if ( item >= count )
115 {
116 // same logic as above
117 item -= count;
118
119 // ... except that we need to check if this is not the last item, not
120 // the first one
121 if ( (item + 1) % (horz ? numCols : numRows) )
122 item++;
123 else
124 item = 0;
125 }
126
127 wxASSERT_MSG( item < count && item >= 0,
128 _T("logic error in wxRadioBox::GetNextItem()") );
129
130 return item;
131 }
132
133 #if WXWIN_COMPATIBILITY_2_4
134
135 // these functions are deprecated and don't do anything
136 int wxRadioBoxBase::GetNumberOfRowsOrCols() const
137 {
138 return 1;
139 }
140
141 void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n))
142 {
143 }
144
145 #endif // WXWIN_COMPATIBILITY_2_4
146
147 #endif // wxUSE_RADIOBOX