Beispiel #1
0
/* 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);
}
Beispiel #2
0
/* TextEditor::openCalltip
 * Opens a calltip for the function name before [pos]. Returns false
 * if the word before [pos] was not a function name, true otherwise
 *******************************************************************/
bool TextEditor::openCalltip(int pos, int arg)
{
	// Don't bother if no language
	if (!language)
		return false;

	// Get start of word before bracket
	int start = WordStartPosition(pos - 1, false);

	// Get word before bracket
	string word = GetTextRange(WordStartPosition(start, true), WordEndPosition(start, true));

	// Get matching language function (if any)
	TLFunction* func = language->getFunction(word);

	// Show calltip if it's a function
	if (func && func->nArgSets() > 0)
	{
		CallTipShow(pos, func->generateCallTipString());
		ct_function = func;
		ct_argset = 0;
		ct_start = pos;

		// Highlight arg
		point2_t arg_ext = ct_function->getArgTextExtent(arg);
		CallTipSetHighlight(arg_ext.x, arg_ext.y);

		return true;
	}
	else
	{
		ct_function = NULL;
		return false;
	}
}
wxString wxSTEditorShell::GetPromptText()
{
    int prompt_line = GetPromptLine();
    int start_pos   = PositionFromLine(prompt_line);
    int end_pos     = GetLength();
    wxString text(GetTextRange(start_pos, end_pos));
    return text;
}
Beispiel #4
0
/* TextEditor::onMouseDown
 * Called when a mouse button is clicked
 *******************************************************************/
