wxTextPos wxTextCtrl::GetLastPosition() const { int numLines = GetNumberOfLines(); long posStartLastLine = XYToPosition(0, numLines - 1); long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine); return posStartLastLine + lenLastLine; }
long luConsoleEdit::getLastPromptPos() { long x = 0, y = 0; long last = GetLastPosition(); if (!PositionToXY(last, &x, &y)) return 0; return XYToPosition(0, y); }
// This is hackage to correct a problem on Leopard where the // caret jumps up two lines when the up arrow is pressed and // the caret is at the beginning of the line. void NyqTextCtrl::OnKeyDown(wxKeyEvent & e) { e.Skip(); if (UMAGetSystemVersion() >= 0x1050) { if (e.GetKeyCode() == WXK_UP && e.GetModifiers() == 0) { long x; long y; PositionToXY(GetInsertionPoint(), &x, &y); if (x == 0 && y > 1) { y--; SetInsertionPoint(XYToPosition(x, y) - 1); e.Skip(false); } } } }
int wxTextCtrl::GetLineLength(long lineNo) const { long pos = XYToPosition(0, lineNo); return GetLengthOfLineContainingPos(pos); }
void luConsoleEdit::OnKeyDown(wxKeyEvent& event) { int ch = event.GetKeyCode(); wxString str; if (ch == WXK_UP) { pasteCommand(-1); return; } else if (ch == WXK_DOWN) { pasteCommand(+1); return; } else if (ch == WXK_ESCAPE) { pasteCommand(0); replaceCommand(""); return; } else if (ch == WXK_LEFT || ch == WXK_BACK) { long x = 0, y = 0; if (PositionToXY(GetInsertionPoint(), &x, &y)) { if (x <= (int)m_prompt.Length()) return; } } else if (ch == WXK_HOME) { long x = 0, y = 0; if (PositionToXY(GetInsertionPoint(), &x, &y)) { x = m_prompt.Length(); long pos = XYToPosition(x, y); SetSelection(pos, pos); } return; } if (ch == WXK_RETURN) { str = GetLineText(GetNumberOfLines() - 1); str.Replace(m_prompt, ""); } else { event.Skip(); } if (ch == WXK_RETURN) { writeLine("\n"); str.Trim().Trim(false); if (!str.IsEmpty()) { runCmd(str, false, false); addCommand(str); } writeLine(m_prompt); pasteCommand(0); } }
void SourceView::showFile(std::string path, int proclinenum, const LINEINFOMAP *lineinfomap) { currentfile = path; SetValue("");//clear text SetDefaultStyle(wxTextAttr(*wxBLACK)); if (path == "[hint KiFastSystemCallRet]") { AppendText( " Hint: KiFastSystemCallRet often means the thread was waiting for something else to finish.\n" " \n" " Possible causes might be disk I/O, waiting for an event, or maybe just calling Sleep().\n" ); return; } if (path == "" || path == "[unknown]") { SetValue("[ No source file available for this location. ]"); return; } FILE *file = fopen(path.c_str(),"r"); if(!file) { char *crtSub = "\\crt\\src\\"; char *crt = strstr((char *)path.c_str(),crtSub); if(crt) { for(size_t i=0;i<msDevPaths.size();i++) { std::string newPath(msDevPaths[i]); newPath += crt+strlen(crtSub); path = newPath; file = fopen(path.c_str(),"r"); if(file) break; } } } if(!file) { AppendText(std::string("[ Could not open file '" + path + "'. ]").c_str()); return; } Show(false); std::string displaytext= "{\\rtf1\\ansi\\fdeff0{\\colortbl;\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;}\\cf1"; int linenum = 1;//1-based counting //int showpos = 0;//index of character to make visible in order to scroll to line where proc is defined. const int MARGIN_WIDTH = 7; char line[1024*10]; bool block=false; char blockType; while(fgets(line,sizeof(line),file)) { char outLine[1024*20]; LINEINFOMAP::const_iterator result = lineinfomap->find(linenum); if(result != lineinfomap->end()) { sprintf(outLine,"{\\b\\cf2 %0.2fs\t}",result->second.count); } else { strcpy(outLine,"\t"); } char *out = outLine+strlen(outLine); char *in = line; while(*in) { if(!block) { if(in[0] == '/' && in[1] == '/') { block = true; blockType = '/'; strcpy(out,"{\\cf3 "); out += strlen(out); } else if(in[0] == '/' && in[1] == '*') { block = true; blockType = '*'; strcpy(out,"{\\cf3 "); out += strlen(out); } else if(in[0] == '"' && ( in[-1] != '\\' || in[-2] == '\\' )) { block = true; blockType = '"'; strcpy(out,"{\\cf3 "); out += strlen(out); } if(!isCToken(in[-1]) && isCToken(in[0])) { char token[1024*10]; char *tokOut = token; while(isCToken(*in)) { *(tokOut++) = *(in++); } *tokOut=0; if(keywords.Contains(token)) { strcpy(out,"{\\cf4 "); out += strlen(out); strcpy(out,token); out += strlen(out); strcpy(out,"}"); out += strlen(out); } else { strcpy(out,token); out += strlen(token); } continue; } } else { if(blockType == '*' && in[-2] == '*' && in[-1] == '/') { block = false; strcpy(out,"}"); out += strlen(out); } else if(blockType == '"' && in[0] == '"' && ( in[-1] != '\\' || in[-2] == '\\' )) { *(out++) = '"'; block = false; strcpy(out,"}"); out += strlen(out); in++; continue; } } switch(in[0]) { case '\n': case '\r': if(block && blockType == '/') { block = false; strcpy(out,"}"); out += strlen(out); } break; case '{': case '}': case '\\': *(out++) = '\\'; *(out++) = in[0]; break; default: *(out++) = in[0]; break; } in++; } *out = 0; strcat(outLine,"\\line\n"); displaytext += outLine ;//form line to display linenum++; } displaytext += "}"; fclose(file); SendMessage((HWND)GetHWND(),EM_EXLIMITTEXT,0,displaytext.size()); SETTEXTEX settextex = { ST_DEFAULT, 1200, }; SendMessage((HWND)GetHWND(),EM_SETTEXTEX,(WPARAM)&settextex,(LPARAM)displaytext.c_str()); wxFont font(8, wxMODERN , wxNORMAL, wxNORMAL); const bool res = SetStyle(0, (long)displaytext.size(), wxTextAttr(wxNullColour, wxNullColour, font)); const int showpos = std::max((int)XYToPosition(0, std::max(proclinenum -7 , 0)), 0); ShowPosition(showpos); Show(true); }