Debian Codegraph @

src/af/xap/xp/xap_InputModes.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 * Copyright (C) 2004 Hubert Figuiere
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301 USA.
19 */
20
21
22 #include "ut_assert.h"
23 #include "ut_string.h"
24
25 #include "xap_InputModes.h"
26
27 //////////////////////////////////////////////////////////////////
28 //////////////////////////////////////////////////////////////////
29
30 XAP_InputModes::XAP_InputModes(void)
31 {
32 m_indexCurrentEventMap = 0;
33 }
34
35 XAP_InputModes::~XAP_InputModes(void)
36 {
37 UT_ASSERT(m_vecEventMaps.getItemCount() == m_vecNames.getItemCount());
38
39 UT_VECTOR_PURGEALL(EV_EditEventMapper *, m_vecEventMaps);
40 UT_VECTOR_FREEALL(char *, m_vecNames);
41 }
42
43 bool XAP_InputModes::createInputMode(const char * szName,
44 EV_EditBindingMap * pBindingMap)
45 {
46 UT_ASSERT(szName && *szName);
47 UT_ASSERT(pBindingMap);
48
49 char * szDup = NULL;
50 EV_EditEventMapper * pEEM = NULL;
51
52 szDup = g_strdup(szName);
53 UT_ASSERT(szDup);
54
55 pEEM = new EV_EditEventMapper(pBindingMap);
56 UT_ASSERT(pEEM);
57
58 bool b1;
59 b1 = (m_vecEventMaps.addItem(pEEM) == 0);
60 bool b2;
61 b2 = (m_vecNames.addItem(szDup) == 0);
62 UT_ASSERT(b1 && b2);
63 UT_UNUSED(b1);
64 UT_UNUSED(b2);
65
66 return true;
67 }
68
69 bool XAP_InputModes::setCurrentMap(const char * szName)
70 {
71 UT_uint32 kLimit = m_vecNames.getItemCount();
72 UT_uint32 k;
73
74 for (k=0; k<kLimit; k++)
75 if (g_ascii_strcasecmp(szName,reinterpret_cast<const char *>(m_vecNames.getNthItem(k))) == 0)
76 {
77 m_indexCurrentEventMap = k;
78 return true;
79 }
80
81 return false;
82 }
83
84 EV_EditEventMapper * XAP_InputModes::getCurrentMap(void) const
85 {
86 return static_cast<EV_EditEventMapper *>(m_vecEventMaps.getNthItem(m_indexCurrentEventMap));
87 }
88
89 const char * XAP_InputModes::getCurrentMapName(void) const
90 {
91 return reinterpret_cast<const char *>(m_vecNames.getNthItem(m_indexCurrentEventMap));
92 }
93
94 EV_EditEventMapper * XAP_InputModes::getMapByName(const char * szName) const
95 {
96 UT_uint32 kLimit = m_vecNames.getItemCount();
97 UT_uint32 k;
98
99 for (k=0; k<kLimit; k++)
100 if (g_ascii_strcasecmp(szName,reinterpret_cast<const char *>(m_vecNames.getNthItem(k))) == 0)
101 return static_cast<EV_EditEventMapper *>(m_vecEventMaps.getNthItem(k));
102
103 return NULL;
104 }
105