void TextEditor::onMouseDown(wxMouseEvent& e)
{
	e.Skip();

	// No language, no checks
	if (!language)
		return;

	// Check for ctrl+left (web lookup)
	if (e.LeftDown() && e.GetModifiers() == wxMOD_CMD)
	{
		int pos = CharPositionFromPointClose(e.GetX(), e.GetY());
		string word = GetTextRange(WordStartPosition(pos, true), WordEndPosition(pos, true));

		if (!word.IsEmpty())
		{
			// TODO: Reimplement for word lists
			//// Check for keyword
			//if (language->isKeyword(word))
			//{
			//	string url = language->getKeywordLink();
			//	if (!url.IsEmpty())
			//	{
			//		url.Replace("%s", word);
			//		wxLaunchDefaultBrowser(url);
			//	}
			//}

			//// Check for constant
			//else if (language->isConstant(word))
			//{
			//	string url = language->getConstantLink();
			//	if (!url.IsEmpty())
			//	{
			//		url.Replace("%s", word);
			//		wxLaunchDefaultBrowser(url);
			//	}
			//}

			// Check for function
			if (language->isFunction(word))
			{
				string url = language->getFunctionLink();
				if (!url.IsEmpty())
				{
					url.Replace("%s", word);
					wxLaunchDefaultBrowser(url);
				}
			}

			hideCalltip();
		}
	}

	if (e.RightDown() || e.LeftDown())
		hideCalltip();
}
Beispiel #5
0
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;
}
Beispiel #6
0
/* 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();
}
Beispiel #7
0
void SourceEdit::OnFormatComment(UINT id)
{
  CallEdit(SCI_BEGINUNDOACTION);

  int line1 = (int)CallEdit(SCI_LINEFROMPOSITION,CallEdit(SCI_GETSELECTIONSTART));
  int line2 = (int)CallEdit(SCI_LINEFROMPOSITION,CallEdit(SCI_GETSELECTIONEND));

  // Check that this is not the last line of a multi-line selection with the cursor at the line's start
  if ((line2 > line1) && (CallEdit(SCI_POSITIONFROMLINE,line2) == CallEdit(SCI_GETSELECTIONEND)))
    line2--;

  // Get the start of the first line and the end of the last line
  int pos1 = (int)CallEdit(SCI_POSITIONFROMLINE,line1);
  int pos2 = (int)CallEdit(SCI_GETLINEENDPOSITION,line2);

  if ((pos1 >= 0) && (pos2 > pos1))
  {
    // Get the first and last characters
    int len = (int)CallEdit(SCI_GETLENGTH);
    CStringW text1 = GetTextRange(pos1,pos1+1,len);
    CStringW text2 = GetTextRange(pos2-1,pos2,len);

    if ((id == ID_FORMAT_COMMENT) && (text1 != L"[") && (text2 != L"]"))
    {
      CallEdit(SCI_SETTARGETSTART,pos2);
      CallEdit(SCI_SETTARGETEND,pos2);
      CallEdit(SCI_REPLACETARGET,1,(LONG_PTR)"]");
      CallEdit(SCI_SETTARGETSTART,pos1);
      CallEdit(SCI_SETTARGETEND,pos1);
      CallEdit(SCI_REPLACETARGET,1,(LONG_PTR)"[");
    }
    else if ((id == ID_FORMAT_UNCOMMENT) && (text1 == L"[") && (text2 == L"]"))
    {
      CallEdit(SCI_SETTARGETSTART,pos2-1);
      CallEdit(SCI_SETTARGETEND,pos2);
      CallEdit(SCI_REPLACETARGET,0,(LONG_PTR)"");
      CallEdit(SCI_SETTARGETSTART,pos1);
      CallEdit(SCI_SETTARGETEND,pos1+1);
      CallEdit(SCI_REPLACETARGET,0,(LONG_PTR)"");
    }
  }
  CallEdit(SCI_ENDUNDOACTION);
}
Beispiel #8
0
void SourceEdit::Search(LPCWSTR text, std::vector<SearchWindow::Result>& results)
{
  CWaitCursor wc;

  int len = (int)CallEdit(SCI_GETLENGTH);
  TextToFind find;
  find.chrg.cpMin = 0;
  find.chrg.cpMax = len;
  CString textUtf = TextFormat::UnicodeToUTF8(text);
  find.lpstrText = (char*)(LPCSTR)textUtf;

  while (true)
  {
    // Search for the text
    if (CallEdit(SCI_FINDTEXT,0,(sptr_t)&find) == -1)
      return;

    // Get the surrounding text as context
    CStringW leading = GetTextRange(find.chrgText.cpMin-4,find.chrgText.cpMin,len);
    CStringW match = GetTextRange(find.chrgText.cpMin,find.chrgText.cpMax,len);
    CStringW trailing = GetTextRange(find.chrgText.cpMax,find.chrgText.cpMax+32,len);
    CStringW context = leading + match + trailing;
    context.Replace(L'\n',L' ');
    context.Replace(L'\r',L' ');
    context.Replace(L'\t',L' ');

    // Store the found result
    SearchWindow::Result result;
    result.context = context;
    result.inContext.cpMin = leading.GetLength();
    result.inContext.cpMax = leading.GetLength() + match.GetLength();
    result.sourceLocation = SOURCE_FILE;
    result.inSource.cpMin = find.chrgText.cpMin;
    result.inSource.cpMax = find.chrgText.cpMax;
    results.push_back(result);

    // Look for the next match
    find.chrg.cpMin = find.chrgText.cpMax;
    theApp.RunMessagePump();
  }
}
Beispiel #9
0
LRESULT ChatCtrl::onClientEnLink(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) {
	ENLINK* pEL = (ENLINK*)pnmh;

	if ( pEL->msg == WM_LBUTTONUP ) {
		long lBegin = pEL->chrg.cpMin, lEnd = pEL->chrg.cpMax;
		TCHAR* sURLTemp = new TCHAR[(lEnd - lBegin)+1];
		if(sURLTemp) {
			GetTextRange(lBegin, lEnd, sURLTemp);
			tstring sURL = sURLTemp;

			if(magnets.find(sURL) == magnets.end()) {
		WinUtil::openLink(sURL);
			} else {
				WinUtil::parseMagnetUri(magnets[sURL]);
			}
	
			delete[] sURLTemp;
		}
	} else if(pEL->msg == WM_RBUTTONUP) {
		selectedURL = Util::emptyStringT;
		long lBegin = pEL->chrg.cpMin, lEnd = pEL->chrg.cpMax;
		TCHAR* sURLTemp = new TCHAR[(lEnd - lBegin)+1];
		if(sURLTemp) {
			GetTextRange(lBegin, lEnd, sURLTemp);

			if(magnets.find(sURLTemp) == magnets.end()) {
			selectedURL = sURLTemp;
			} else {
				selectedURL = magnets[sURLTemp];
			}

			delete[] sURLTemp;
		}

		SetSel(lBegin, lEnd);
		InvalidateRect(NULL);
	}
	return 0;
}
void TranscriptEdit::OnKillFocus(CWnd* pNewWnd)
{
  RichEdit::OnKillFocus(pNewWnd);
  ShowWindow(SW_HIDE);

  if (m_node != NULL)
  {
    CStringW text;
    GetTextRange(0,-1,text);
    GetParent()->SendMessage(WM_SETEXPECTED,(WPARAM)m_node,(LPARAM)(LPCWSTR)text);
  }
  GetParent()->Invalidate();
  m_node = NULL;
}
Beispiel #11
0
static void SelectMatchingJumpLocations(const Location& location)
{
	if (IsLocationValid(location))
	{
		std::string jumpLocationText = GetTextRange(location.first, location.second);

		// A location of "()" is interpreted as an empty jump
		// location which should not match other emtpy locations
		if (jumpLocationText == "()")
		{
			return;
		}

		int startPos = 0;
		do {
			auto match = FindNextJumpLocation(startPos, false);
			startPos = match.second + 1;

			if (IsLocationValid(match))
			{
				if (match.first != location.first)
				{
					std::string nextLocationText = GetTextRange(match.first, match.second);

					if (jumpLocationText == nextLocationText)
					{
						editor.AddSelection(match.second, match.first);
					}
				}
			}
			else
			{
				break;
			}
		} while (startPos != INVALID_POSITION);
	}
}
BOOL CRichEditCtrlX::OnEnLink(NMHDR *pNMHDR, LRESULT *pResult)
{
	BOOL bMsgHandled = FALSE;
	*pResult = 0;
	ENLINK* pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
	if (pEnLink && pEnLink->msg == WM_LBUTTONDOWN)
	{
		CString strUrl;
		GetTextRange(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax, strUrl);

		ShellExecute(NULL, NULL, strUrl, NULL, NULL, SW_SHOWDEFAULT);
		*pResult = 1;
		bMsgHandled = TRUE; // do not route this message to any parent
	}
	return bMsgHandled;
}
tstring::size_type CFulEditCtrl::TextUnderCursor(POINT mousePT, tstring& x) {
	
	tstring::size_type start = tstring::npos;

	int ch = CharFromPos(mousePT);
	POINT charPT = PosFromChar(ch);

	//since CharFromPos returns the last character even if the cursor is past the end of text
	//we have to check if the pointer was actually above the last char

	//check xpos
	if( mousePT.x > ( charPT.x + 3 ) ) 
		return start;

	//check ypos
	if( mousePT.y > (charPT.y + fontHeight ) )
		return start;

	FINDTEXT ft;
	ft.chrg.cpMin = ch;
	ft.chrg.cpMax = -1;
	ft.lpstrText = _T("\r");

	int begin = (int)SendMessage(EM_FINDTEXT, 0, (LPARAM)&ft) + 1;
	int rEnd = (int)SendMessage(EM_FINDTEXT, FR_DOWN, (LPARAM)&ft);

	if(begin < 0) {
		begin = 0;
	}

	if(rEnd == -1) {
		rEnd = GetTextLengthEx(GTL_NUMCHARS);
	}

	if(rEnd > begin) {
		TCHAR *buf = new TCHAR[(rEnd-begin)+1];
		if(buf) {
			GetTextRange(begin, rEnd, buf);
			x = buf;
			delete[] buf;
			start = ch - begin;
		}
	}
	return start;
}
Beispiel #14
0
bool ChatCtrl::HitIP(const POINT& p, tstring& sIP, int& iBegin, int& iEnd) {
	int iCharPos = CharFromPos(p), len = LineLength(iCharPos) + 1;
	if(len < 3)
		return false;

	DWORD lPosBegin = FindWordBreak(WB_LEFT, iCharPos);
	DWORD lPosEnd = FindWordBreak(WB_RIGHTBREAK, iCharPos);
	len = lPosEnd - lPosBegin;

	tstring sText;
	sText.resize(len);
	GetTextRange(lPosBegin, lPosEnd, &sText[0]);

	for(int i = 0; i < len; i++) {
		if(!((sText[i] == 0) || (sText[i] == '.') || ((sText[i] >= '0') && (sText[i] <= '9')))) {
			return false;
		}
	}

	sText += _T('.');
	size_t iFindBegin = 0, iPos = tstring::npos, iEnd2 = 0;

	for(int i = 0; i < 4; ++i) {
		iPos = sText.find(_T('.'), iFindBegin);
		if(iPos == tstring::npos) {
			return false;
		}
		iEnd2 = atoi(Text::fromT(sText.substr(iFindBegin)).c_str());
		if((iEnd2 < 0) || (iEnd2 > 255)) { // 13197	V547	Expression 'iEnd2 < 0' is always false. Unsigned type value is never < 0.
			return false;
		}
		iFindBegin = iPos + 1;
	}

		sIP = sText.substr(0, iPos);
		iBegin = lPosBegin;
		iEnd = lPosEnd;

	return true;
}
Beispiel #15
0
/* TextEditor::openCalltip
 * Opens a calltip for the function name before [pos]. Returns false
 * if the word before [pos] was not a function name, true otherwise
 *******************************************************************/
