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