]> git.saurik.com Git - wxWidgets.git/blame - src/common/radiocmn.cpp
re-renamed DoCreate() to XmDoCreateTLW() to avoid virtual function hiding in other...
[wxWidgets.git] / src / common / radiocmn.cpp
CommitLineData
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
e421922f
VZ
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
8ba7c771
VZ
37int 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
e421922f
VZ
49int 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") );
701a0b47 109 return wxNOT_FOUND;
e421922f
VZ
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
18c509fb
VZ
145#if WXWIN_COMPATIBILITY_2_4
146
bd0a76e2
VZ
147// these functions are deprecated and don't do anything
148int wxRadioBoxBase::GetNumberOfRowsOrCols() const
149{
150 return 1;
151}
152
153void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n))
154{
155}
156
18c509fb
VZ
157#endif // WXWIN_COMPATIBILITY_2_4
158
b4efc9b9
WS
159#if WXWIN_COMPATIBILITY_2_2
160
161int wxRadioBoxBase::Number() const
162{
163 return GetCount();
164}
165
166wxString wxRadioBoxBase::GetLabel(int n) const
167{
168 return GetString(n);
169}
170
171void wxRadioBoxBase::SetLabel(int n, const wxString& label)
172{
173 SetString(n, label);
174}
175
176#endif // WXWIN_COMPATIBILITY_2_2
177
e421922f
VZ
178#endif // wxUSE_RADIOBOX
179