]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/radiocmn.cpp
Generate EVT_SPINCTRL_UPDATED for wxMotif, too
[wxWidgets.git] / src / common / radiocmn.cpp
... / ...
CommitLineData
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 license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
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
41int 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") );
101 return -1;
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
137#endif // wxUSE_RADIOBOX
138