void CustomGrid::OnLabeClick( wxGridEvent& event) { int row = event.GetRow(); int col = event.GetCol(); wxPoint p = event.GetPosition(); ClearSelection(); if( row == wxNOT_FOUND && event.GetCol() == wxNOT_FOUND ){ //corner label //find the first visible row/col int frow = 0, fcol = 0; GetFirstVisibleCell(frow, fcol); //then scroll as requested; MakeCellVisible(frow, m_numCols - 1); MakeCellVisible(frow, m_gParent->m_pIndex); } else if( row != wxNOT_FOUND && col == wxNOT_FOUND ){ //numerical row label int idx = GetRowIndex(row); if( idx != wxNOT_FOUND ){ if(m_IsDigit.GetChar(idx) == 'X' ) m_IsDigit.SetChar(idx, '.'); else m_IsDigit.SetChar(idx, 'X'); for( int c = 0; c < m_numCols; c++){ double value = m_NumRowVal[idx][c]; /*Current direction is generally reported as the "flow" direction, which is opposite from wind convention. So, adjust.*/ if( idx == R_CURRENT && m_IsDigit.GetChar(idx) == 'X' && value != GRIB_NOTDEF){ value += 180; if(value >= 360) value -= 360; if( value < 0 ) value += 360; } SetCellRenderer( row, c, new CustomRenderer(value, m_IsDigit.GetChar(idx) == 'X') ); } m_tRefreshTimer.Start( 10, wxTIMER_ONE_SHOT ); } } }
/** OnUpdateHideAddresses * * Called when the user wants change the hide memory address setting */ void OnUpdateHideAddresses(MemoryGrid* memory, MemoryView* memoryView, int mode) { if (!memoryView) return; if (mode == SHOW_ALL) memoryView->ShowAllAddresses(); else if (mode == SHOW_MODIFIED) { memoryView->ShowAllAddresses(); memoryView->SetDefaultVisibility(ViewAction::HIDE); memoryView->ModifyAddresses(modified_addresses); } else if (mode == SHOW_NONZERO) { std::vector<ViewRange> ranges; int start = 0; for (int current = 1; current <= 0xFFFF; current++) { if (state.mem[current] != 0 && state.mem[current - 1] == 0) start = current; else if (state.mem[current] == 0 && state.mem[current - 1] != 0) ranges.emplace_back(start, current - 1); } if (state.mem[0xFFFF] != 0) ranges.emplace_back(start, 0xFFFF); memoryView->ShowAllAddresses(); memoryView->SetDefaultVisibility(ViewAction::HIDE); memoryView->ModifyAddresses(ranges); } ///TODO learn the interface for updating a grid's dimensions via wxGridTableMessage // This is inefficient, but well... memory->SetView(memoryView); MakeCellVisible(memory, state.pc); memory->ForceRefresh(); }
void LogMessagesViewer::appendMessages() { wxCriticalSectionLocker lock( _messagesCS ); if ( _messages.empty() ) { return; } BeginBatch(); int row = GetNumberRows(); AppendRows( _messages.size() ); do { appendMessage( _messages.front(), row ); _messages.pop(); ++row; } while ( !_messages.empty() ); AutoSizeColumns(); EndBatch(); MakeCellVisible( GetNumberRows()-1, 0 ); }
void BaseGrid::SetActiveLine(AssDialogue *new_line) { if (new_line != active_line) { assert(new_line == 0 || line_index_map.count(new_line)); active_line = new_line; AnnounceActiveLineChanged(active_line); MakeCellVisible(GetDialogueIndex(active_line), 0, false); Refresh(false); extendRow = GetDialogueIndex(new_line); } }
/** SelectLocation * * Shows a location on the grid */ void MemoryGrid::SelectLocation(unsigned short location) { last_address = location; // Handles close to edge! int n_location = (location + 8 + 1) > 0xFFFF ? location : location + 8 + 1; SelectRow(location); SetGridCursor(location, 0); MakeCellVisible((location < 16) ? location : n_location, 0); Refresh(); }
/** OnGoto * * Called when the user wants to goto a certain address */ void OnGoto(MemoryGrid* memory) { wxString wxaddress = wxGetTextFromUser(_("Input Address"), _("Goto Address")); if (wxaddress.IsEmpty()) return; int addr; int error = lc3_calculate(state, wxaddress.ToStdString(), addr); if (error) { PrintError(error); return; } MakeCellVisible(memory, addr); }
void DataGrid::scrollToDay(int day) { int i; for (i = 0; i < GetNumberRows(); i++) { wxString title = GetRowLabelValue(i); if (title.length() == DATE_LEN) { struct ymd_date ymd; str_to_ymd_date(&ymd, title); if (ymd.day == day) { MakeCellVisible(i, 1); break; } } } }
///////////////////////// // Selects visible lines void BaseGrid::SelectVisible() { int rows = GetRows(); bool selectedOne = false; for (int i=0;i<rows;i++) { if (IsDisplayed(GetDialogue(i))) { if (!selectedOne) { SelectRow(i,false); MakeCellVisible(i,0); selectedOne = true; } else { SelectRow(i,true); } } } }
/** OnGoto * * Called when the user wants customize what memory addresses are shown */ void OnHideAddressesCustom(MemoryGrid* memory, MemoryView* memoryView) { ///TODO come up with a better dialog for this. std::string rangesStr = wxGetTextFromUser( "Enter a list of ranges in the format start-end,start2-end2,start3-end3\n" "Ending address for range is inclusive\n" "Example x3000-x3010,xE000-xF000", "Custom Hide Addresses").ToStdString(); if (rangesStr.empty()) return; std::vector<std::string> parsed_ranges; tokenize(rangesStr, parsed_ranges, ","); std::vector<ViewRange> ranges; for (const auto& parsed_range : parsed_ranges) { int start, end; std::vector<std::string> start_end; tokenize(parsed_range, start_end, "-"); if (start_end.size() != 2) { wxMessageBox(wxString::Format("%s is not a valid range", parsed_range), "Error"); return; } if (lc3_calculate(state, start_end[0], start) || lc3_calculate(state, start_end[1], end)) { wxMessageBox(wxString::Format("%s does not contain valid addresses or malformed", parsed_range), "Error"); return; } ranges.emplace_back(start, end); } memoryView->ShowAllAddresses(); memoryView->SetDefaultVisibility(ViewAction::HIDE); memoryView->ModifyAddresses(ranges); ///TODO learn the interface for updating a grid's dimensions via wxGridTableMessage // This is inefficient, but well... memory->SetView(memoryView); MakeCellVisible(memory, state.pc); memory->ForceRefresh(); }
void CustomGrid::OnMouseEvent( wxMouseEvent& event ) { static wxPoint s_pevt; wxPoint pevt = event.GetPosition(); #ifdef __WXOSX__ if (!m_bLeftDown && event.LeftIsDown()){ m_bLeftDown = true; s_pevt = pevt; } else if (m_bLeftDown && !event.LeftIsDown()){ m_bLeftDown = false; if (HasCapture()) ReleaseMouse(); } #else if(event.LeftDown()) s_pevt = pevt; if(event.LeftUp()){ if(HasCapture()) ReleaseMouse(); } #endif if(event.Dragging()){ int frow, fcol, lrow, lcol; GetFirstVisibleCell(frow, fcol); GetLastVisibleCell(lrow, lcol); if( pevt != s_pevt ) { bool rfh = false; int diff = pevt.x - s_pevt.x; //scrolling right if( diff > SCROLL_SENSIBILITY ){ s_pevt.x = pevt.x; if( fcol > 0 ){ MakeCellVisible(frow, fcol - 1 ); rfh = true; } } //scrolling left else if ( -diff > SCROLL_SENSIBILITY ){ s_pevt.x = pevt.x; if( lcol < m_numCols - 1 ){ MakeCellVisible(frow, lcol + 1); rfh = true; } } //scrolling down diff = pevt.y - s_pevt.y; if( diff > SCROLL_SENSIBILITY ){ s_pevt.y = pevt.y; if( frow > 0 ){ MakeCellVisible(frow - 1, fcol); rfh = true; } } //scrolling up else if( -diff > SCROLL_SENSIBILITY ) { s_pevt.y = pevt.y; if( lrow < m_numRows - 1 ){ MakeCellVisible(lrow + 1, fcol); MakeCellVisible(frow + 1, fcol); //workaroud for what seems curious moving 2 rows instead of 1 in previous function rfh = true; } } if(rfh) m_tRefreshTimer.Start( 10, wxTIMER_ONE_SHOT ); } } }
void Grid::OnKeyDown(wxKeyEvent &event) { switch (event.GetKeyCode()) { case WXK_LEFT: case WXK_RIGHT: { int rows = GetNumberRows(); int cols = GetNumberCols(); int crow = GetGridCursorRow(); int ccol = GetGridCursorCol(); if (event.GetKeyCode() == WXK_LEFT) { if (crow == 0 && ccol == 0) { // do nothing } else if (ccol == 0) { SetGridCursor(crow - 1, cols - 1); } else { SetGridCursor(crow, ccol - 1); } } else { if (crow == rows - 1 && ccol == cols - 1) { // do nothing } else if (ccol == cols - 1) { SetGridCursor(crow + 1, 0); } else { SetGridCursor(crow, ccol + 1); } } #if wxUSE_ACCESSIBILITY // Make sure the NEW cell is made available to the screen reader mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol()); #endif } break; case WXK_TAB: { int rows = GetNumberRows(); int cols = GetNumberCols(); int crow = GetGridCursorRow(); int ccol = GetGridCursorCol(); if (event.ControlDown()) { int flags = wxNavigationKeyEvent::FromTab | ( event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward ); Navigate(flags); return; } else if (event.ShiftDown()) { if (crow == 0 && ccol == 0) { Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsBackward); return; } else if (ccol == 0) { SetGridCursor(crow - 1, cols - 1); } else { SetGridCursor(crow, ccol - 1); } } else { if (crow == rows - 1 && ccol == cols - 1) { Navigate(wxNavigationKeyEvent::FromTab | wxNavigationKeyEvent::IsForward); return; } else if (ccol == cols - 1) { SetGridCursor(crow + 1, 0); } else { SetGridCursor(crow, ccol + 1); } } MakeCellVisible(GetGridCursorRow(), GetGridCursorCol()); #if wxUSE_ACCESSIBILITY // Make sure the NEW cell is made available to the screen reader mAx->SetCurrentCell(GetGridCursorRow(), GetGridCursorCol()); #endif } break; case WXK_RETURN: case WXK_NUMPAD_ENTER: { if (!IsCellEditControlShown()) { wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); wxWindow *def = tlw->GetDefaultItem(); if (def && def->IsEnabled()) { wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId()); GetParent()->GetEventHandler()->ProcessEvent(cevent); } } else { wxGrid::OnKeyDown(event); // This looks strange, but what it does is selects the cell when // enter is pressed after editing. Without it, Jaws and Window-Eyes // do not speak the NEW cell contents (the one below the edited one). SetGridCursor(GetGridCursorRow(), GetGridCursorCol()); } break; } default: wxGrid::OnKeyDown(event); break; } }
bool wex::grid::find_next(const std::string& text, bool forward) { if (text.empty()) { return false; } static bool recursive = false; static int start_row; static int end_row; static int init_row; static int start_col; static int end_col; wxString text_use = text; if (!find_replace_data::get()->match_case()) { text_use.MakeUpper(); } wxGridCellCoords grid_cursor(GetGridCursorRow(), GetGridCursorCol()); if (forward) { init_row = 0; if (recursive) { start_row = init_row; start_col = 0; } else { start_row = grid_cursor.GetRow() + 1; start_col = grid_cursor.GetCol(); } end_row = GetNumberRows(); end_col = GetNumberCols(); } else { init_row = GetNumberRows() - 1; if (recursive) { start_row = init_row; start_col = GetNumberCols() - 1; } else { start_row = grid_cursor.GetRow() - 1; start_col = grid_cursor.GetCol(); } end_row = -1; end_col = -1; } if (start_col == -1) { start_col = 0; } if (start_row == -1) { start_row = 0; } wxGridCellCoords match; for (int j = start_col; j != end_col && !match; (forward ? j++: j--)) { for (int i = (j == start_col ? start_row: init_row); i != end_row && !match; (forward ? i++: i--)) { wxString text = GetCellValue(i, j); if (!find_replace_data::get()->match_case()) { text.MakeUpper(); } if (find_replace_data::get()->match_word()) { if (text == text_use) { match = wxGridCellCoords(i, j); } } else { if (text.Contains(text_use)) { match = wxGridCellCoords(i, j); } } } } if (!match) { bool result = false; frame::statustext( get_find_result(text, forward, recursive), std::string()); if (!recursive) { recursive = true; result = find_next(text, forward); recursive = false; } return result; } else { recursive = false; SetGridCursor(match.GetRow(), match.GetCol()); MakeCellVisible(match); // though docs say this isn't necessary, it is return true; } }
///////////// // Key press void BaseGrid::OnKeyPress(wxKeyEvent &event) { // Get size int w,h; GetClientSize(&w,&h); // Get scan code int key = event.KeyCode(); bool ctrl = event.m_controlDown; bool alt = event.m_altDown; bool shift = event.m_shiftDown; // Left/right, forward to seek bar if video is loaded if (key == WXK_LEFT || key == WXK_RIGHT) { if (video->loaded) { video->ControlSlider->SetFocus(); video->ControlSlider->AddPendingEvent(event); return; } event.Skip(); return; } // Select all if (key == 'A' && ctrl && !alt && !shift) { int rows = GetRows(); for (int i=0;i<rows;i++) SelectRow(i,true); } // Up/down int dir = 0; int step = 1; if (key == WXK_UP) dir = -1; if (key == WXK_DOWN) dir = 1; if (key == WXK_PRIOR) { dir = -1; step = h/lineHeight - 2; } if (key == WXK_NEXT) { dir = 1; step = h/lineHeight - 2; } if (key == WXK_HOME) { dir = -1; step = GetRows(); } if (key == WXK_END) { dir = 1; step = GetRows(); } // Moving if (dir) { // Move selection if (!ctrl && !shift && !alt) { // Move to extent first int curLine = editBox->linen; if (extendRow != -1) { curLine = extendRow; extendRow = -1; } int next = MID(0,curLine+dir*step,GetRows()-1); editBox->SetToLine(next); SelectRow(next); MakeCellVisible(next,0,false); return; } // Move active only if (alt && !shift && !ctrl) { extendRow = -1; int next = MID(0,editBox->linen+dir*step,GetRows()-1); editBox->SetToLine(next); Refresh(false); MakeCellVisible(next,0,false); return; } // Shift-selection if (shift && !ctrl && !alt) { // Find end if (extendRow == -1) extendRow = editBox->linen; extendRow = MID(0,extendRow+dir*step,GetRows()-1); // Set range int i1 = editBox->linen; int i2 = extendRow; if (i2 < i1) { int aux = i1; i1 = i2; i2 = aux; } // Select range ClearSelection(); for (int i=i1;i<=i2;i++) { SelectRow(i,true); } MakeCellVisible(extendRow,0,false); return; } } // Other events, send to audio display if (video->audio->loaded) { video->audio->AddPendingEvent(event); } else event.Skip(); }
void BaseGrid::OnKeyDown(wxKeyEvent &event) { int w,h; GetClientSize(&w,&h); int key = event.GetKeyCode(); bool ctrl = event.CmdDown(); bool alt = event.AltDown(); bool shift = event.ShiftDown(); int dir = 0; int step = 1; if (key == WXK_UP) dir = -1; else if (key == WXK_DOWN) dir = 1; else if (key == WXK_PAGEUP) { dir = -1; step = h / lineHeight - 2; } else if (key == WXK_PAGEDOWN) { dir = 1; step = h / lineHeight - 2; } else if (key == WXK_HOME) { dir = -1; step = GetRows(); } else if (key == WXK_END) { dir = 1; step = GetRows(); } if (!dir) { event.Skip(); return; } int old_extend = extendRow; int next = mid(0, GetDialogueIndex(active_line) + dir * step, GetRows() - 1); SetActiveLine(GetDialogue(next)); // Move selection if (!ctrl && !shift && !alt) { SelectRow(next); return; } // Move active only if (alt && !shift && !ctrl) { Refresh(false); return; } // Shift-selection if (shift && !ctrl && !alt) { extendRow = old_extend; // Set range int begin = next; int end = extendRow; if (end < begin) std::swap(begin, end); // Select range Selection newsel; for (int i = begin; i <= end; i++) newsel.insert(GetDialogue(i)); SetSelectedSet(newsel); MakeCellVisible(next, 0, false); return; } }
void BaseGrid::OnMouseEvent(wxMouseEvent &event) { int h = GetClientSize().GetHeight(); bool shift = event.ShiftDown(); bool alt = event.AltDown(); bool ctrl = event.CmdDown(); // Row that mouse is over bool click = event.LeftDown(); bool dclick = event.LeftDClick(); int row = event.GetY() / lineHeight + yPos - 1; if (holding && !click) { row = mid(0,row,GetRows()-1); } AssDialogue *dlg = GetDialogue(row); if (!dlg) row = 0; if (event.ButtonDown() && OPT_GET("Subtitle/Grid/Focus Allow")->GetBool()) SetFocus(); if (holding) { if (!event.LeftIsDown()) { if (dlg) MakeCellVisible(row, 0, false); holding = false; ReleaseMouse(); } else { // Only scroll if the mouse has moved to a different row to avoid // scrolling on sloppy clicks if (row != extendRow) { if (row <= yPos) ScrollTo(yPos - 3); // When dragging down we give a 3 row margin to make it easier // to see what's going on, but we don't want to scroll down if // the user clicks on the bottom row and drags up else if (row > yPos + h / lineHeight - (row > extendRow ? 3 : 1)) ScrollTo(yPos + 3); } } } else if (click && dlg) { holding = true; CaptureMouse(); } if ((click || holding || dclick) && dlg) { int old_extend = extendRow; // SetActiveLine will scroll the grid if the row is only half-visible, // but we don't want to scroll until the mouse moves or the button is // released, to avoid selecting multiple lines on a click int old_y_pos = yPos; SetActiveLine(dlg); ScrollTo(old_y_pos); // Toggle selected if (click && ctrl && !shift && !alt) { bool isSel = !!selection.count(dlg); if (isSel && selection.size() == 1) return; SelectRow(row, true, !isSel); return; } // Normal click if ((click || dclick) && !shift && !ctrl && !alt) { if (dclick) { context->audioBox->ScrollToActiveLine(); context->videoController->JumpToTime(dlg->Start); } SelectRow(row, false); return; } // Change active line only if (click && !shift && !ctrl && alt) return; // Block select if ((click && shift && !alt) || holding) { extendRow = old_extend; int i1 = row; int i2 = extendRow; if (i1 > i2) std::swap(i1, i2); // Toggle each Selection newsel; if (ctrl) newsel = selection; for (int i = i1; i <= i2; i++) { newsel.insert(GetDialogue(i)); } SetSelectedSet(newsel); return; } return; } // Mouse wheel if (event.GetWheelRotation() != 0) { if (ForwardMouseWheelEvent(this, event)) { int step = shift ? h / lineHeight - 2 : 3; ScrollTo(yPos - step * event.GetWheelRotation() / event.GetWheelDelta()); } return; } event.Skip(); }