bool TextEditor::openCalltip(int pos, int arg, bool dwell)
{
	// Don't bother if no language
	if (!language)
		return false;

	// Get start of word before bracket
	int start = WordStartPosition(pos - 1, false);
	int end = WordEndPosition(pos - 1, true);

	// Get word before bracket
	string word = GetTextRange(WordStartPosition(start, true), WordEndPosition(start, true));

	// Get matching language function (if any)
	TLFunction* func = language->getFunction(word);

	// Show calltip if it's a function
	if (func && func->nArgSets() > 0)
	{
		call_tip->enableArgSwitch(!dwell && func->nArgSets() > 1);
		call_tip->openFunction(func, arg);
		showCalltip(dwell ? pos : end + 1);

		ct_function = func;
		ct_start = pos;
		ct_dwell = dwell;

		// Highlight arg
		call_tip->setCurrentArg(arg);

		return true;
	}
	else
	{
		ct_function = nullptr;
		return false;
	}
}
Beispiel #16
0
static void PreProcessJumpLocation(Location& location)
{
	if (IsLocationValid(location))
	{
		// For empty locations e.g. "$()" replace it with "()"
		if (location.second - location.first == strlen("$()"))
		{
			editor.SetTargetRange(location.first, location.second);
			editor.ReplaceTarget(-1, "()");
		}
		else
		{
			// Remove the "$(" and ")" to just keep the text
			std::string text = GetTextRange(location.first, location.second);
			editor.SetTargetRange(location.first, location.second);
			editor.ReplaceTarget((int)text.length() - 3, &text[2]);
		}

		// Set the location to the new range
		location.first = editor.GetTargetStart();
		location.second = editor.GetTargetEnd();
	}
}
BOOL CHTRichEditCtrl::OnEnLink(NMHDR *pNMHDR, LRESULT *pResult)
{
	BOOL bMsgHandled = FALSE;
	*pResult = 0;
	ENLINK* pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
	if (pEnLink && pEnLink->msg == WM_LBUTTONDOWN)
	{
		CString strUrl;
		GetTextRange(pEnLink->chrg.cpMin, pEnLink->chrg.cpMax, strUrl);

		// check if that "URL" has a valid URL scheme. if it does not have, pass that notification up to the
		// parent window which may interpret that "URL" in some other way.
		for (int i = 0; i < ARRSIZE(_apszSchemes); i++){
			if (_tcsncmp(strUrl, _apszSchemes[i].pszScheme, _apszSchemes[i].iLen) == 0){
				ShellExecute(NULL, NULL, strUrl, NULL, NULL, SW_SHOWDEFAULT);
				*pResult = 1;
				bMsgHandled = TRUE; // do not route this message to any parent
				break;
			}
		}
	}
	return bMsgHandled;
}
Beispiel #18
0
/**
 * CHaracter added
 */ 
