/* TextEditor::checkBraceMatch * Checks for a brace match at the current cursor position *******************************************************************/ void TextEditor::checkBraceMatch() { #ifdef __WXMAC__ bool refresh = false; #else bool refresh = true; #endif // Check for brace match at current position int bracematch = BraceMatch(GetCurrentPos()); if (bracematch != wxSTC_INVALID_POSITION) { BraceHighlight(GetCurrentPos(), bracematch); if (refresh) Refresh(); return; } // No match, check for match at previous position bracematch = BraceMatch(GetCurrentPos() - 1); if (bracematch != wxSTC_INVALID_POSITION) { BraceHighlight(GetCurrentPos() - 1, bracematch); if (refresh) Refresh(); return; } // No match at all, clear any previous brace match BraceHighlight(-1, -1); if (refresh) Refresh(); }
/* TextEditor::showFindReplacePanel * Shows or hides the Find+Replace panel, depending on [show]. If * shown, fills the find text box with the current selection or the * current word at the caret *******************************************************************/ void TextEditor::showFindReplacePanel(bool show) { // Do nothing if no F+R panel has been set if (!panel_fr) return; // Hide if needed if (!show) { panel_fr->Hide(); panel_fr->GetParent()->Layout(); SetFocus(); return; } // Get currently selected text string find = GetSelectedText(); // Get the word at the current cursor position if there is no current selection if (find.IsEmpty()) { int ws = WordStartPosition(GetCurrentPos(), true); int we = WordEndPosition(GetCurrentPos(), true); find = GetTextRange(ws, we); } // Show the F+R panel panel_fr->Show(); panel_fr->GetParent()->Layout(); panel_fr->setFindText(find); }
void ContainerStacker::DriveToPoint() { SmartDashboard::PutNumber("TargetPosition", m_targetHeight); int position = CalculatePos(); double error = position - GetCurrentPos(); SmartDashboard::PutNumber("error, can", error); SmartDashboard::PutNumber("current, can", GetCurrentPos()); SmartDashboard::PutNumber("point, can", position); CheckSensors(); if(error > 50){ if(error > 1000) { containerLift->Set(-1); } else { containerLift->Set(-error/1000); } } else if(error < -50) { if(error < -1000) { containerLift->Set(1); } else { containerLift->Set(-error/1000); } } else { containerLift->Set(0); } }
void ContainerStacker::DriveToPoint(int point) { double error = point - GetCurrentPos(); SmartDashboard::PutNumber("error1, can", error); SmartDashboard::PutNumber("current1, can", GetCurrentPos()); SmartDashboard::PutNumber("point1, can", point); CheckSensors(); if(error > 50){ if(error > 1000) { containerLift->Set(-1); } else { containerLift->Set(-error/1000); } } else if(error < -50) { if(error < -1000) { containerLift->Set(1); } else { containerLift->Set(-error/1000); } } else { containerLift->Set(0); } }
/* TextEditor::onCharAdded * Called when a character is added to the text *******************************************************************/ void TextEditor::onCharAdded(wxStyledTextEvent& e) { // Update line numbers margin width string numlines = S_FMT("0%d", GetNumberOfLines()); SetMarginWidth(0, TextWidth(wxSTC_STYLE_LINENUMBER, numlines)); // Auto indent int currentLine = GetCurrentLine(); if (txed_auto_indent && e.GetKey() == '\n') { // Get indentation amount int lineInd = 0; if (currentLine > 0) lineInd = GetLineIndentation(currentLine - 1); // Do auto-indent if needed if (lineInd != 0) { SetLineIndentation(currentLine, lineInd); // Skip to end of tabs while (1) { int chr = GetCharAt(GetCurrentPos()); if (chr == '\t' || chr == ' ') GotoPos(GetCurrentPos()+1); else break; } } } // The following require a language to work if (language) { // Call tip if (e.GetKey() == '(' && txed_calltips_parenthesis) { openCalltip(GetCurrentPos()); } // End call tip if (e.GetKey() == ')') { CallTipCancel(); } // Comma, possibly update calltip if (e.GetKey() == ',' && txed_calltips_parenthesis) { //openCalltip(GetCurrentPos()); //if (CallTipActive()) updateCalltip(); } } // Continue e.Skip(); }
void cbStyledTextCtrl::OnKeyDown(wxKeyEvent& event) { switch (event.GetKeyCode()) { case WXK_TAB: { if (m_tabSmartJump && !(event.ControlDown() || event.ShiftDown() || event.AltDown())) { if (!AutoCompActive() && m_bracePosition != wxSCI_INVALID_POSITION) { m_lastPosition = GetCurrentPos(); GotoPos(m_bracePosition); // Need judge if it's the final brace HighlightRightBrace(); if (!m_tabSmartJump && CallTipActive()) CallTipCancel(); return; } } } break; case WXK_BACK: { if (m_tabSmartJump) { if (!(event.ControlDown() || event.ShiftDown() || event.AltDown())) { const int pos = GetCurrentPos(); const int index = s_leftBrace.Find((wxChar)GetCharAt(pos - 1)); if (index != wxNOT_FOUND && (wxChar)GetCharAt(pos) == s_rightBrace.GetChar(index)) { CharRight(); DeleteBack(); } } else if (m_lastPosition != wxSCI_INVALID_POSITION && event.ControlDown()) { GotoPos(m_lastPosition); m_lastPosition = wxSCI_INVALID_POSITION; return; } } } break; case WXK_RETURN: case WXK_ESCAPE: { if (m_tabSmartJump) m_tabSmartJump = false; } break; } event.Skip(); }
/* TextEditor::onUpdateUI * Called when anything is modified in the text editor (cursor * position, styling, text, etc) *******************************************************************/ void TextEditor::onUpdateUI(wxStyledTextEvent& e) { // Check for brace match if (txed_brace_match) checkBraceMatch(); // If a calltip is open, update it if (call_tip->IsShown()) updateCalltip(); // Do word matching if appropriate if (txed_match_cursor_word && language) { int word_start = WordStartPosition(GetCurrentPos(), true); int word_end = WordEndPosition(GetCurrentPos(), true); string current_word = GetTextRange(word_start, word_end); if (!current_word.IsEmpty() && HasFocus()) { if (current_word != prev_word_match) { prev_word_match = current_word; SetIndicatorCurrent(8); IndicatorClearRange(0, GetTextLength()); SetTargetStart(0); SetTargetEnd(GetTextLength()); SetSearchFlags(0); while (SearchInTarget(current_word) != -1) { IndicatorFillRange(GetTargetStart(), GetTargetEnd() - GetTargetStart()); SetTargetStart(GetTargetEnd()); SetTargetEnd(GetTextLength()); } } } else { SetIndicatorCurrent(8); IndicatorClearRange(0, GetTextLength()); prev_word_match = ""; } } // Hilight current line MarkerDeleteAll(1); MarkerDeleteAll(2); if (txed_hilight_current_line > 0 && HasFocus()) { int line = LineFromPosition(GetCurrentPos()); MarkerAdd(line, 1); if (txed_hilight_current_line > 1) MarkerAdd(line, 2); } e.Skip(); }
void CodeEditor::OnCharAdded(wxScintillaEvent &event) { char ch = event.GetKey(); int currentLine = GetCurrentLine(); int pos = GetCurrentPos(); if (ch == wxT('\n') && currentLine > 0) { BeginUndoAction(); wxString indent = GetLineIndentString(currentLine - 1); wxChar b = GetLastNonWhitespaceChar(); if(b == wxT('{')) { if(GetUseTabs()) indent << wxT("\t"); else indent << wxT(" "); } InsertText(pos, indent); GotoPos((int)(pos + indent.Length())); ChooseCaretX(); EndUndoAction(); } else if(ch == wxT('}')) { BeginUndoAction(); wxString line = GetLine(currentLine); line.Trim(false); line.Trim(true); if(line.Matches(wxT("}"))) { pos = GetCurrentPos() - 2; pos = FindBlockStart(pos, wxT('{'), wxT('}')); if(pos != -1) { wxString indent = GetLineIndentString(LineFromPosition(pos)); indent << wxT('}'); DelLineLeft(); DelLineRight(); pos = GetCurrentPos(); InsertText(pos, indent); GotoPos((int)(pos + indent.Length())); ChooseCaretX(); } } EndUndoAction(); } }
CString ScintillaEditor::GetWord() { int savePos = GetCurrentPos(); SendEditor(SCI_WORDLEFT); DWORD startPos = GetCurrentPos(); SendEditor(SCI_WORDRIGHTEXTEND); DWORD endPos = GetCurrentPos(); CStringA str; LPSTR buf = str.GetBufferSetLength(endPos - startPos); GetSelText(buf); str.ReleaseBuffer(endPos - startPos); SendEditor(SCI_SETCURRENTPOS, savePos); return CString(str); }
void MaterialScriptEditor::OnCharAdded(wxScintillaEvent &event) { ScintillaEditor::OnCharAdded(event); char ch = event.GetKey(); if(getCallTipManager().isTrigger(ch)) { int lineNum = GetCurrentLine(); if(lineNum != -1) { wxString line = GetLine(lineNum); int pos = GetCurrentPos() - 1; wxString word(""); wxChar ch; while(pos) { ch = GetCharAt(--pos); if(ch != ' ' && ch != '\n' && ch != '\r' && ch != '\t' && ch != '{' && ch != '}') word.Prepend(ch); else break; } wxString* tips = getCallTipManager().find(word); if(tips != NULL) { CallTipShow(pos, *tips); } } } }
wxChar CodeEditor::GetLastNonWhitespaceChar(int position /* = -1 */) { if (position == -1) position = GetCurrentPos(); int count = 0; // Used to count the number of blank lines bool foundlf = false; // For the rare case of CR's without LF's while (position) { wxChar c = GetCharAt(--position); int style = GetStyleAt(position); bool inComment = style == wxSCI_C_COMMENT || style == wxSCI_C_COMMENTDOC || style == wxSCI_C_COMMENTDOCKEYWORD || style == wxSCI_C_COMMENTDOCKEYWORDERROR || style == wxSCI_C_COMMENTLINE || style == wxSCI_C_COMMENTLINEDOC; if (c == wxT('\n')) { count++; foundlf = true; } else if (c == wxT('\r') && !foundlf) count++; else foundlf = false; if (count > 1) return 0; // Don't over-indent if (!inComment && c != wxT(' ') && c != wxT('\t') && c != wxT('\n') && c != wxT('\r')) return c; } return 0; }
void CodeEditor::HighlightBraces() { int currPos = GetCurrentPos(); int newPos = BraceMatch(currPos); if (newPos == wxSCI_INVALID_POSITION) { if(currPos > 0) newPos = BraceMatch(--currPos); } wxChar ch = GetCharAt(currPos); if (ch == wxT('{') || ch == wxT('[') || ch == wxT('(') || ch == wxT('}') || ch == wxT(']') || ch == wxT(')')) { if (newPos != wxSCI_INVALID_POSITION) { BraceHighlight(currPos, newPos); } else { BraceBadLight(currPos); } } else BraceHighlight(-1, -1); Refresh(false); }
void DlgEditMusic::s_DefEndPos() { if (StopMaj) return; MusicObject->EndPos=GetCurrentPos(); if (MusicObject->EndPos>=MusicObject->GetRealDuration()) MusicObject->EndPos=MusicObject->GetRealDuration().addMSecs(-1); ui->CustomRuler->EndPos=QTime(0,0,0,0).msecsTo(MusicObject->EndPos); RefreshControls(); }
bool SearchableEditor::find(bool newSearch) { if (!fd) fd = new FindDialog(this, ::wxGetTopLevelParent(this)); if (newSearch || findTextM.empty()) { if (newSearch) { // find selected text wxString findText(GetSelectedText()); // failing that initialize with the word at the caret if (findText.empty()) { int pos = GetCurrentPos(); int start = WordStartPosition(pos, true); int end = WordEndPosition(pos, true); if (end > start) findText = GetTextRange(start, end); } fd->SetFindText(findText); } // do not re-center dialog if it is already visible if (!fd->IsShown()) fd->Show(); fd->SetFocus(); return false; // <- caller shouldn't care about this } int start = GetSelectionEnd(); if (findFlagsM.has(se::FROM_TOP)) { start = 0; findFlagsM.remove(se::ALERT); // remove flag after first find } int end = GetTextLength(); int p = FindText(start, end, findTextM, findFlagsM.asStc()); if (p == -1) { if (findFlagsM.has(se::WRAP)) p = FindText(0, end, findTextM, findFlagsM.asStc()); if (p == -1) { if (findFlagsM.has(se::ALERT)) wxMessageBox(_("No more matches"), _("Search complete"), wxICON_INFORMATION|wxOK); return false; } } centerCaret(true); GotoPos(p); GotoPos(p + findTextM.Length()); SetSelectionStart(p); SetSelectionEnd(p + findTextM.Length()); centerCaret(false); return true; }
/// Override logic for assigning the molecule type /// @note fForceType is ignored if the sequence length is less than the /// value configured in the constructor virtual void AssignMolType(ILineErrorListener * pMessageListener) { if (GetCurrentPos(eRawPos) < m_SeqLenThreshold) { _ASSERT( (TestFlag(fAssumeNuc) ^ TestFlag(fAssumeProt) ) ); SetCurrentSeq().SetInst().SetMol(TestFlag(fAssumeNuc) ? CSeq_inst::eMol_na : CSeq_inst::eMol_aa); } else { CFastaReader::AssignMolType(pMessageListener); } }
void Edit::OnBraceMatch (wxCommandEvent &WXUNUSED(event)) { int min = GetCurrentPos (); int max = BraceMatch (min); if (max > (min+1)) { BraceHighlight (min+1, max); SetSelection (min+1, max); }else{ BraceBadLight (min); } }
void SQFuncState::AddLineInfos(SQInteger line,bool lineop,bool force) { if(_lastline!=line || force){ SQLineInfo li; li._line=line;li._op=(GetCurrentPos()+1); if(lineop)AddInstruction(_OP_LINE,0,line); _lineinfos.push_back(li); _lastline=line; } }
void ctlSQLBox::OnPositionStc(wxStyledTextEvent &event) { int pos = GetCurrentPos(); wxChar ch = GetCharAt(pos - 1); int st = GetStyleAt(pos - 1); int match; // Line numbers // Ensure we don't recurse through any paint handlers on Mac #ifdef __WXMAC__ Freeze(); #endif UpdateLineNumber(); #ifdef __WXMAC__ Thaw(); #endif // Clear all highlighting BraceBadLight(wxSTC_INVALID_POSITION); // Check for braces that aren't in comment styles, // double quoted styles or single quoted styles if ((ch == '{' || ch == '}' || ch == '[' || ch == ']' || ch == '(' || ch == ')') && st != 2 && st != 6 && st != 7) { match = BraceMatch(pos - 1); if (match != wxSTC_INVALID_POSITION) BraceHighlight(pos - 1, match); } // Roll back through the doc and highlight any unmatched braces while ((pos--) >= 0) { ch = GetCharAt(pos); st = GetStyleAt(pos); if ((ch == '{' || ch == '}' || ch == '[' || ch == ']' || ch == '(' || ch == ')') && st != 2 && st != 6 && st != 7) { match = BraceMatch(pos); if (match == wxSTC_INVALID_POSITION) { BraceBadLight(pos); break; } } } event.Skip(); }
bool cbStyledTextCtrl::AllowTabSmartJump() { const int pos = GetCurrentPos(); if (pos == wxSCI_INVALID_POSITION) return false; const int style = GetStyleAt(pos); if (IsString(style) || IsCharacter(style) || IsComment(style) || IsPreprocessor(style)) return !m_tabSmartJump; return true; }
void CodeEdit::OnCharAdded(wxStyledTextEvent& event) { // Indent the line to the same indentation as the previous line. // Adapted from http://STCntilla.sourceforge.net/STCntillaUsage.html char ch = event.GetKey(); if (ch == '\r' || ch == '\n') { int line = GetCurrentLine(); int lineLength = LineLength(line); if (line > 0 && lineLength <= 2) { wxString buffer = GetLine(line - 1); for (unsigned int i = 0; i < buffer.Length(); ++i) { if (buffer[i] != ' ' && buffer[i] != '\t') { buffer.Truncate(i); break; } } ReplaceSelection(buffer); // Remember that we just auto-indented so that the backspace // key will un-autoindent us. m_autoIndented = true; } } else if (m_enableAutoComplete && m_autoCompleteManager != NULL) { // Handle auto completion. wxString token; if (GetTokenFromPosition(GetCurrentPos() - 1, ".:", token)) { StartAutoCompletion(token); } } event.Skip(); }
SQInteger SQFuncState::PushLocalVariable(const SQObject &name) { SQInteger pos=_vlocals.size(); SQLocalVarInfo lvi; lvi._name=name; lvi._start_op=GetCurrentPos()+1; lvi._pos=_vlocals.size(); _vlocals.push_back(lvi); if(_vlocals.size()>((SQUnsignedInteger)_stacksize))_stacksize=_vlocals.size(); return pos; }
void OutputCtrl::OnCopy( wxCommandEvent& event ) { if ( GetCurrentPos() != GetAnchor() ) Copy(); else if ( wxTheClipboard->Open() ) { wxASSERT( m_Selected != -1 ); wxTheClipboard->SetData( new wxTextDataObject( GetLine( m_Selected ) ) ); wxTheClipboard->Close(); } }
void SQFuncState::SetStackSize(SQInteger n) { SQInteger size=_vlocals.size(); while(size>n){ size--; SQLocalVarInfo lvi=_vlocals.back(); if(type(lvi._name)!=OT_NULL){ lvi._end_op=GetCurrentPos(); _localvarinfos.push_back(lvi); } _vlocals.pop_back(); } }
void Edit::OnKeyDown (wxKeyEvent &event) { if (CallTipActive()) CallTipCancel(); if (event.GetKeyCode() == WXK_SPACE && event.ControlDown() && event.ShiftDown()) { int pos = GetCurrentPos(); CallTipSetBackground(*wxYELLOW); CallTipShow(pos, "This is a CallTip with multiple lines.\n" "It is meant to be a context sensitive popup helper for the user."); return; } event.Skip(); }
void wgt_QVideoPlayer::SetActualDuration(int Duration) { if (ui->CustomRuler!=NULL) { ui->CustomRuler->setMaximum(Duration-1); //ui->CustomRuler->repaint(); } ui->CustomRuler->TotalDuration=Duration; //ui->CustomRuler->repaint(); int TimeMSec =(Duration %1000); int TimeSec =int(Duration/1000); int TimeHour =TimeSec/(60*60); int TimeMinute =(TimeSec%(60*60))/60; tDuration.setHMS(TimeHour,TimeMinute,TimeSec%60,TimeMSec); ui->Position->setText(GetCurrentPos().toString(DisplayMSec?"hh:mm:ss.zzz":"hh:mm:ss")); ui->Duration->setText(tDuration.toString(DisplayMSec?"hh:mm:ss.zzz":"hh:mm:ss")); }
bool Edit::FindText(int &found_start, int &found_end, bool find_next) { const int flags = m_FindData.GetFlags(); const bool find_down = (flags & wxFR_DOWN) ? true : false; const wxString find_string = m_FindData.GetFindString(); found_start = found_end = -1; if (find_next) { GotoPos(find_down ? GetCurrentPos() : GetCurrentPos() - find_string.size()); } SearchAnchor(); // search up/down found_start = find_down ? SearchNext(flags, find_string) : SearchPrev(flags, find_string); // found if (found_start > -1) { found_end = found_start + find_string.size(); GotoPos(found_start); return true; } return false; }
/* TextEditor::findNext * Finds the next occurrence of the [find] after the caret position, * selects it and scrolls to it if needed. Returns false if the * [find] was invalid or no match was found, true otherwise *******************************************************************/ bool TextEditor::findNext(string find, int flags) { // Check search string if (find.IsEmpty()) return false; // Get current selection int sel_start = GetSelectionStart(); int sel_end = GetSelectionEnd(); // Search forwards from the end of the current selection SetSelection(GetCurrentPos(), GetCurrentPos()); SearchAnchor(); int found = SearchNext(flags, find); if (found < 0) { // Not found, loop back to start SetSelection(0, 0); SearchAnchor(); found = SearchNext(flags, find); if (found < 0) { // No match found in entire text, reset selection SetSelection(sel_start, sel_end); return false; } } // Set caret to the end of the matching text // (it defaults to the start for some dumb reason) // and scroll to the selection SetSelection(found, found + find.length()); EnsureCaretVisible(); return true; }
void DlgEditMusic::s_SliderMoved(int Value) { if (ResetPositionWanted) SetPlayerToPause(); if (InSliderMoveEvent) return; InSliderMoveEvent=true; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); // Update display in controls ui->CustomRuler->setValue(Value); ActualPosition=Value; ui->Position->setText(GetCurrentPos().toString("hh:mm:ss.zzz")); // Audio if ((audio_outputStream->state()==QAudio::ActiveState)||(audio_outputStream->state()==QAudio::IdleState)) { int len=audio_outputStream->bytesFree(); if (len>0) { Mutex.lock(); while ((AudioBufSize<len)&&(MixedMusic.ListCount()>0)) { int16_t *Packet=MixedMusic.DetachFirstPacket(true); if (Packet!=NULL) { memcpy(AudioBuf+AudioBufSize,Packet,MixedMusic.SoundPacketSize); AudioBufSize+=MixedMusic.SoundPacketSize; } } if ((len)&&(len<=AudioBufSize)) { int RealLen=audio_outputDevice->write((char *)AudioBuf,len); if (RealLen<=AudioBufSize) { memcpy(AudioBuf,AudioBuf+RealLen,AudioBufSize-RealLen); AudioBufSize-=RealLen; } } Mutex.unlock(); } } if (PlayerPlayMode && !PlayerPauseMode) { if (ActualPosition>=QTime(0,0,0,0).msecsTo(MusicObject->GetRealDuration())) { SetPlayerToPause(); // Stop if it's the end } else if (FrameList.List.count()>1) { // Process cDiaporamaObjectInfo *Frame=(cDiaporamaObjectInfo *)FrameList.DetachFirstFrame(); // Retrieve frame information delete Frame; } } QApplication::restoreOverrideCursor(); InSliderMoveEvent=false; }
void SQFuncState::SetStackSize(SQInteger n) { SQInteger size=_vlocals.size(); while(size>n){ size--; SQLocalVarInfo lvi = _vlocals.back(); if(type(lvi._name)!=OT_NULL){ if(lvi._end_op == UINT_MINUS_ONE) { //this means is an outer _outers--; } lvi._end_op = GetCurrentPos(); _localvarinfos.push_back(lvi); } _vlocals.pop_back(); } }
wxString CodeEditor::GetLineIndentString(int line) { int currLine = (line == -1) ? LineFromPosition(GetCurrentPos()) : line; wxString text = GetLine(currLine); int length = (int)text.Length(); wxString indent; for (int i = 0; i < length; ++i) { if (text[i] == wxT(' ') || text[i] == wxT('\t')) indent << text[i]; else break; } return indent; }