]>
Commit | Line | Data |
---|---|---|
e421922f VZ |
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> | |
65571936 | 9 | // License: wxWindows licence |
e421922f VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e421922f VZ |
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::GetNextItem(int item, wxDirection dir, long style) const | |
42 | { | |
43 | int count = GetCount(), | |
44 | numCols = GetColumnCount(), | |
45 | numRows = GetRowCount(); | |
46 | ||
47 | bool horz = (style & wxRA_SPECIFY_COLS) != 0; | |
48 | ||
49 | switch ( dir ) | |
50 | { | |
51 | case wxUP: | |
52 | if ( horz ) | |
53 | { | |
54 | item -= numCols; | |
55 | } | |
56 | else // vertical layout | |
57 | { | |
58 | if ( !item-- ) | |
59 | item = count - 1; | |
60 | } | |
61 | break; | |
62 | ||
63 | case wxLEFT: | |
64 | if ( horz ) | |
65 | { | |
66 | if ( !item-- ) | |
67 | item = count - 1; | |
68 | } | |
69 | else // vertical layout | |
70 | { | |
71 | item -= numRows; | |
72 | } | |
73 | break; | |
74 | ||
75 | case wxDOWN: | |
76 | if ( horz ) | |
77 | { | |
78 | item += numCols; | |
79 | } | |
80 | else // vertical layout | |
81 | { | |
82 | if ( ++item == count ) | |
83 | item = 0; | |
84 | } | |
85 | break; | |
86 | ||
87 | case wxRIGHT: | |
88 | if ( horz ) | |
89 | { | |
90 | if ( ++item == count ) | |
91 | item = 0; | |
92 | } | |
93 | else // vertical layout | |
94 | { | |
95 | item += numRows; | |
96 | } | |
97 | break; | |
98 | ||
99 | default: | |
100 | wxFAIL_MSG( _T("unexpected wxDirection value") ); | |
701a0b47 | 101 | return wxNOT_FOUND; |
e421922f VZ |
102 | } |
103 | ||
104 | // ensure that the item is in range [0..count) | |
105 | if ( item < 0 ) | |
106 | { | |
107 | // first map the item to the one in the same column but in the last row | |
108 | item += count; | |
109 | ||
110 | // now there are 2 cases: either it is the first item of the last row | |
111 | // in which case we need to wrap again and get to the last item or we | |
112 | // can just go to the previous item | |
113 | if ( item % (horz ? numCols : numRows) ) | |
114 | item--; | |
115 | else | |
116 | item = count - 1; | |
117 | } | |
118 | else if ( item >= count ) | |
119 | { | |
120 | // same logic as above | |
121 | item -= count; | |
122 | ||
123 | // ... except that we need to check if this is not the last item, not | |
124 | // the first one | |
125 | if ( (item + 1) % (horz ? numCols : numRows) ) | |
126 | item++; | |
127 | else | |
128 | item = 0; | |
129 | } | |
130 | ||
131 | wxASSERT_MSG( item < count && item >= 0, | |
132 | _T("logic error in wxRadioBox::GetNextItem()") ); | |
133 | ||
134 | return item; | |
135 | } | |
136 | ||
18c509fb VZ |
137 | #if WXWIN_COMPATIBILITY_2_4 |
138 | ||
bd0a76e2 VZ |
139 | // these functions are deprecated and don't do anything |
140 | int wxRadioBoxBase::GetNumberOfRowsOrCols() const | |
141 | { | |
142 | return 1; | |
143 | } | |
144 | ||
145 | void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n)) | |
146 | { | |
147 | } | |
148 | ||
18c509fb VZ |
149 | #endif // WXWIN_COMPATIBILITY_2_4 |
150 | ||
b4efc9b9 WS |
151 | #if WXWIN_COMPATIBILITY_2_2 |
152 | ||
153 | int wxRadioBoxBase::Number() const | |
154 | { | |
155 | return GetCount(); | |
156 | } | |
157 | ||
158 | wxString wxRadioBoxBase::GetLabel(int n) const | |
159 | { | |
160 | return GetString(n); | |
161 | } | |
162 | ||
163 | void wxRadioBoxBase::SetLabel(int n, const wxString& label) | |
164 | { | |
165 | SetString(n, label); | |
166 | } | |
167 | ||
168 | #endif // WXWIN_COMPATIBILITY_2_2 | |
169 | ||
e421922f VZ |
170 | #endif // wxUSE_RADIOBOX |
171 |