void FbEditor::onCharAdded(wxStyledTextEvent & event)
{
    int p = GetCurrentPos();
    auto w = GetTextRange(WordStartPosition(p, true), p);
    if (w.length() < 2) return;

    
    w.UpperCase();
    wxString words = "";
    int count = 0;
    for (auto id : m_srcCtx->getIdentifiers(LineFromPosition(p), p - LineFromPosition(p))) {
        wxString ID(id);
        ID.UpperCase();
        if (ID.compare(0, w.length(), w) == 0) {
            if (ID.length() == w.length()) continue;
            words += id + " ";
            count++;
        }
    }
    
    if (count > 0) {
        AutoCompShow((int)w.Length(), words);
    }
}
/*
================
CSyntaxRichEditCtrl::HighlightSyntax

  Update the syntax highlighting for the given character range.
================
*/
void CSyntaxRichEditCtrl::HighlightSyntax(int startCharIndex, int endCharIndex)
{
	int c, t, line, charIndex, textLength, syntaxStart, keyWordLength, keyWordIndex;
	const char *keyWord;
	CHARRANGE visRange;
	CString text;

	// get text length
	GetTextRange(0, GetTextLength(), text);
	textLength = text.GetLength();

	// make sure the indexes are within bounds
	if (startCharIndex < 0) {
		startCharIndex = 0;
	}

	if (endCharIndex < 0) {
		endCharIndex = textLength - 1;
	} else if (endCharIndex >= textLength) {
		endCharIndex = textLength - 1;
	}

	// move the start index to the beginning of the line
	for (; startCharIndex > 0; startCharIndex--) {
		if (idStr::CharIsNewLine(text[startCharIndex-1])) {
			break;
		}
	}

	// move the end index to the end of the line
	for (; endCharIndex < textLength - 1; endCharIndex++) {
		if (idStr::CharIsNewLine(text[endCharIndex+1])) {
			break;
		}
	}

	// get the visible char range
	visRange = GetVisibleRange();

	// never update beyond the visible range
	if (startCharIndex < visRange.cpMin) {
		SetColor(startCharIndex, visRange.cpMin - 1, SRE_COLOR_BLACK, INVALID_BACK_COLOR, false);
		startCharIndex = visRange.cpMin;
	}

	if (visRange.cpMax < endCharIndex) {
		SetColor(visRange.cpMax, endCharIndex, SRE_COLOR_BLACK, INVALID_BACK_COLOR, false);
		endCharIndex = visRange.cpMax;

		if (endCharIndex >= textLength) {
			endCharIndex = textLength - 1;
		}
	}

	// test if the start index is inside a multi-line comment
	if (startCharIndex > 0) {
		// multi-line comments have a slightly different background color
		if (GetBackColor(startCharIndex-1) == MULTILINE_COMMENT_BACK_COLOR) {
			for (; startCharIndex > 0; startCharIndex--) {
				if (text[startCharIndex] == '/' && text[startCharIndex+1] == '*') {
					break;
				}
			}
		}
	}

	// test if the end index is inside a multi-line comment
	if (endCharIndex < textLength - 1) {
		// multi-line comments have a slightly different background color
		if (GetBackColor(endCharIndex+1) == MULTILINE_COMMENT_BACK_COLOR) {
			for (endCharIndex++; endCharIndex < textLength - 1; endCharIndex++) {
				if (text[endCharIndex-1] == '*' && text[endCharIndex] == '/') {
					break;
				}
			}
		}
	}

	line = 0;
	stringColorLine = -1;
	stringColorIndex = 0;

	// set the default color
	SetDefaultFont(startCharIndex, endCharIndex + 1);

	// syntax based colors
	for (charIndex = startCharIndex; charIndex <= endCharIndex; charIndex++) {

		t = charType[text[charIndex]];

		switch (t) {
			case CT_WHITESPACE: {
				if (idStr::CharIsNewLine(text[charIndex])) {
					line++;
				}

				break;
			}
			case CT_COMMENT: {
				c = text[charIndex+1];

				if (c == '/') {
					// single line comment
					syntaxStart = charIndex;

					for (charIndex += 2; charIndex < textLength; charIndex++) {
						if (idStr::CharIsNewLine(text[charIndex])) {
							break;
						}
					}

					SetColor(syntaxStart, charIndex + 1, singleLineCommentColor, DEFAULT_BACK_COLOR, false);
				} else if (c == '*') {
					// multi-line comment
					syntaxStart = charIndex;

					for (charIndex += 2; charIndex < textLength; charIndex++) {
						if (text[charIndex] == '*' && text[charIndex+1] == '/') {
							break;
						}
					}

					charIndex++;
					SetColor(syntaxStart, charIndex + 1, multiLineCommentColor, MULTILINE_COMMENT_BACK_COLOR, false);
				}

				break;
			}
			case CT_STRING: {
				if (line != stringColorLine) {
					stringColorLine = line;
					stringColorIndex = 0;
				}

				syntaxStart = charIndex;

				for (charIndex++; charIndex < textLength; charIndex++) {
					c = text[charIndex];

					if (charType[c] == CT_STRING && text[charIndex-1] != '\\') {
						break;
					}

					if (idStr::CharIsNewLine(c)) {
						line++;
						break;
					}
				}

				SetColor(syntaxStart, charIndex + 1, stringColor[stringColorIndex], DEFAULT_BACK_COLOR, false);
				stringColorIndex ^= 1;
				break;
			}
			case CT_LITERAL: {
				syntaxStart = charIndex;

				for (charIndex++; charIndex < textLength; charIndex++) {
					c = text[charIndex];

					if (charType[c] == CT_LITERAL && text[charIndex-1] != '\\') {
						break;
					}

					if (idStr::CharIsNewLine(c)) {
						line++;
						break;
					}
				}

				SetColor(syntaxStart, charIndex + 1, literalColor, DEFAULT_BACK_COLOR, false);
				break;
			}
			case CT_NUMBER: {
				break;
			}
			case CT_NAME: {
				syntaxStart = charIndex;
				keyWord = ((const char *)text) + charIndex;

				for (charIndex++; charIndex < textLength; charIndex++) {
					c = text[charIndex];
					t = charType[c];

					if (t != CT_NAME && t != CT_NUMBER) {
						// allow path names
						if (!allowPathNames || (c != '/' && c != '\\' && c != '.')) {
							break;
						}
					}
				}

				keyWordLength = charIndex - syntaxStart;
				keyWordIndex = FindKeyWord(keyWord, keyWordLength);

				if (keyWordIndex != -1) {
					SetColor(syntaxStart, syntaxStart + keyWordLength, keyWordColors[keyWordIndex], DEFAULT_BACK_COLOR, false);
				}

				break;
			}
			case CT_PUNCTUATION: {
				break;
			}
		}
	}

	// show braced section
	BracedSectionShow();
}
Beispiel #20
0
/* TextEditor::onKeyDown
 * Called when a key is pressed
 *******************************************************************/
void TextEditor::onKeyDown(wxKeyEvent& e)
{
	// Check if keypress matches any keybinds
	wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers()));

	// Go through matching binds
	bool handled = false;
	for (unsigned a = 0; a < binds.size(); a++)
	{
		string name = binds[a];

		// Open/update calltip
		if (name == "ted_calltip")
		{
			updateCalltip();
			handled = true;
		}

		// Autocomplete
		else if (name == "ted_autocomplete")
		{
			// Get word before cursor
			string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos());

			// If a language is loaded, bring up autocompletion list
			if (language)
			{
				autocomp_list = language->getAutocompletionList(word);
				AutoCompShow(word.size(), autocomp_list);
			}

			handled = true;
		}

		// Find/replace
		else if (name == "ted_findreplace")
		{
			showFindReplaceDialog();
			handled = true;
		}

		// Find next
		else if (name == "ted_findnext")
		{
			wxCommandEvent e;
			onFRDBtnFindNext(e);
			handled = true;
		}

		// Jump to
		else if (name == "ted_jumpto")
		{
			openJumpToDialog();
			handled = true;
		}
	}

#ifdef __WXMSW__
	Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine()));
#endif

	if (!handled)
		e.Skip();
}
BOOL CUrlRichEditCtrl::OnNotifyLink(NMHDR* pNMHDR, LRESULT* pResult)
{
	BOOL bShift = Misc::IsKeyPressed(VK_SHIFT);
	ENLINK* pENL = (ENLINK*)pNMHDR;

	switch (pENL->msg)
	{
	case WM_SETCURSOR:
		if (bShift)
		{
			// because we're overriding the default behaviour we need to
			// handle the cursor being over a selected block
			CHARRANGE crSel;
			GetSel(crSel);

			CPoint ptCursor(GetMessagePos());
			ScreenToClient(&ptCursor);

			LPCTSTR nCursor = IDC_ARROW;

			int nChar = CharFromPoint(ptCursor);
				
			if (nChar < crSel.cpMin || nChar > crSel.cpMax)
				nCursor = IDC_IBEAM;

			SetCursor(AfxGetApp()->LoadStandardCursor(nCursor));

			*pResult = TRUE;
			return TRUE;
		}
		break;

	case WM_LBUTTONDOWN:
		if (!bShift)
		{
			m_nContextUrl = FindUrl(pENL->chrg);

			// might be a hidden link
			if (m_nContextUrl == -1)
			{
				//CString sUrl = GetTextRange(pENL->chrg);
			}
		}
		break;

	case WM_LBUTTONUP:
		// handle tasklinks in OnLButtonUp
		if (m_nContextUrl == -1)
		{
			CString sUrl = GetTextRange(pENL->chrg);
			
			if (sUrl.IsEmpty())
			{
				if (FileMisc::Run(*this, sUrl) > 32)
					return TRUE;
			}
		}
		break;

	case WM_RBUTTONUP:
		m_nContextUrl = FindUrl(pENL->chrg);
		break;
	}

	return FALSE;
}
Beispiel #22
0
wxString wxSTEditorShell::GetPromptText()
{
    int prompt_line = GetPromptLine();
    wxString text = GetTextRange(PositionFromLine(prompt_line), GetLength());
    return text;
}
Beispiel #23
0
/* TextEditor::onKeyDown
 * Called when a key is pressed
 *******************************************************************/
