1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <vcl/mnemonicengine.hxx>
31 #include <vcl/i18nhelp.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/event.hxx>
35 //........................................................................
38 //........................................................................
40 //====================================================================
41 //= MnemonicEngine_Data
42 //====================================================================
43 struct MnemonicEngine_Data
45 IMnemonicEntryList
& rEntryList
;
47 MnemonicEngine_Data( IMnemonicEntryList
& _rEntryList
)
48 :rEntryList( _rEntryList
)
53 //--------------------------------------------------------------------
56 const void* lcl_getEntryForMnemonic( IMnemonicEntryList
& _rEntryList
, sal_Unicode _cMnemonic
, bool& _rbAmbiguous
)
60 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
63 const void* pSearchEntry
= _rEntryList
.FirstSearchEntry( sEntryText
);
65 const void* pFirstFoundEntry
= NULL
;
66 bool bCheckingAmbiguity
= false;
67 const void* pStartedWith
= pSearchEntry
;
68 while ( pSearchEntry
)
70 if ( rI18nHelper
.MatchMnemonic( sEntryText
, _cMnemonic
) )
72 if ( bCheckingAmbiguity
)
74 // that's the second (at least) entry with this mnemonic
76 return pFirstFoundEntry
;
79 pFirstFoundEntry
= pSearchEntry
;
80 bCheckingAmbiguity
= true;
83 pSearchEntry
= _rEntryList
.NextSearchEntry( pSearchEntry
, sEntryText
);
84 if ( pSearchEntry
== pStartedWith
)
88 return pFirstFoundEntry
;
92 //====================================================================
94 //====================================================================
95 //--------------------------------------------------------------------
96 MnemonicEngine::MnemonicEngine( IMnemonicEntryList
& _rEntryList
)
97 :m_pData( new MnemonicEngine_Data( _rEntryList
) )
101 //--------------------------------------------------------------------
102 bool MnemonicEngine::HandleKeyEvent( const KeyEvent
& _rKEvt
)
104 sal_Bool bAccelKey
= _rKEvt
.GetKeyCode().IsMod2();
108 sal_Unicode cChar
= _rKEvt
.GetCharCode();
109 bool bAmbiguous
= false;
110 const void* pEntry
= lcl_getEntryForMnemonic( m_pData
->rEntryList
, cChar
, bAmbiguous
);
114 m_pData
->rEntryList
.SelectSearchEntry( pEntry
);
116 m_pData
->rEntryList
.ExecuteSearchEntry( pEntry
);
122 //--------------------------------------------------------------------
123 MnemonicEngine::~MnemonicEngine()
127 //........................................................................
129 //........................................................................
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */