summaryrefslogtreecommitdiff
path: root/vcl/source/window/dlgctrl.cxx
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-11-22 17:14:23 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-11-22 20:11:52 +0000
commitdf0cef5bc7b15c40caa9b3224d5f033063856afb (patch)
tree12779d3c500566a3f6acedfd7aba55271963301b /vcl/source/window/dlgctrl.cxx
parent1b329fd5ccc0ff270d776dfd03571da3f4d6f34d (diff)
make left-right traverse through radiobutton groups
lets preserve the traversal order from the initial grouping order, so convert the radio group set to a vector Change-Id: If057f0c5d5f2eac2e8866a8a39efde8035c4fc4a
Diffstat (limited to 'vcl/source/window/dlgctrl.cxx')
-rw-r--r--vcl/source/window/dlgctrl.cxx150
1 files changed, 121 insertions, 29 deletions
diff --git a/vcl/source/window/dlgctrl.cxx b/vcl/source/window/dlgctrl.cxx
index 26f730016a15..0ff589bc3407 100644
--- a/vcl/source/window/dlgctrl.cxx
+++ b/vcl/source/window/dlgctrl.cxx
@@ -526,6 +526,89 @@ void Window::ImplControlFocus( sal_uInt16 nFlags )
// -----------------------------------------------------------------------
+namespace
+{
+ bool isSuitableDestination(Window *pWindow)
+ {
+ return (pWindow && isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled());
+ }
+
+ bool backInGroup(std::vector<RadioButton*>::reverse_iterator aRevStart, std::vector<RadioButton*> &rGroup)
+ {
+ std::vector<RadioButton*>::reverse_iterator aI(aRevStart);
+ while (aI != rGroup.rend())
+ {
+ Window *pWindow = *aI;
+
+ if (isSuitableDestination(pWindow))
+ {
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
+ return true;
+ }
+ }
+
+ aI = rGroup.rbegin();
+ while (aI != aRevStart)
+ {
+ Window *pWindow = *aI;
+
+ if (isSuitableDestination(pWindow))
+ {
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool forwardInGroup(std::vector<RadioButton*>::iterator aStart, std::vector<RadioButton*> &rGroup)
+ {
+ std::vector<RadioButton*>::iterator aI(aStart);
+ while (++aI != rGroup.end())
+ {
+ Window *pWindow = *aI;
+
+ if (isSuitableDestination(pWindow))
+ {
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
+ return true;
+ }
+ }
+
+ aI = rGroup.begin();
+ while (aI != aStart)
+ {
+ Window *pWindow = *aI;
+
+ if (isSuitableDestination(pWindow))
+ {
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_FORWARD );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool nextInGroup(RadioButton *pSourceWindow, bool bBackward)
+ {
+ std::vector<RadioButton*> aGroup(pSourceWindow->GetRadioButtonGroup(true));
+
+ if (aGroup.size() == 1) //only one button in group
+ return false;
+
+ std::vector<RadioButton*>::iterator aStart(std::find(aGroup.begin(), aGroup.end(), pSourceWindow));
+
+ assert(aStart != aGroup.end());
+
+ if (bBackward)
+ return backInGroup(std::vector<RadioButton*>::reverse_iterator(aStart), aGroup);
+ else
+ return forwardInGroup(aStart, aGroup);
+ }
+}
+
sal_Bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, sal_Bool bKeyInput )
{
KeyCode aKeyCode = rKEvt.GetKeyCode();
@@ -796,50 +879,59 @@ sal_Bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, sal_Bool bKeyInput )
}
else if ( (nKeyCode == KEY_LEFT) || (nKeyCode == KEY_UP) )
{
- Window* pWindow = pSWindow;
- WinBits nStyle = pSWindow->GetStyle();
- if ( !(nStyle & WB_GROUP) )
+ if (pSWindow->GetType() == WINDOW_RADIOBUTTON)
+ return nextInGroup(static_cast<RadioButton*>(pSWindow), true);
+ else
{
- pWindow = prevLogicalChildOfParent(this, pWindow);
- while ( pWindow )
+ WinBits nStyle = pSWindow->GetStyle();
+ if ( !(nStyle & WB_GROUP) )
{
- pWindow = pWindow->ImplGetWindow();
+ Window* pWindow = prevLogicalChildOfParent(this, pSWindow);
+ while ( pWindow )
+ {
+ pWindow = pWindow->ImplGetWindow();
- nStyle = pWindow->GetStyle();
+ nStyle = pWindow->GetStyle();
- if ( isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled() )
- {
- if ( pWindow != pSWindow )
- pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
- return sal_True;
- }
+ if ( isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled() )
+ {
+ if ( pWindow != pSWindow )
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
+ return sal_True;
+ }
- if ( nStyle & WB_GROUP )
- break;
+ if ( nStyle & WB_GROUP )
+ break;
- pWindow = prevLogicalChildOfParent(this, pWindow);
+ pWindow = prevLogicalChildOfParent(this, pWindow);
+ }
}
}
}
else if ( (nKeyCode == KEY_RIGHT) || (nKeyCode == KEY_DOWN) )
{
- Window* pWindow = nextLogicalChildOfParent(this, pSWindow);
- while ( pWindow )
+ if (pSWindow->GetType() == WINDOW_RADIOBUTTON)
+ return nextInGroup(static_cast<RadioButton*>(pSWindow), false);
+ else
{
- pWindow = pWindow->ImplGetWindow();
+ Window* pWindow = nextLogicalChildOfParent(this, pSWindow);
+ while ( pWindow )
+ {
+ pWindow = pWindow->ImplGetWindow();
- WinBits nStyle = pWindow->GetStyle();
+ WinBits nStyle = pWindow->GetStyle();
- if ( nStyle & WB_GROUP )
- break;
+ if ( nStyle & WB_GROUP )
+ break;
- if ( isVisibleInLayout(pWindow) && isEnabledInLayout(pWindow) && pWindow->IsInputEnabled() )
- {
- pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
- return sal_True;
- }
+ if (isSuitableDestination(pWindow))
+ {
+ pWindow->ImplControlFocus( GETFOCUS_CURSOR | GETFOCUS_BACKWARD );
+ return sal_True;
+ }
- pWindow = nextLogicalChildOfParent(this, pWindow);
+ pWindow = nextLogicalChildOfParent(this, pWindow);
+ }
}
}
else
@@ -860,7 +952,7 @@ sal_Bool Window::ImplDlgCtrl( const KeyEvent& rKEvt, sal_Bool bKeyInput )
}
}
- if ( pButtonWindow && isVisibleInLayout(pButtonWindow) && isEnabledInLayout(pButtonWindow) && pButtonWindow->IsInputEnabled() )
+ if (isSuitableDestination(pButtonWindow))
{
if ( bKeyInput )
{