void TextEditor::onKeyDown(wxKeyEvent& e)
{
	// Check if keypress matches any keybinds
	wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers()));

	// Go through matching binds
	bool handled = false;
	for (unsigned a = 0; a < binds.size(); a++)
	{
		string name = binds[a];

		// Open/update calltip
		if (name == "ted_calltip")
		{
			updateCalltip();
			handled = true;
		}

		// Autocomplete
		else if (name == "ted_autocomplete")
		{
			// Get word before cursor
			string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos());

			// If a language is loaded, bring up autocompletion list
			if (language)
			{
				autocomp_list = language->getAutocompletionList(word);
				AutoCompShow(word.size(), autocomp_list);
			}

			handled = true;
		}

		// Find/replace
		else if (name == "ted_findreplace")
		{
			showFindReplaceDialog();
			handled = true;
		}

		// Find next
		else if (name == "ted_findnext")
		{
			wxCommandEvent e;
			onFRDBtnFindNext(e);
			handled = true;
		}

		// Jump to
		else if (name == "ted_jumpto")
		{
			openJumpToDialog();
			handled = true;
		}
	}

#ifdef __WXMSW__
	Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine()));
#endif
	
#ifdef __APPLE__
	if (!handled) {
		const int  keyCode =   e.GetKeyCode();
		const bool shiftDown = e.ShiftDown();

		if (e.ControlDown()) {
			if (WXK_LEFT == keyCode) {
				if (shiftDown) {
					HomeExtend();
				}
				else {
					Home();
				}

				handled = true;
			}
			else if (WXK_RIGHT == keyCode) {
				if (shiftDown) {
					LineEndExtend();
				}
				else {
					LineEnd();
				}

				handled = true;
			}
			else if (WXK_UP == keyCode) {
				if (shiftDown) {
					DocumentStartExtend();
				}
				else {
					DocumentStart();
				}

				handled = true;
			}
			else if (WXK_DOWN == keyCode) {
				if (shiftDown) {
					DocumentEndExtend();
				}
				else {
					DocumentEnd();
				}

				handled = true;
			}
		}
		else if (e.RawControlDown()) {
			if (WXK_LEFT == keyCode) {
				if (shiftDown) {
					WordLeftExtend();
				}
				else {
					WordLeft();
				}

				handled = true;
			}
			else if (WXK_RIGHT == keyCode) {
				if (shiftDown) {
					WordRightExtend();
				}
				else {
					WordRight();
				}

				handled = true;
			}
		}
	}
