1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_VCL_MNEMONICENGINE_HXX
21 #define INCLUDED_VCL_MNEMONICENGINE_HXX
23 #include <vcl/dllapi.h>
25 #include <sal/config.h>
26 #include <sal/types.h>
27 #include <rtl/ustring.hxx>
39 //= IMnemonicEntryList
41 /// callback for a MnemonicEngine
42 class SAL_NO_VTABLE VCL_DLLPUBLIC IMnemonicEntryList
45 /** returns the first list entry for the mnemonic search
48 a pointer which can be used to unuquely identify the entry.
49 The MenomonicEngine itself does not use this value, it
50 is only passed to other methods of this callback interface.
52 If this value is NULL, searching stops.
54 virtual const void* FirstSearchEntry( OUString
& _rEntryText
) const = 0;
56 /** returns the next list entry for the mnemonic search
59 a pointer which can be used to unuquely identify the entry.
60 The MenomonicEngine itself does not use this value, it
61 is only passed to other methods of this callback interface.
63 If this value is NULL, searching stops.
65 If this value is the same as returned by the previous call
66 to FirstSearchEntry (i.e. you cycled
67 around), then searching stops, too.
69 virtual const void* NextSearchEntry( const void* _pCurrentSearchEntry
, OUString
& _rEntryText
) const = 0;
71 /** "selects" a given entry.
73 Note: The semantics of "select" depends on your implementation. You
74 might actually really select the entry (in the sense of a selected
75 list box entry, for example), you might make it the current entry,
76 if your implementation supports this - whatever.
79 the entry to select. This is the return value of a previous call
80 to FirstSearchEntry or NextSearchEntry.
82 virtual void SelectSearchEntry( const void* _pEntry
) = 0;
84 /** "executes" the current search entry, i.e. the one returned
85 in the previous NextSearchEntry call.
87 Note: The semantics of "execute" depends on your implementation. You
88 might even have a list of entries which cannot be executed at all.
90 This method is called after SelectSearchEntry,
91 if and only if the current entry's mnemonic is unambiguous.
93 For instance, imagine a list which has two entries with the same mnemonic
94 character, say "c". Now if the user presses <code>Alt-C</code>, the MnemonicEngine
95 will call SelectCurrentEntry as soon as it encounters
96 the first entry, but it'll never call ExecuteSearchEntry.
98 If, however, "c" is a unique mnemonic character in your entry list, then the
99 call of SelectSearchEntry will be followed by a
100 call to ExecuteSearchEntry.
102 This way, you can implement cyclic selection of entries: In
103 FirstSearchEntry, return the entry which was previously
104 selected, and in NextSearchEntry, interlly cycle around
105 in your list. Then, multiple user inputs of <code>Alt-C</code> will
106 cycle through all entries with the mnemonic being "c".
109 the entry to select. This is the return value of a previous call
110 to FirstSearchEntry or NextSearchEntry.
112 virtual void ExecuteSearchEntry( const void* _pEntry
) const = 0;
115 ~IMnemonicEntryList() {}
121 struct MnemonicEngine_Data
;
122 class VCL_DLLPUBLIC MnemonicEngine
124 ::std::unique_ptr
< MnemonicEngine_Data
> m_pData
;
127 MnemonicEngine( IMnemonicEntryList
& _rEntryList
);
130 /** handles a key event
132 If the key event denotes pressing an accelerator key, then the
133 entry list is searched for a matching entry. If such an entry is
134 found, IMnemonicEntryList::SelectSearchEntry
137 If the entry is the only one with the given mnemonic character, then
138 also IMnemonicEntryList::ExecuteSearchEntry
142 if the key event has been handled, and should thus not be processed
145 bool HandleKeyEvent( const KeyEvent
& _rKEvt
);
152 #endif // INCLUDED_VCL_MNEMONICENGINE_HXX
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */