You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
3.6 KiB

  1. #include "hotkey_grid_table.h"
  2. /*
  3. * Reads the hotkey table from its stored format into a format suitable
  4. * for a wxGrid.
  5. */
  6. HotkeyGridTable::HotkeyGridTable( struct EDA_HOTKEY_CONFIG* origin ) :
  7. wxGridTableBase(),
  8. m_hotkeys()
  9. {
  10. EDA_HOTKEY_CONFIG* section;
  11. for( section = origin; section->m_HK_InfoList; section++ )
  12. {
  13. hotkey_spec spec( *section->m_SectionTag, new EDA_HOTKEY( NULL, 0, 0 ) );
  14. m_hotkeys.push_back( spec );
  15. EDA_HOTKEY** info_ptr;
  16. for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ )
  17. {
  18. EDA_HOTKEY* info = *info_ptr;
  19. hotkey_spec spec( *section->m_SectionTag, new EDA_HOTKEY( info ) );
  20. m_hotkeys.push_back( spec );
  21. }
  22. }
  23. }
  24. HotkeyGridTable::hotkey_spec_vector& HotkeyGridTable::getHotkeys()
  25. {
  26. return m_hotkeys;
  27. }
  28. int HotkeyGridTable::GetNumberRows()
  29. {
  30. return m_hotkeys.size();
  31. }
  32. int HotkeyGridTable::GetNumberCols()
  33. {
  34. return 2;
  35. }
  36. bool HotkeyGridTable::IsEmptyCell( int row, int col )
  37. {
  38. return col == 1 && m_hotkeys[row].second == 0;
  39. }
  40. wxString HotkeyGridTable::GetValue( int row, int col )
  41. {
  42. if( col == 0 )
  43. {
  44. if( m_hotkeys[row].second == 0 )
  45. {
  46. // section header
  47. return m_hotkeys[row].first;
  48. }
  49. else
  50. {
  51. return m_hotkeys[row].second->m_InfoMsg;
  52. }
  53. }
  54. else
  55. {
  56. if( m_hotkeys[row].second == 0 )
  57. {
  58. return wxString();
  59. }
  60. else
  61. {
  62. return ReturnKeyNameFromKeyCode( m_hotkeys[row].second->m_KeyCode );
  63. }
  64. }
  65. }
  66. void HotkeyGridTable::SetValue( int row, int col, const wxString& value )
  67. {
  68. }
  69. wxString HotkeyGridTable::GetTypeName( int row, int col )
  70. {
  71. return wxGRID_VALUE_STRING;
  72. }
  73. bool HotkeyGridTable::CanGetValueAs( int row, int col, const wxString& typeName )
  74. {
  75. return typeName == wxGRID_VALUE_STRING && col == 2;
  76. }
  77. bool HotkeyGridTable::CanSetValueAs( int row, int col, const wxString& typeName )
  78. {
  79. return false;
  80. }
  81. long HotkeyGridTable::GetValueAsLong( int row, int col )
  82. {
  83. return -1L;
  84. }
  85. double HotkeyGridTable::GetValueAsDouble( int row, int col )
  86. {
  87. return 0.0;
  88. }
  89. bool HotkeyGridTable::GetValueAsBool( int row, int col )
  90. {
  91. return false;
  92. }
  93. void HotkeyGridTable::SetValueAsLong( int row, int col, long value )
  94. {
  95. }
  96. void HotkeyGridTable::SetValueAsDouble( int row, int col, double value )
  97. {
  98. }
  99. void HotkeyGridTable::SetValueAsBool( int row, int col, bool value )
  100. {
  101. }
  102. void* HotkeyGridTable::GetValueAsCustom( int row, int col )
  103. {
  104. return 0;
  105. }
  106. void HotkeyGridTable::SetValueAsCustom( int row, int col, void* value )
  107. {
  108. }
  109. wxString HotkeyGridTable::GetColLabelValue( int col )
  110. {
  111. return col == 0 ? _( "Command" ) : _( "Hotkey" );
  112. }
  113. bool HotkeyGridTable::isHeader( int row )
  114. {
  115. return m_hotkeys[row].second == 0;
  116. }
  117. void HotkeyGridTable::SetKeyCode( int row, long key )
  118. {
  119. m_hotkeys[row].second->m_KeyCode = key;
  120. }
  121. void HotkeyGridTable::RestoreFrom( struct EDA_HOTKEY_CONFIG* origin )
  122. {
  123. int row = 0;
  124. EDA_HOTKEY_CONFIG* section;
  125. for( section = origin; section->m_HK_InfoList; section++ )
  126. {
  127. ++row;
  128. EDA_HOTKEY** info_ptr;
  129. for( info_ptr = section->m_HK_InfoList; *info_ptr; info_ptr++ )
  130. {
  131. EDA_HOTKEY* info = *info_ptr;
  132. m_hotkeys[row++].second->m_KeyCode = info->m_KeyCode;
  133. }
  134. }
  135. }
  136. HotkeyGridTable::~HotkeyGridTable()
  137. {
  138. hotkey_spec_vector::iterator i;
  139. for( i = m_hotkeys.begin(); i != m_hotkeys.end(); ++i )
  140. {
  141. if( i->second )
  142. {
  143. delete i->second;
  144. }
  145. }
  146. }