#endif // __APPLE__

	if (!handled)
		e.Skip();
}
STDMETHODIMP CExRichEditWindowless::GetClipboardData(CHARRANGE FAR *lpchrg, DWORD reco, LPDATAOBJECT FAR *lplpdataobj)
{
	switch(reco)
	{
	case RECO_COPY:
		{
			HRESULT hr = E_NOTIMPL;
			FORMATETC formatEtc;
			STGMEDIUM stgMedium;
			CDataObject *pDataObject = new CDataObject(NULL);

			CString text = GetTextRange(lpchrg->cpMin,lpchrg->cpMax);
			CString embedding(WCH_EMBEDDING);
			text.Replace(embedding,_T("<objtct/>"));
			if(!text.IsEmpty())
			{
				UINT uFormat = m_uOwnOleClipboardFormat;
				if (0 != uFormat)
				{
					HGLOBAL hMemBlock = ::GlobalAlloc(GMEM_MOVEABLE, (text.GetLength() + 1) * sizeof(TCHAR));
					if (NULL != hMemBlock)
					{
						LPTSTR pDest = LPTSTR(::GlobalLock(hMemBlock));
						_tcscpy(pDest, LPCTSTR(text));
						::GlobalUnlock(hMemBlock);

						SecureZeroMemory(&formatEtc, sizeof(FORMATETC));
						formatEtc.cfFormat = uFormat;
						formatEtc.dwAspect = DVASPECT_CONTENT;
						formatEtc.lindex = -1;
						formatEtc.ptd = NULL;
						formatEtc.tymed = TYMED_HGLOBAL;

						SecureZeroMemory(&stgMedium, sizeof(STGMEDIUM));
						stgMedium.tymed = TYMED_HGLOBAL;
						stgMedium.hGlobal = hMemBlock;
						hr = pDataObject->SetData(&formatEtc, &stgMedium, TRUE);
						if (FAILED(hr))
						{
							::GlobalFree(hMemBlock);
							hr &= E_FAIL;
						}
					}
					else
					{
						hr &= E_OUTOFMEMORY;
					}
				}
				else
				{
					hr &= E_FAIL;
				}
			}
			else
			{
				return E_UNEXPECTED;
			}
			if (SUCCEEDED(hr))
			{
				(*lplpdataobj) = pDataObject;
				(*lplpdataobj)->AddRef();
			}
			return hr;
		}
	case RECO_CUT:
	case RECO_DRAG:
	case RECO_DROP:
	case RECO_PASTE:
	default:
		return E_NOTIMPL;
	}
}
Beispiel #25
0
void ChatCtrl::AppendText(const Identity& i, const tstring& sMyNick, const tstring& sTime, tstring sMsg, CHARFORMAT2& cf, bool bUseEmo/* = true*/) {
	SetRedraw(FALSE);

	SCROLLINFO si = { 0 };
	POINT pt = { 0 };

	si.cbSize = sizeof(si);
	si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
	GetScrollInfo(SB_VERT, &si);
	GetScrollPos(&pt);

	LONG lSelBegin = 0, lSelEnd = 0, lTextLimit = 0, lNewTextLen = 0;
	LONG lSelBeginSaved, lSelEndSaved;

	// Unify line endings
	tstring::size_type j = 0; 
	while((j = sMsg.find(_T("\r"), j)) != tstring::npos)
		sMsg.erase(j, 1);

	GetSel(lSelBeginSaved, lSelEndSaved);
	lSelEnd = lSelBegin = GetTextLengthEx(GTL_NUMCHARS);

	bool isMyMessage = i.getUser() == ClientManager::getInstance()->getMe();
	tstring sLine = sTime + sMsg;

	// Remove old chat if size exceeds
	lNewTextLen = sLine.size();
	lTextLimit = GetLimitText();

	if(lSelEnd + lNewTextLen > lTextLimit) {
		LONG lRemoveChars = 0;
		int multiplier = 1;

		if(lNewTextLen >= lTextLimit) {
			lRemoveChars = lSelEnd;
			magnets.clear();
		} else {
			while(lRemoveChars < lNewTextLen)
				lRemoveChars = LineIndex(LineFromChar(multiplier++ * lTextLimit / 10));
		}

		if(magnets.size()) {
			tstring buf;
			buf.resize(lRemoveChars);
			GetTextRange(0, lRemoveChars, &buf[0]);

			CHARFORMAT2 cfSel;
			cfSel.cbSize = sizeof(CHARFORMAT2);

			for(TStringMap::iterator i = magnets.begin(); i != magnets.end();) {
				tstring::size_type j = 0;
				while((j = buf.find(i->first, j)) != tstring::npos) {
					SetSel(j, j + i->first.size());
					GetSelectionCharFormat(cfSel);
					if(cfSel.dwEffects & CFE_LINK) {
						magnets.erase(i++);
						break;
					}
					j += i->first.size();
				} if(j == tstring::npos) {
					++i;
				}
			}
		}

		// Update selection ranges
		lSelEnd = lSelBegin -= lRemoveChars;
		lSelEndSaved -= lRemoveChars;
		lSelBeginSaved -= lRemoveChars;

		// ...and the scroll position
		pt.y -= PosFromChar(lRemoveChars).y;

		SetSel(0, lRemoveChars);
		ReplaceSel(_T(""));
	}


	// Add to the end
	SetSel(lSelBegin, lSelEnd);
	setText(sLine);

	CHARFORMAT2 enc;
	enc.bCharSet = RUSSIAN_CHARSET;
	enc.dwMask = CFM_CHARSET;

	SetSel(0, sLine.length());
	SetSelectionCharFormat(enc);

	// Format TimeStamp
	if(!sTime.empty()) {
		lSelEnd += sTime.size();
		SetSel(lSelBegin, lSelEnd - 1);
		SetSelectionCharFormat(WinUtil::m_TextStyleTimestamp);

		PARAFORMAT2 pf;
		memzero(&pf, sizeof(PARAFORMAT2));
		pf.dwMask = PFM_STARTINDENT; 
		pf.dxStartIndent = 0;
		SetParaFormat(pf);
	}

	// Authors nick
	tstring sAuthor = Text::toT(i.getNick());
	if(!sAuthor.empty()) {
		LONG iLen = (sMsg[0] == _T('*')) ? 1 : 0;
		LONG iAuthorLen = sAuthor.size() + 1;
		sMsg.erase(0, iAuthorLen + iLen);
   		
		lSelBegin = lSelEnd;
		lSelEnd += iAuthorLen + iLen;
		
		if(isMyMessage) {
			SetSel(lSelBegin, lSelBegin + iLen + 1);
			SetSelectionCharFormat(WinUtil::m_ChatTextMyOwn);
			SetSel(lSelBegin + iLen + 1, lSelBegin + iLen + iAuthorLen);
			SetSelectionCharFormat(WinUtil::m_TextStyleMyNick);
		} else {
			bool isFavorite = FavoriteManager::getInstance()->isFavoriteUser(i.getUser());

			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || i.isOp()) {
				SetSel(lSelBegin, lSelBegin + iLen + 1);
				SetSelectionCharFormat(cf);
				SetSel(lSelBegin + iLen + 1, lSelEnd);
				if(isFavorite){
					SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
				} else if(i.isOp()) {
					SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
				} else {
					SetSelectionCharFormat(WinUtil::m_TextStyleBold);
				}
			} else {
				SetSel(lSelBegin, lSelEnd);
				SetSelectionCharFormat(cf);
            }
		}
	} else {
		bool thirdPerson = false;
        switch(sMsg[0]) {
			case _T('*'):
				if(sMsg[1] != _T(' ')) break;
				thirdPerson = true;
            case _T('<'):
				tstring::size_type iAuthorLen = sMsg.find(thirdPerson ? _T(' ') : _T('>'), thirdPerson ? 2 : 1);
				if(iAuthorLen != tstring::npos) {
                    bool isOp = false, isFavorite = false;

                    if(client != NULL) {
						tstring nick(sMsg.c_str() + 1);
						nick.erase(iAuthorLen - 1);
						
						const OnlineUserPtr ou = client->findUser(Text::fromT(nick));
						if(ou != NULL) {
							isFavorite = FavoriteManager::getInstance()->isFavoriteUser(ou->getUser());
							isOp = ou->getIdentity().isOp();
						}
                    }
                    
					lSelBegin = lSelEnd;
					lSelEnd += iAuthorLen;
					sMsg.erase(0, iAuthorLen);

        			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || isOp) {
        				SetSel(lSelBegin, lSelBegin + 1);
        				SetSelectionCharFormat(cf);
						SetSel(lSelBegin + 1, lSelEnd);
						if(isFavorite){
							SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
						} else if(isOp) {
							SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
						} else {
							SetSelectionCharFormat(WinUtil::m_TextStyleBold);
						}
        			} else {
        				SetSel(lSelBegin, lSelEnd);
        				SetSelectionCharFormat(cf);
                    }
				}
        }
	}
				   			
	// Format the message part
	FormatChatLine(sMyNick, sMsg, cf, isMyMessage, sAuthor, lSelEnd, bUseEmo);

	SetSel(lSelBeginSaved, lSelEndSaved);
	if(	isMyMessage || ((si.nPage == 0 || (size_t)si.nPos >= (size_t)si.nMax - si.nPage - 5) &&
		(lSelBeginSaved == lSelEndSaved || !selectedUser.empty() || !selectedIP.empty() || !selectedURL.empty())))
	{
		PostMessage(EM_SCROLL, SB_BOTTOM, 0);
	} else {
		SetScrollPos(&pt);
	}

	// Force window to redraw
	SetRedraw(TRUE);
	InvalidateRect(NULL);
}
Beispiel #26
0
/* TextEditor::onKeyDown
 * Called when a key is pressed
 *******************************************************************/
