1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mnemonicengine.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/mnemonicengine.hxx>
35 #include <vcl/i18nhelp.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/event.hxx>
39 //........................................................................
42 //........................................................................
44 //====================================================================
45 //= MnemonicEngine_Data
46 //====================================================================
47 struct MnemonicEngine_Data
49 IMnemonicEntryList
& rEntryList
;
51 MnemonicEngine_Data( IMnemonicEntryList
& _rEntryList
)
52 :rEntryList( _rEntryList
)
57 //--------------------------------------------------------------------
60 const void* lcl_getEntryForMnemonic( IMnemonicEntryList
& _rEntryList
, sal_Unicode _cMnemonic
, bool& _rbAmbiguous
)
64 const vcl::I18nHelper
& rI18nHelper
= Application::GetSettings().GetUILocaleI18nHelper();
67 const void* pSearchEntry
= _rEntryList
.FirstSearchEntry( sEntryText
);
69 const void* pFirstFoundEntry
= NULL
;
70 bool bCheckingAmbiguity
= false;
71 const void* pStartedWith
= pSearchEntry
;
72 while ( pSearchEntry
)
74 if ( rI18nHelper
.MatchMnemonic( sEntryText
, _cMnemonic
) )
76 if ( bCheckingAmbiguity
)
78 // that's the second (at least) entry with this mnemonic
80 return pFirstFoundEntry
;
83 pFirstFoundEntry
= pSearchEntry
;
84 bCheckingAmbiguity
= true;
87 pSearchEntry
= _rEntryList
.NextSearchEntry( pSearchEntry
, sEntryText
);
88 if ( pSearchEntry
== pStartedWith
)
92 return pFirstFoundEntry
;
96 //====================================================================
98 //====================================================================
99 //--------------------------------------------------------------------
100 MnemonicEngine::MnemonicEngine( IMnemonicEntryList
& _rEntryList
)
101 :m_pData( new MnemonicEngine_Data( _rEntryList
) )
105 //--------------------------------------------------------------------
106 bool MnemonicEngine::HandleKeyEvent( const KeyEvent
& _rKEvt
)
108 BOOL bAccelKey
= _rKEvt
.GetKeyCode().IsMod2();
112 sal_Unicode cChar
= _rKEvt
.GetCharCode();
113 bool bAmbiguous
= false;
114 const void* pEntry
= lcl_getEntryForMnemonic( m_pData
->rEntryList
, cChar
, bAmbiguous
);
118 m_pData
->rEntryList
.SelectSearchEntry( pEntry
);
120 m_pData
->rEntryList
.ExecuteSearchEntry( pEntry
);
126 //--------------------------------------------------------------------
127 MnemonicEngine::~MnemonicEngine()
131 //........................................................................
133 //........................................................................