1 /* 2 * Copyright 1999-2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Jeremy Friesner 7 */ 8 9 10 #include "MetaKeyStateMap.h" 11 12 13 #include <stdio.h> 14 #include <string.h> 15 16 17 #include "BitFieldTesters.h" 18 19 20 MetaKeyStateMap::MetaKeyStateMap() 21 : 22 fKeyName(NULL) 23 { 24 // User MUST call SetInfo() before using! 25 } 26 27 28 MetaKeyStateMap::MetaKeyStateMap(const char* name) 29 { 30 SetInfo(name); 31 } 32 33 34 void 35 MetaKeyStateMap::SetInfo(const char* keyName) 36 { 37 fKeyName = new char[strlen(keyName) + 1]; 38 strcpy(fKeyName, keyName); 39 } 40 41 42 MetaKeyStateMap::~MetaKeyStateMap() 43 { 44 delete [] fKeyName; 45 int nr = fStateDescs.CountItems(); 46 for (int i = 0; i < nr; i++) 47 delete [] ((const char*) fStateDescs.ItemAt(i)); 48 49 nr = fStateTesters.CountItems(); 50 for (int j = 0; j < nr; j++) 51 delete ((BitFieldTester*) fStateTesters.ItemAt(j)); 52 // _stateBits are stored in-line, no need to delete them 53 } 54 55 56 void 57 MetaKeyStateMap::AddState(const char* d, const BitFieldTester* t) 58 { 59 char* copy = new char[strlen(d) + 1]; 60 strcpy(copy, d); 61 fStateDescs.AddItem(copy); 62 fStateTesters.AddItem((void *)t); 63 } 64 65 66 int 67 MetaKeyStateMap::GetNumStates() const 68 { 69 return fStateTesters.CountItems(); 70 } 71 72 73 const BitFieldTester* 74 MetaKeyStateMap::GetNthStateTester(int stateNum) const 75 { 76 return ((const BitFieldTester*) fStateTesters.ItemAt(stateNum)); 77 } 78 79 80 const char* 81 MetaKeyStateMap::GetNthStateDesc(int stateNum) const 82 { 83 return ((const char*) fStateDescs.ItemAt(stateNum)); 84 } 85 86 87 const char* 88 MetaKeyStateMap::GetName() const 89 { 90 return fKeyName; 91 } 92