void TextEditor::onKeyDown(wxKeyEvent& e)
{
	// Check if keypress matches any keybinds
	wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers()));

	// Go through matching binds
	bool handled = false;
	for (unsigned a = 0; a < binds.size(); a++)
	{
		string name = binds[a];

		// Open/update calltip
		if (name == "ted_calltip")
		{
			updateCalltip();
			handled = true;
		}

		// Autocomplete
		else if (name == "ted_autocomplete")
		{
			// Get word before cursor
			string word = GetTextRange(WordStartPosition(GetCurrentPos(), true), GetCurrentPos());

			// If a language is loaded, bring up autocompletion list
			if (language)
			{
				autocomp_list = language->getAutocompletionList(word);
				AutoCompShow(word.size(), autocomp_list);
			}

			handled = true;
		}

		// Find/replace
		else if (name == "ted_findreplace")
		{
			showFindReplacePanel();
			handled = true;
		}

		// Find next
		else if (name == "ted_findnext")
		{
			if (panel_fr && panel_fr->IsShown())
				findNext(panel_fr->getFindText(), panel_fr->getFindFlags());

			handled = true;
		}

		// Find previous
		else if (name == "ted_findprev")
		{
			if (panel_fr && panel_fr->IsShown())
				findPrev(panel_fr->getFindText(), panel_fr->getFindFlags());

			handled = true;
		}

		// Replace next
		else if (name == "ted_replacenext")
		{
			if (panel_fr && panel_fr->IsShown())
				replaceCurrent(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags());

			handled = true;
		}

		// Replace all
		else if (name == "ted_replaceall")
		{
			if (panel_fr && panel_fr->IsShown())
				replaceAll(panel_fr->getFindText(), panel_fr->getReplaceText(), panel_fr->getFindFlags());

			handled = true;
		}

		// Fold all
		else if (name == "ted_fold_foldall")
		{
			foldAll(true);
			handled = true;
		}

		// Unfold all
		else if (name == "ted_fold_unfoldall")
		{
			foldAll(false);
			handled = true;
		}

		// Jump to line
		else if (name == "ted_jumptoline")
		{
			jumpToLine();
			handled = true;
		}
	}

	// Check for esc key
	if (!handled && e.GetKeyCode() == WXK_ESCAPE)
	{
		// Hide call tip if showing
		if (call_tip->IsShown())
			call_tip->Show(false);

		// Hide F+R panel if showing
		else if (panel_fr && panel_fr->IsShown())
			showFindReplacePanel(false);
	}

	// Check for up/down keys while calltip with multiple arg sets is open
	if (call_tip->IsShown() && ct_function && ct_function->nArgSets() > 1 && !ct_dwell)
	{
		if (e.GetKeyCode() == WXK_UP)
		{
			call_tip->prevArgSet();
			handled = true;
		}
		else if (e.GetKeyCode() == WXK_DOWN)
		{
			call_tip->nextArgSet();
			handled = true;
		}
	}

#ifdef __WXMSW__
	Colourise(GetCurrentPos(), GetLineEndPosition(GetCurrentLine()));
#endif
	
#ifdef __APPLE__
	if (!handled) {
		const int  keyCode =   e.GetKeyCode();
		const bool shiftDown = e.ShiftDown();

		if (e.ControlDown()) {
			if (WXK_LEFT == keyCode) {
				if (shiftDown) {
					HomeExtend();
				}
				else {
					Home();
				}

				handled = true;
			}
			else if (WXK_RIGHT == keyCode) {
				if (shiftDown) {
					LineEndExtend();
				}
				else {
					LineEnd();
				}

				handled = true;
			}
			else if (WXK_UP == keyCode) {
				if (shiftDown) {
					DocumentStartExtend();
				}
				else {
					DocumentStart();
				}

				handled = true;
			}
			else if (WXK_DOWN == keyCode) {
				if (shiftDown) {
					DocumentEndExtend();
				}
				else {
					DocumentEnd();
				}

				handled = true;
			}
		}
		else if (e.RawControlDown()) {
			if (WXK_LEFT == keyCode) {
				if (shiftDown) {
					WordLeftExtend();
				}
				else {
					WordLeft();
				}

				handled = true;
			}
			else if (WXK_RIGHT == keyCode) {
				if (shiftDown) {
					WordRightExtend();
				}
				else {
					WordRight();
				}

				handled = true;
			}
		}
	}
