bool GLIDebugVariableGrid::OnDnDText(const wxString &newWatchName)
{
  //If currently editing, return now
  if(IsCellEditControlEnabled())
  {
    return false;
  }

  //If showing watch values or there is already too many watch variables
  if(!(gridFlags & DF_ShowWatchValues) || 
     watchValuesArray.size() >= MAX_NUM_WATCH_VALUES)
  {
    return false;
  }

  //Add the value
  UniformData newWatchData;
  newWatchData.name = newWatchName;
  newWatchData.type = GL_FLOAT;
  newWatchData.isFloatType = true;

  watchValuesArray.push_back(newWatchData);

  //Refresh the display
  int currRow    = GetGridCursorRow();
  int currColumn = GetGridCursorCol();

  //Update the grid
  RefreshGrid();
  
  //Reset the selected cell
  SetCurrentCell(currRow, currColumn);

  return true;
}
Esempio n. 2
0
void DataGrid::onKeyDown(wxKeyEvent &event)
{
	bool modified = false;
	if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) {
		if (event.ControlDown()) {
			if (!IsCellEditControlEnabled()) {
				insertRowToDataUp(GetGridCursorRow());
				modified = true;
			}
		} else {
			insertRowToData(GetGridCursorRow());
			modified = true;
		}
	} else if (event.GetKeyCode() == WXK_DELETE) {
		if (IsSelection()) {
			wxArrayInt rows = GetSelectedRows();
			if (rows.Count() > 0) {
				modified = deleteRowsFromData(rows);
			} else {
				unsigned int i;
				int row, col;
				wxGridCellCoordsArray cells = GetSelectedCells();
				for (i = 0; i < cells.Count(); i++) {
					clearCellData(cells[i].GetRow(), cells[i].GetCol());
				}
				wxGridCellCoordsArray topLeft = GetSelectionBlockTopLeft();
				wxGridCellCoordsArray bottomRight = GetSelectionBlockBottomRight();
				for (i = 0; i < topLeft.Count(); i++) {
					for (row = topLeft[i].GetRow(); row <= bottomRight[i].GetRow(); row++) {
						for (col = topLeft[i].GetCol(); col <= bottomRight[i].GetCol(); col++) {
							clearCellData(row, col);
						}
					}
				}
				wxArrayInt cols = GetSelectedCols();
				for (i = 0; i < cols.Count(); i++) {
					for (row = 1; row < GetNumberRows(); row++) {
						clearCellData(row, cols[i]);
					}
				}
			}
			ClearSelection();
		} else {
			clearCellData(GetGridCursorRow(), GetGridCursorCol());
		}
	}
	wxGrid::OnKeyDown(event);
	if (modified) updateData(true);
}
void GLIDebugVariableGrid::OnKeyDown(wxKeyEvent &keyEvent)
{
  //If in edit mode, allow all keys through
  if(IsCellEditControlEnabled())
  {
    keyEvent.Skip();
    return;
  }

  //Don't allow the enter key to switch between rows
  if(keyEvent.m_keyCode == WXK_RETURN)
  {
    //Toggle the expandable rows if necessary
    if(ToggleRowExpansion(GetGridCursorRow()))
    {
      return;
    }

    //If the cell is able to be edited, start editing
    if(!IsCurrentCellReadOnly())
    {
      EnableCellEditControl();
    }

    return;
  }

  //Delete watch values on the delete key
  if(keyEvent.m_keyCode == WXK_DELETE)
  {
    int currRow    = GetGridCursorRow();
    int currColumn = GetGridCursorCol();

    //Check that the current row is in range
    if(currRow >= 0 && currRow < rowTypeDataArray.size() &&
       rowTypeDataArray[currRow].type == RT_WatchValue)
    {
      //Can only delete old stored watch values, not in progress editing ones
      uint watchIndex = rowTypeDataArray[currRow].indexValue;
      if(watchIndex < watchValuesArray.size())
      {
        //Delete the watch value from the array
        watchValuesArray.erase(watchValuesArray.begin() + watchIndex);

        //Refresh the grid
        RefreshGrid();

        //Reset the selected cell
        SetCurrentCell(currRow, currColumn);
        return;
      }
    }
  }

  //Handle Ctrl-C to copy the contents of a cell to the clipboard
  if(keyEvent.m_keyCode == 'C' && keyEvent.m_controlDown)
  {
    if (wxTheClipboard->Open())
    {
      //Add the data this is in the current cell
      wxTheClipboard->SetData( new wxTextDataObject(GetCellValue(GetGridCursorRow(), GetGridCursorCol())) );
      wxTheClipboard->Close();
    }
  }

  //Process all other keys
  keyEvent.Skip();
}