示例#1
0
/**
 * Return the key at position lPos
 */
CString CScintillaBibWnd::GetKeyAt(long lPos)
{
	if (GetStyleAt(lPos) != SCE_BIB_KEY)
		return _T("");

	DWORD start = lPos;
	DWORD end = lPos;
	while (start > 0 && GetStyleAt(start) == SCE_BIB_KEY)
		start--;
	start++;
	while (GetStyleAt(end) == SCE_BIB_KEY)
		end++;
	TextRange tr;
	tr.chrg.cpMin = start;
	tr.chrg.cpMax = end;
	TCHAR *buff = new TCHAR[(end - start) + 1];
	tr.lpstrText = buff;

	SendMessage(SCI_GETTEXTRANGE, 0, (long)&tr);
	CString key(buff);

	delete [] buff;

	return key;
}
示例#2
0
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();
}
示例#3
0
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 cbStyledTextCtrl::DoBraceCompletion(const wxChar& ch)
{
    const int pos   = GetCurrentPos();
    const int style = GetStyleAt(pos);
    if (IsComment(style) || IsComment(GetStyleAt(pos - 2)))
        return; // do nothing
    if (ch == wxT('\'') || ch == wxT('"'))
    {
        if (GetCharAt(pos) == ch)
        {
            DeleteBack();
            CharRight();
        }
        else if (!IsString(GetStyleAt(pos - 2)) && !IsCharacter(GetStyleAt(pos - 2)))
            InsertText(pos, ch);
        return; // done
    }

    if (IsString(style) || IsCharacter(style))
        return; // do nothing

    const wxString opBraces(wxT("([{")); const int opBraceIdx = opBraces.Find(ch);
    const wxString clBraces(wxT(")]}")); const int clBraceIdx = clBraces.Find(ch);
    if ( (opBraceIdx != wxNOT_FOUND) || (clBraceIdx != wxNOT_FOUND) )
    {
        if ( GetCharAt(pos) == ch )
        {
            DeleteBack();
            CharRight();
        }
        else if (opBraceIdx != wxNOT_FOUND)
        {
            int nextPos = pos;
            while ( wxIsspace(GetCharAt(nextPos)) && (nextPos < GetLength()) )
                ++nextPos;

            if (   ((wxChar)GetCharAt(nextPos) != clBraces[opBraceIdx])
                || (BraceMatch(nextPos)        != wxNOT_FOUND) )
            {
                InsertText(pos, clBraces[opBraceIdx]);
            }
        }
    }
}
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;
}
示例#6
0
/*---------------------------------------------------------------------------*/
bool wxSQLEditorBase::EndLineIsComment(int lineindex)
{
   int pos, style;

   pos = PositionFromLine(lineindex) + GetLine(lineindex).Length() - 1;
   style = GetStyleAt(pos);
   if ((style == wxSTC_SQL_COMMENT)||(style == wxSTC_SQL_COMMENTDOC)||
       (style == wxSTC_SQL_SQLPLUS_COMMENT)||(style == wxSTC_SQL_COMMENTDOCKEYWORD)||
       (style == wxSTC_SQL_COMMENTDOCKEYWORDERROR)||(style == wxSTC_SQL_COMMENTLINE)||
       (style == wxSTC_SQL_COMMENTLINEDOC))
      return true;
   return false;
}
NS_IMETHODIMP
nsAutoCompleteController::GetCellProperties(PRInt32 row, nsITreeColumn* col, nsISupportsArray* properties)
{
  if (row >= 0) {
    nsAutoString className;
    GetStyleAt(row, className);
    if (!className.IsEmpty()) {
      nsCOMPtr<nsIAtom> atom(do_GetAtom(className));
      properties->AppendElement(atom);
    }
  }

  return NS_OK;
}
void cbStyledTextCtrl::EmulateDwellStart()
{
    EditorBase *editor = static_cast<EditorBase*>(m_pParent);

    CodeBlocksEvent event(cbEVT_EDITOR_TOOLTIP);
    wxPoint pt(ScreenToClient(wxGetMousePosition()));
    event.SetX(pt.x);
    event.SetY(pt.y);
    int pos = PositionFromPoint(pt);
    int style = GetStyleAt(pos);
    event.SetInt(style);
    event.SetEditor(editor);
    event.SetExtraLong(0); // allow plugins to recommend each other not to cancel a tooltip
    Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
示例#9
0
/**
 * Returns the position of a bib item.
 */
int CScintillaBibWnd::FindItem(CString key)
{
	// Finds nothing when short before the text was set
	// Well, the style is not yet set. Now it calls CScintillaWnd::Colourise
	// in CSourceView if needed.
	if (key.IsEmpty())
		return -1;
	TextToFind tf;
	int lPos = -1;
	tf.lpstrText = key.GetBuffer(key.GetLength()+1);
	tf.chrg.cpMax = SendMessage(SCI_GETLENGTH, 0, 0);
	do {
		tf.chrg.cpMin = lPos+1;
		lPos = SendMessage(SCI_FINDTEXT, SCFIND_WHOLEWORD | SCFIND_MATCHCASE, (long)&tf);
	} while (lPos > -1 && GetStyleAt(lPos) != SCE_BIB_KEY);
	return lPos;
}
void PythonCodeCtrl::OnCharAdded(wxScintillaEvent& ke)
{
    //User has pressed enter
    //if the cursor is at the end of a completed statement, submit the statement to the interpreter
    //otherwise, do auto-indentation
    if (ke.GetKey() == _T('\n'))
    {
        //int pos = GetCurrentPos();
        int line = LineFromPosition(GetCurrentPos());

        if(line>0)
        {
            wxString prevlinetext = GetLine(line-1).Trim();
            int indentation = GetLineIndentation(line-1);

            if((indentation==0) //submit a return pressed on an unindented line
                || (indentation>0 && prevlinetext==wxEmptyString)) // or an indented block where the previous line was empty
            {
                long rs,re;
                GetSelection(&rs,&re);
                //if(rs==re && GetLastPosition()==rs)
                if(rs==re && GetLength()==rs) // only submit if the cursor is at the end of the control (and there is no selection)
                {
                    m_pyctrl->DispatchCode(GetValue());
                    ke.Skip();
                }
            }

            // Otherwise indent the code if necessary
            if (GetLine(line-1).Trim().EndsWith(_T(":")))
            {
                if(GetStyleAt(GetLineEndPosition(line-1)-1) == wxSCI_P_OPERATOR)
                    indentation+=GetIndent();
            }
            if (indentation>0)
            {
                SetLineIndentation(line,indentation);
                SetCurrentPos(PositionFromLine(line)+indentation);
                SetAnchor(PositionFromLine(line)+indentation);
            }
        }
    }
    ke.Skip();
}
void cbStyledTextCtrl::HighlightRightBrace()
{
    if (m_bracePosition == wxSCI_INVALID_POSITION)
        return;

    int pos = GetCurrentPos();
    if (pos == wxSCI_INVALID_POSITION)
        return;

    const static wxColour caretForeground = GetCaretForeground();
    const static int caretWidth = GetCaretWidth();
    const int curLine = GetCurrentLine();
    const int len = GetLength();

    if (m_tabSmartJump && (curLine == LineFromPosition(m_bracePosition)))
    {
        SetIndicatorCurrent(s_indicHighlight);
        const int indPos = GetLineIndentPosition(curLine);
        IndicatorClearRange(indPos, GetLineEndPosition(curLine)-indPos);
        do
        {
            if (pos >= len)
                break;

            wxString cur((wxChar)GetCharAt(pos));
            if (cur == _T("\n"))
                break;

            int style = GetStyleAt(pos);
            if (IsComment(style))
                continue;

            if (IsString(style) || IsCharacter(style))
            {
                const int nextOne = (pos == len) ? GetStyleAt(pos) : GetStyleAt(pos + 1);
                if (IsCharacter(nextOne) || IsString(nextOne))
                    continue;
            }

            if (s_rightBrace.Contains(cur))
            {
                SetCaretForeground(wxColour(255, 0, 0));
                SetCaretWidth(caretWidth + 1);

                IndicatorSetForeground(s_indicHighlight, wxColour(80, 236, 120));
                IndicatorSetStyle(s_indicHighlight, wxSCI_INDIC_HIGHLIGHT);
#ifndef wxHAVE_RAW_BITMAP
                IndicatorSetUnder(s_indicHighlight, true);
#endif
                SetIndicatorCurrent(s_indicHighlight);
                IndicatorFillRange(pos, 1);
                m_bracePosition = pos + 1;
                return;
            }
        }
        while (++pos);
    }

    m_bracePosition = wxSCI_INVALID_POSITION;
    m_lastPosition = wxSCI_INVALID_POSITION;
    m_tabSmartJump = false;
    SetIndicatorCurrent(s_indicHighlight);
    IndicatorClearRange(0, len);

    SetCaretForeground(caretForeground);
    SetCaretWidth(caretWidth);
}