#endif // __APPLE__

	if (!handled)
		e.Skip();
}
Beispiel #27
0
bool ChatCtrl::HitNick(const POINT& p, tstring& sNick, int& iBegin, int& iEnd) {
	if(client == NULL) return false;
	
	int iCharPos = CharFromPos(p), line = LineFromChar(iCharPos), len = LineLength(iCharPos) + 1;
	long lSelBegin = 0, lSelEnd = 0;
	if(len < 3)
		return false;

	// Metoda FindWordBreak nestaci, protoze v nicku mohou byt znaky povazovane za konec slova
	int iFindBegin = LineIndex(line), iEnd1 = LineIndex(line) + LineLength(iCharPos);

	for(lSelBegin = iCharPos; lSelBegin >= iFindBegin; lSelBegin--) {
		if(FindWordBreak(WB_ISDELIMITER, lSelBegin))
			break;
	}
	lSelBegin++;
	for(lSelEnd = iCharPos; lSelEnd < iEnd1; lSelEnd++) {
		if(FindWordBreak(WB_ISDELIMITER, lSelEnd))
			break;
	}

	len = lSelEnd - lSelBegin;
	if(len <= 0)
		return false;

	tstring sText;
	sText.resize(len);

	GetTextRange(lSelBegin, lSelEnd, &sText[0]);

	size_t iLeft = 0, iRight = 0, iCRLF = sText.size(), iPos = sText.find(_T('<'));
	if(iPos != tstring::npos) {
		iLeft = iPos + 1;
		iPos = sText.find(_T('>'), iLeft);
		if(iPos == tstring::npos) 
			return false;

		iRight = iPos - 1;
		iCRLF = iRight - iLeft + 1;
	} else {
		iLeft = 0;
	}

	tstring sN = sText.substr(iLeft, iCRLF);
	if(sN.empty())
		return false;

	if(client->findUser(Text::fromT(sN)) != NULL) {
		sNick = sN;
		iBegin = lSelBegin + iLeft;
		iEnd = lSelBegin + iLeft + iCRLF;
		return true;
	}
    
	// Jeste pokus odmazat eventualni koncovou ':' nebo '>' 
	// Nebo pro obecnost posledni znak 
	// A taky prvni znak 
	// A pak prvni i posledni :-)
	if(iCRLF > 1) {
		sN = sText.substr(iLeft, iCRLF - 1);
		if(client->findUser(Text::fromT(sN)) != NULL) {
			sNick = sN;
   			iBegin = lSelBegin + iLeft;
   			iEnd = lSelBegin + iLeft + iCRLF - 1;
			return true;
		}

		sN = sText.substr(iLeft + 1, iCRLF - 1);
		if(client->findUser(Text::fromT(sN)) != NULL) {
        	sNick = sN;
			iBegin = lSelBegin + iLeft + 1;
			iEnd = lSelBegin + iLeft + iCRLF;
			return true;
		}

		sN = sText.substr(iLeft + 1, iCRLF - 2);
		if(client->findUser(Text::fromT(sN)) != NULL) {
			sNick = sN;
   			iBegin = lSelBegin + iLeft + 1;
			iEnd = lSelBegin + iLeft + iCRLF - 1;
			return true;
		}
	}	
	return false;
}
Beispiel #28
0
bool ctlSQLBox::BlockComment(bool uncomment)
{
	wxString lineEnd;
	switch (GetEOLMode())
	{
		case wxSTC_EOL_LF:
			lineEnd = wxT("\n");
			break;
		case wxSTC_EOL_CRLF:
			lineEnd = wxT("\r\n");
			break;
		case wxSTC_EOL_CR:
			lineEnd = wxT("\r");
			break;
	}

	// Save the start position
	const wxString comment = wxT("-- ");
	int start = GetSelectionStart();

	if (!GetSelectedText().IsEmpty())
	{
		wxString selection = GetSelectedText();
		if (!uncomment)
		{
			selection.Replace(lineEnd, lineEnd + comment);
			selection.Prepend(comment);
			if (selection.EndsWith(comment))
				selection = selection.Left(selection.Length() - comment.Length());
		}
		else
		{
			selection.Replace(lineEnd + comment, lineEnd);
			if (selection.StartsWith(comment))
				selection = selection.Right(selection.Length() - comment.Length());
		}
		ReplaceSelection(selection);
		SetSelection(start, start + selection.Length());
	}
	else
	{
		// No text selection - (un)comment the current line
		int column = GetColumn(start);
		int curLineNum = GetCurrentLine();
		int pos = PositionFromLine(curLineNum);

		if (!uncomment)
		{
			InsertText(pos, comment);
		}
		else
		{
			wxString t = GetTextRange(pos, pos + comment.Length());
			if (t == comment)
			{
				// The line starts with a comment, so we remove it
				SetTargetStart(pos);
				SetTargetEnd(pos + comment.Length());
				ReplaceTarget(wxT(""));
			}
			else
			{
				// The line doesn't start with a comment, do nothing
				return false;
			}
		}

		if (GetLineCount() > curLineNum)
		{
			wxString nextLine = GetLine(curLineNum + 1);
			if (nextLine.EndsWith(lineEnd))
				nextLine = nextLine.Left(nextLine.Length() - lineEnd.Length());

			int nextColumn = (nextLine.Length() < (unsigned int)column ? nextLine.Length() : column);
			GotoPos(PositionFromLine(curLineNum + 1) + nextColumn);
		}
	}

	return true;
}
Beispiel #29
0
BOOL UIIMEdit::GetContent(OUT MixedMsg& mixMsg)
{
	mixMsg.m_strTextData = GetTextRange(0, GetTextLength());
	if (mixMsg.m_strTextData.IsEmpty())
		return FALSE;
    mixMsg.ReplaceReturnKey();

	IRichEditOle *pRichEditOle = m_pRichEditOle;
	if (NULL == pRichEditOle)
	{
		return FALSE;
	}
	UInt32 nImageCount = pRichEditOle->GetObjectCount();
	if (nImageCount == 0)//纯文字
	{
		CString strContent = mixMsg.m_strTextData;
		strContent.Trim();
		if (strContent.IsEmpty())
		{
			LOG__(DEBG, _T("After trimed,is empty msg"));//日志干扰
			return FALSE;
		}
	}
	else//图文混排
	{
		CString strEmotionFilesDir = module::getMiscModule()->getEmotionFilesDir();
		int nPosAdd = 0;
		for (UInt32 i = 0; i < nImageCount; i++)
		{
			ST_picData picData;
			if (GetPicPosAndPathbyOrder(i, picData.nPos, picData.strLocalPicPath))
			{
				TCHAR fullPath[MAX_PATH] = { 0 };
				LPTSTR* pStart = nullptr;
				if (!GetFullPathName(picData.strLocalPicPath, MAX_PATH, fullPath, pStart))
				{
					continue;
				}
				CString strFullPath = fullPath;
				int nPos = strFullPath.Find(strEmotionFilesDir);
				if (-1 != nPos)
				{
					//是表情,不用上传图片
					int nLen = picData.strLocalPicPath.GetLength();
					CString fileName = strFullPath.Mid(strEmotionFilesDir.GetLength(), nLen - strEmotionFilesDir.GetLength() + 1);
					CString fileID;
					if (!module::getEmotionModule()->getEmotionIDByName(fileName, fileID))
					{
						return FALSE;
					}
					mixMsg.m_strTextData.Insert(nPosAdd + picData.nPos, fileID);
					mixMsg.m_strTextData.Delete(nPosAdd + picData.nPos + fileID.GetLength(), 1);
					//nPosAdd += picData.nPos + fileID.GetLength();
					nPosAdd += fileID.GetLength() - 1;
				}
				else
				{
					picData.nPos += nPosAdd;
					mixMsg.m_picDataVec.push_back(picData);
				}
			}
		}
	}
	SetText(_T(""));
	return TRUE;
}