Пример #1
0
void CChatSession::AddText(const wxString& text, const wxTextAttr& style, bool newline)
{
	// Split multi-line messages into individual lines
	wxStringTokenizer tokens( text, wxT("\n") );

	while ( tokens.HasMoreTokens() ) {
		// Check if we should add a time-stamp
		if ( GetNumberOfLines() > 1 ) {
			// Check if the last line ended with a newline
			wxString line = GetLineText( GetNumberOfLines() - 1 );
			if ( line.IsEmpty() ) {
				SetDefaultStyle( COLOR_BLACK );

				AppendText( wxT(" [") + wxDateTime::Now().FormatISOTime() + wxT("] ") );
			}
		}

		SetDefaultStyle(style);

		AppendText( tokens.GetNextToken() );

		// Only add newlines after the last line if it is desired
		if ( tokens.HasMoreTokens() || newline ) {
			AppendText( wxT("\n") );
		}
	}
}
Пример #2
0
//Resize logics
void ExpandoTextCtrl::AdjustCtrl(long newHeight) {

    //If the required height is more than the maxHieght, decrease it to that
    if(maxHeight != -1 && newHeight > maxHeight) {
        newHeight = maxHeight;
    }

    //If the required height is less than the minHieght, increase it to that
    if(minHeight != -1 && newHeight < minHeight) {
        newHeight = minHeight;
    }

    decHeight = newHeight;

    SetMinSize(wxSize(GetMinSize().GetWidth(), newHeight));

    //If requested height between min and max height, resize the Expando
    if(newHeight != GetSize().GetHeight()) {

        bool hasSizer = GetContainingSizer() != NULL;

        if(!hasSizer) {
            SetSize(GetSize().GetWidth(), newHeight);
        }

        //Throw a LayoutNeeded Event
        wxExpandEvent evt(wxEVT_ETC_LAYOUT_NEEDED, GetId());
        evt.SetEventObject(this);
        evt.height = newHeight;
        evt.numLines = GetNumberOfLines();
        GetEventHandler()->ProcessEvent(evt);
    }
}
Пример #3
0
unsigned int Operator::SnapToMeshLine(int ny, double coord, bool &inside, bool dualMesh) const
{
	inside = false;
	if ((ny<0) || (ny>2))
		return 0;
	if (coord<GetDiscLine(ny,0))
		return 0;
	unsigned int numLines = GetNumberOfLines(ny);
	if (coord>GetDiscLine(ny,numLines-1))
		return numLines-1;
	inside=true;
	if (dualMesh==false)
	{
		for (unsigned int n=0;n<numLines;++n)
		{
			if (coord<=GetDiscLine(ny,n,true))
				return n;
		}
	}
	else
	{
		for (unsigned int n=1;n<numLines;++n)
		{
			if (coord<=GetDiscLine(ny,n,false))
				return n-1;
		}
	}
	//should not happen
	return 0;
}
Пример #4
0
/* TextEditor::loadEntry
 * Reads the contents of [entry] into the text area, returns false
 * if the given entry is invalid
 *******************************************************************/
bool TextEditor::loadEntry(ArchiveEntry* entry)
{
	// Clear current text
	ClearAll();

	// Check that the entry exists
	if (!entry)
	{
		Global::error = "Invalid archive entry given";
		return false;
	}

	// Check that the entry has any data, if not do nothing
	if (entry->getSize() == 0 || !entry->getData())
		return true;

	// Get character entry data
	//string text = wxString::From8BitData((const char*)entry->getData(), entry->getSize());
	string text = wxString::FromUTF8((const char*)entry->getData(), entry->getSize());
	// If opening as UTF8 failed for some reason, try again as 8-bit data
	if (text.length() == 0)
		text = wxString::From8BitData((const char*)entry->getData(), entry->getSize());

	// Load text into editor
	SetText(text);

	// Update line numbers margin width
	string numlines = S_FMT("0%d", GetNumberOfLines());
	SetMarginWidth(0, TextWidth(wxSTC_STYLE_LINENUMBER, numlines));

	return true;
}
Пример #5
0
/*------------------------------------------------------------------------
Procedure:     AppendToEditBuffer ID:1
Author:		   Chris Watford [email protected]
Purpose:       Add a line to the edit buffer
Input:		   Handle of the edit control
Output:
Errors:
------------------------------------------------------------------------*/
void AppendToEditBuffer(HWND hEdit)
{
	char *p = NULL, linebuffer[2048];
	int n = 0;
	int curline = GetCurLineIndex(hEdit);
	int linescount = GetNumberOfLines(hEdit);

	// they are passing the size of the buffer as
	// the first 'short' in the array...
	*(unsigned short *)linebuffer = sizeof(linebuffer)-1;

	if (curline > (linescount-1))
	{
		n = SendMessage(hEdit, EM_GETLINE, curline, (LPARAM)linebuffer);
	} else {
		n = SendMessage(hEdit, EM_GETLINE, --curline, (LPARAM)linebuffer);
	}

	// correct for the prompt line
	if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ')
	{
		n -= 2;
		memmove(linebuffer, linebuffer+2, n);
	}

	linebuffer[n] = '\0';

	// linebuffer now has the line to add to our edit buffer
	editbuffer_updateoraddline(CurrentEditBuffer, (curline - LastPromptPosition.line), linebuffer);
}
Пример #6
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();
}
Пример #7
0
wxTextPos wxTextCtrl::GetLastPosition() const
{
    int numLines = GetNumberOfLines();
    long posStartLastLine = XYToPosition(0, numLines - 1);

    long lenLastLine = GetLengthOfLineContainingPos(posStartLastLine);

    return posStartLastLine + lenLastLine;
}
Пример #8
0
void Trajectory::LoadMatrixFromCSV( const std::string& filename, Eigen::MatrixXd &matrix) {

    cout << "Loading " << filename << endl;

    int number_of_lines = GetNumberOfLines(filename);
    int row_num = 0;

    int i =  0;
    //                                   file, delimiter, first_line_is_header?
    CsvParser *csvparser = CsvParser_new(filename.c_str(), ",", true);
    CsvRow *header;
    CsvRow *row;

    header = CsvParser_getHeader(csvparser);
    if (header == NULL) {
        printf("%s\n", CsvParser_getErrorMessage(csvparser));
        return;
    }

    char **headerFields = CsvParser_getFields(header);
    for (i = 0 ; i < CsvParser_getNumFields(header) ; i++) {
        //printf("TITLE: %s\n", headerFields[i]);
    }

    matrix.resize(number_of_lines - 1, i); // minus 1 for header, i = number of columns

    while ((row = CsvParser_getRow(csvparser)) ) {
        //printf("NEW LINE:\n");
        char **rowFields = CsvParser_getFields(row);
        for (i = 0 ; i < CsvParser_getNumFields(row) ; i++) {

            matrix(row_num, i) = atof(rowFields[i]);

            //printf("FIELD: %20.20f\n", atof(rowFields[i]));
        }
        CsvParser_destroy_row(row);

        if (row_num == 1) {
            dt_ = matrix(1, 0) - matrix(0, 0);
        } else if (row_num > 1) {
            if (matrix(row_num, 0) - matrix(row_num - 1, 0) - dt_ > 5*std::numeric_limits<double>::epsilon()) {
                cerr << "Error: non-constant dt. Expected dt = " << dt_ << " but got matrix[" << row_num << "][0] - matrix[" << row_num - 1 << "][0] = " << matrix(row_num, 0) - matrix(row_num - 1, 0) << " (residual = " << (matrix(row_num, 0) - matrix(row_num - 1, 0) - dt_) << endl;

                cout << matrix << endl;
                exit(1);
            }
        }

        row_num ++;
    }
    CsvParser_destroy(csvparser);


}
Пример #9
0
void wxTextCtrl::ShowPosition( long pos )
{
    if (m_windowStyle & wxTE_MULTILINE)
    {
        GtkAdjustment *vp = GTK_TEXT(m_text)->vadj;
        float totalLines =  (float) GetNumberOfLines();
        long posX;
        long posY;
        PositionToXY(pos, &posX, &posY);
        float posLine = (float) posY;
        float p = (posLine/totalLines)*(vp->upper - vp->lower) + vp->lower;
        gtk_adjustment_set_value(GTK_TEXT(m_text)->vadj, p);
    }
}
Пример #10
0
void moLogTextCtrl::LogError( moText p_message ) {

    wxString  w = moText2Wx( p_message );

    if (GetNumberOfLines()>10000) {
        Clear();
    }

    SetDefaultStyle( wxTextAttr( wxColour(255,0,0) ) );
    AppendText(w + wxT("\n"));

    ShowPosition( GetLastPosition() );

}
Пример #11
0
void moLogTextCtrl::Log( moText p_message ) {

    wxString  w = moText2Wx( p_message );

    ///cada 10000 lineas publicadas, limpia el buffer completo
    if (GetNumberOfLines()>10000) {
        Clear();
    }

    SetDefaultStyle( wxTextAttr( wxColour( 50, 255, 50 )) );
    AppendText(w + wxT("\n"));

    ShowPosition( GetLastPosition() );

}
Пример #12
0
//---------------------------------------------------------
void CINFO_Messages::_Add_Text(wxString Text)
{
	int		i, n;

	if( m_MaxLength <= (int)(GetLastPosition() + Text.Length()) )
	{
		for(i=0, n=0; i<GetNumberOfLines() && n<(int)Text.Length(); i++)
		{
			n	+= 1 + GetLineLength(i);
		}

		Remove(0, n + 1);
	}

	AppendText(Text);
}
Пример #13
0
/* TextEditor::foldAll
 * Folds or unfolds all code folding levels, depending on [fold]
 *******************************************************************/
void TextEditor::foldAll(bool fold)
{
#if (wxMAJOR_VERSION >= 3 && wxMINOR_VERSION >= 1)
	// FoldAll is only available in wxWidgets 3.1+
	FoldAll(fold ? wxSTC_FOLDACTION_CONTRACT : wxSTC_FOLDACTION_EXPAND);
#else
	for (int a = 0; a < GetNumberOfLines(); a++)
	{
		int level = GetFoldLevel(a);
		if ((level & wxSTC_FOLDLEVELHEADERFLAG) > 0 &&
			GetFoldExpanded(a) == fold)
			ToggleFold(a);
	}
#endif

	updateFolding();
}
Пример #14
0
wxSize wxTextCtrl::DoGetBestSize() const
{
    int                             nCx;
    int                             nCy;
    wxFont                          vFont = (wxFont)GetFont();

    wxGetCharSize(GetHWND(), &nCx, &nCy, &vFont);

    int                             wText = DEFAULT_ITEM_WIDTH;
    int                             hText = (int)(EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy) * .8);

    if (m_windowStyle & wxTE_MULTILINE)
    {
        hText *= wxMax(GetNumberOfLines(), 5);
    }
    //else: for single line control everything is ok
    return wxSize(wText, hText);
} // end of wxTextCtrl::DoGetBestSize
Пример #15
0
/*------------------------------------------------------------------------
Procedure:     GetLastLine ID:1
Purpose:       Gets the data in the line containing the cursor to
			   the interpreter.
Input:         The edit control window handle
Output:        None explicit
Errors:        None
------------------------------------------------------------------------*/
char* GetLastLine(HWND hEdit)
{
	int curline = GetCurLineIndex(hEdit);
	char *linebuffer = (char*)SafeMalloc(2048*sizeof(char));
	int n;
	int linescount = GetNumberOfLines(hEdit);

	*(unsigned short *)linebuffer = 2047;
	n = SendMessage(hEdit,EM_GETLINE,curline,(LPARAM)linebuffer);

	if (n >= 2 && linebuffer[0] == '#' && linebuffer[1] == ' ') {
		n -= 2;
		memmove(linebuffer, linebuffer+2, n);
	}

	linebuffer[n] = '\0';

	return linebuffer;
}
Пример #16
0
wxSize wxTextCtrl::DoGetBestSize() const
{
    int cx, cy;
    wxGetCharSize(GetBuddyHwnd(), &cx, &cy, GetFont());

    int wText = DEFAULT_ITEM_WIDTH;

    int hText = cy;
    if ( m_windowStyle & wxTE_MULTILINE )
    {
        hText *= wxMax(GetNumberOfLines(), 5);
    }
    //else: for single line control everything is ok

    // we have to add the adjustments for the control height only once, not
    // once per line, so do it after multiplication above
    hText += EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) - cy;

    return wxSize(wText, hText);
}
Пример #17
0
/* TextEditor::onStyleNeeded
 * Called when text styling is needed
 *******************************************************************/
void TextEditor::onStyleNeeded(wxStyledTextEvent& e)
{
	// Get range of lines to be updated
	int line_start = LineFromPosition(GetEndStyled());
	int line_end = LineFromPosition(e.GetPosition());

	// Lex until done (end of lines, end of file or end of block comment)
	int l = line_start;
	bool force_next = false;
	while (l <= GetNumberOfLines() && (l <= line_end || force_next))
	{
		int end = GetLineEndPosition(l) - 1;
		int start = end - GetLineLength(l) + 1;

		if (start > end)
			end = start;

		force_next = lexer.doStyling(this, start, end);
		l++;
	}

	if (txed_fold_enable)
		lexer.updateFolding(this, line_start);
}
Пример #18
0
/* TextEditor::jumpToLine
 * Prompts the user for a line number and moves the cursor to the end
 * of the entered line
 *******************************************************************/
void TextEditor::jumpToLine()
{
	int numlines = GetNumberOfLines();

	// Prompt for line number
	long line = wxGetNumberFromUser(
		"Enter a line number to jump to",
		S_FMT("Line number (1-%d):", numlines),
		"Jump To Line",
		GetCurrentLine() + 1,
		1,
		numlines,
		this);

	if (line >= 1)
	{
		// Move to line
		int pos = GetLineEndPosition(line - 1);
		SetCurrentPos(pos);
		SetSelection(pos, pos);
		EnsureCaretVisible();
		SetFocus();
	}
}
Пример #19
0
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);
	}
}
Пример #20
0
int Operator::SnapBox2Mesh(const double* start, const double* stop, unsigned int* uiStart, unsigned int* uiStop, bool dualMesh, int SnapMethod, bool* bStartIn, bool* bStopIn) const
{
	double l_start[3], l_stop[3];
	for (int n=0;n<3;++n)
	{
		l_start[n] = fmin(start[n],stop[n]);
		l_stop[n] = fmax(start[n], stop[n]);
		double min = GetDiscLine(n,0);
		double max = GetDiscLine(n,GetNumberOfLines(n)-1);
		if ( ((l_start[n]<min) && (l_stop[n]<min)) || ((l_start[n]>max) && (l_stop[n]>max)) )
		{
			return -2;
		}
	}

	SnapToMesh(l_start, uiStart, dualMesh, bStartIn);
	SnapToMesh(l_stop, uiStop, dualMesh, bStopIn);
	int iDim = 0;

	if (SnapMethod==0)
	{
		for (int n=0;n<3;++n)
			if (uiStop[n]>uiStart[n])
				++iDim;
		return iDim;
	}
	else if (SnapMethod==1)
	{
		for (int n=0;n<3;++n)
		{
			if (uiStop[n]>uiStart[n])
			{
				if ((GetDiscLine( n, uiStart[n], dualMesh ) > l_start[n]) && (uiStart[n]>0))
					--uiStart[n];
				if ((GetDiscLine( n, uiStop[n], dualMesh ) < l_stop[n]) && (uiStop[n]<GetNumberOfLines(n)-1))
					++uiStop[n];
			}
			if (uiStop[n]>uiStart[n])
				++iDim;
		}
		return iDim;
	}
	else if (SnapMethod==2)
	{
		for (int n=0;n<3;++n)
		{
			if (uiStop[n]>uiStart[n])
			{
				if ((GetDiscLine( n, uiStart[n], dualMesh ) < l_start[n]) && (uiStart[n]<GetNumberOfLines(n)-1))
					++uiStart[n];
				if ((GetDiscLine( n, uiStop[n], dualMesh ) > l_stop[n]) && (uiStop[n]>0))
					--uiStop[n];
			}
			if (uiStop[n]>uiStart[n])
				++iDim;
		}
		return iDim;
	}
	else
		cerr << "Operator::SnapBox2Mesh: Unknown snapping method!" << endl;
	return -1;
}
Пример #21
0
void CliCtrl::AppendAutoCompleteCommad(const wxString& data)
{
	wxString curLine = GetLineText(GetNumberOfLines() - 1);
	AppendText("\n" + data);
	AppendText("\n" + curLine);
}
Пример #22
0
/*------------------------------------------------------------------------
Procedure:     SubClassEdit ID:1
Purpose:       Handles messages to the editbox
Input:         
Output:        
Errors:
--------------------------------------------------------------------------
Edit History:
	14 Sept 2003 - Chris Watford [email protected]
		- Setup handler for up and down arrows
	15 Sept 2003 - Chris Watford [email protected]
		- Setup framework for history on up arrow
		- Saves lines you move off of in the edit buffer
	16 Sept 2003 - Chris Watford [email protected]
		- Proper handling of newline message finished
		- Fixed ENTER on middle of interior line, moves cursor to the end
		  and sends the line
		- Setup the copying and destroying of the old buffer
		- Included buffer rewrite
	17 Sept 2003 - Chris Watford [email protected]
		- Added C-p/C-n support
		- Changed UpArrow to C-UpArrow so as to not confuse users
	18 Sept 2003 - Chris Watford [email protected]
		- Added Left and Right arrow line saving
		- Added backspace and delete line saving and removing
		- Fixed history scrolling
	21 Sept 2003 - Chris Watford [email protected]
		- Fixed pasting errors associated with lines being out of bounds
		  for the buffer
		- Added error handling, possibly able to handle it diff down the
		  line
		- Removed C-Up/C-Dn for history scrolling, buggy at best on my
		  machine
------------------------------------------------------------------------*/
static LRESULT CALLBACK SubClassEdit(HWND hwnd, UINT msg, WPARAM mp1, LPARAM mp2)
{
	LRESULT r;
	int postit=0,nl;

	if (msg == WM_CHAR && mp1 == '\r') {
		if (!busy) {
			r =  GetCurLineIndex(hwnd);
			nl = GetNumberOfLines(hwnd);

			// if we're not the last line
			if (r != nl-1)
			{
				// update or add us, we might not have any lines in the edit buffer
				editbuffer_updateoraddline(CurrentEditBuffer, r-LastPromptPosition.line, GetLastLine(hwnd));

				// scroll to the end, add CrLf then post the newline message
				GotoEOF();
				AddStringToControl("\r\n");
				PostMessage(GetParent(hwnd),WM_NEWLINE,0,0);
				return 0;
			}

			CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1);
			CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1);

			postit = 1;
		}

	}
	else if (msg == WM_CHAR && mp1 == (char)0x08) {
		int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2;
		int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0);
		int nextline = 0;
		int curpoint = 0;

		SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); 
		nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0);

		if(curpoint <= lineindex)
		{
			return 0;
		} else if(nextline != curline) {
			// delete the line we're on

			// grab the index
			curline -= LastPromptPosition.line;

			// kill it
			editbuffer_removeline(CurrentEditBuffer, curline);
		}
	}
	else if (msg == WM_KEYDOWN && mp1 == VK_F1) {
		DoHelp(hwnd);
	}
	else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && mp1 == VK_UP) {
		int curline = GetCurLineIndex(hwnd);

		/*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000))
		{	// go forward once in history
			NextHistoryEntry();
			return 0;
		} else */
		if((curline > LastPromptPosition.line) && (curline <= (LastPromptPosition.line + CurrentEditBuffer->LineCount)))
		{
			// update current line
			if (msg == WM_KEYDOWN)
			{
				int lineidx = (curline - LastPromptPosition.line);

				CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1);
				CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1);
				
				// we may have to add this line, otherwise update it
				editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd));
			}
		} else {
			return 0;
		}
	}
	else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_LEFT)) {
		int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2;
		int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0);
		int nextline = 0;
		int curpoint = 0;

		SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); 
		nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint - 1),0);

		if(curpoint <= lineindex)
		{	// no left arrow to the left of the prompt
			return 0;
		} else if(nextline != curline) {
			// update current line
			if (msg == WM_KEYDOWN)
			{
				int lineidx = (curline - LastPromptPosition.line);

				CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1);
				CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1);
				
				// we may have to add this line, otherwise update it
				editbuffer_updateoraddline(CurrentEditBuffer, lineidx, GetLastLine(hwnd));

				CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_HOME,1);
				CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_HOME,1);
			}
		}
	}
	else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DOWN)) {
		int curline = GetCurLineIndex(hwnd);
		
		/*if((msg == WM_KEYDOWN) && (GetKeyState(VK_CONTROL) && 0x8000))
		{	// go back once in history
			PrevHistoryEntry();
			return 0;
		} else*/
		if((curline >= LastPromptPosition.line) && (curline < (LastPromptPosition.line + CurrentEditBuffer->LineCount)))
		{
			// We don't post the newline, but instead update the current line
			if (msg == WM_KEYDOWN)
			{
				int lineidx = (curline - LastPromptPosition.line);

				CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1);
				CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1);
				
				editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd));
			}
		} else {
			return 0;
		}
	}
	else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_RIGHT)) {
		int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 1;
		int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0);
		int nextline = 0;
		int curpoint = 0;

		SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); 
		nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0);

		if(curpoint <= lineindex)
		{	// no movement behind the prompt
			return 0;
		} else if((nextline != curline) && (msg = WM_KEYDOWN)) {
			int lineidx = (curline - LastPromptPosition.line);

			CallWindowProc(lpEProc,hwnd,WM_KEYDOWN,VK_END,1);
			CallWindowProc(lpEProc,hwnd,WM_KEYUP,VK_END,1);
			
			editbuffer_updateline(CurrentEditBuffer, lineidx, GetLastLine(hwnd));
		}
	}
	else if ((msg == WM_KEYDOWN) && (mp1 == VK_PRIOR) && (GetKeyState(VK_CONTROL) && 0x8000)) {
		// C-p
		NextHistoryEntry();
		return 0;
	}
	else if ((msg == WM_KEYDOWN) && (mp1 == VK_NEXT) && (GetKeyState(VK_CONTROL) && 0x8000)) {
		// C-n
		PrevHistoryEntry();
		return 0;
	}
	else if ((msg == WM_KEYDOWN || msg == WM_KEYUP) && (mp1 == VK_DELETE)) {
		// see if we're the last char on the line, if so delete the next line
		// don't allow deleting left of the prompt
		int lineindex = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2;
		int curline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)-1,0);
		int nextline = 0;
		int curpoint = 0;

		SendMessage(hwnd, EM_GETSEL, (WPARAM)&curpoint, (LPARAM)NULL); 
		nextline = SendMessage(hwnd,EM_LINEFROMCHAR,(WPARAM)(curpoint + 2),0);

		if(curpoint < lineindex)
		{	// no chomping behind the prompt
			return 0;
		} else if(nextline != curline) {
			// deleting
			// grab the next line index
			curline -= LastPromptPosition.line;

			// kill it
			editbuffer_removeline(CurrentEditBuffer, curline+1);
		}
	}
	else if (msg == WM_PASTE) {
		// if they paste text, allow it
		r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2);

		// update the current edit buffer
		RefreshCurrentEditBuffer();

		return r;
	}

	// handle errors
	switch(msg)
	{
		case WM_SYNTAXERROR:
		case WM_ILLEGALCHAR:
		case WM_UNBOUNDVAL:
			{	// currently I handle them all the same
				// get the start of the line
				int start = SendMessage(hwnd, EM_LINEINDEX, LastPromptPosition.line, 0) + 2;

				// get the statement that error'd
				NextHistoryEntry();

				// tell the history that the last line errored
				if(History != NULL)
					if(History->Statement != NULL)
						History->Statement->isCorrect = FALSE;

				// highlight the offending chars
				SendMessage(hwnd,EM_SETSEL,(WPARAM)(start + mp1), (LPARAM)(start + mp2));
				
				return 0;
			}
	}

	r = CallWindowProc(lpEProc, hwnd, msg, mp1, mp2);

	if (postit)
		PostMessage(GetParent(hwnd),WM_NEWLINE,0,0);

	return r;
}
Пример #23
0
    void Label::DrawText()
    {
        //Safety check that the font pointer is null
        if(m_Font == nullptr)
        {
            Error(false, "Unable to draw the text of the Label, the font pointer is null");
            return;
        }
        
        //Is there any text to render?
        if(m_Text.length() == 0)
        {
            return;
        }
        
        //calculate the baseline and origin for the label
        unsigned int baseline = m_Font->GetLineHeight() - m_Font->GetBaseLine();
        vec2 origin(0.0f, baseline + (m_Font->GetLineHeight() * (GetNumberOfLines() - 1)));
        int lineIndex = 0;
        
        //What justification are we dealing with
        if(m_Justification == JustifyLeft)
        {
            origin.x = 0.0f;
        }
        else if(m_Justification == JustifyCenter)
        {
            origin.x = (GetSize().x - m_LineWidth.at(lineIndex)) / 2.0f;
        }
        else if(m_Justification == JustifyRight)
        {
            origin.x = GetSize().x - m_LineWidth.at(lineIndex);
        }
        
        //Cycle through the characters in the text label
        for(unsigned int i = 0; i < m_Text.length(); i++)
        {
            //Did we reach a new line?
            if(m_Text.at(i) == '\n')
            {
                //Increment the line index
                lineIndex++;
            
                //Calculate the line's origin based on the justification
                if(m_Justification == JustifyLeft)
                {
                    origin.x = 0.0f;
                }
                else if(m_Justification == JustifyCenter)
                {
                    origin.x = (GetSize().x - m_LineWidth.at(lineIndex)) / 2.0f;
                }
                else if(m_Justification == JustifyRight)
                {
                    origin.x = GetSize().x - m_LineWidth.at(lineIndex);
                }
            
                //Set the y line origin based on the line height of the font
                origin.y -= m_Font->GetLineHeight();
                continue;
            }
            
            //Get the texture frame for the character
            TextureFrame* textureFrame = m_Font->GetTextureFrameForCharacter(m_Text.at(i));
            
            //Safety check the texture frame
            if(textureFrame != nullptr)
            {
                //Calculate the character position based on the x and y bearing
                vec2 charPosition = origin;
                charPosition.x += m_Font->GetBearingXForCharacter(m_Text.at(i));
                charPosition.y += m_Font->GetBearingYForCharacter(m_Text.at(i)) - m_Font->GetSourceFrameForCharacter(m_Text.at(i)).size.y;

                //Draw the character
                DrawCharacter(textureFrame, charPosition);
                
                //Increment the origin
                origin.x += m_Font->GetAdvanceXForCharacter(m_Text.at(i)) + GetCharacterSpacing();
            }
        }
    }
Пример #24
0
int CTortoiseGitBlameData::FindFirstLineWrapAround(SearchDirection direction, const CString& what, int line, bool bCaseSensitive)
{
	bool allAscii = true;
	for (int i = 0; i < what.GetLength(); ++i)
	{
		if (what[i] > 0x7f)
		{
			allAscii = false;
			break;
		}
	}
	CString whatNormalized(what);
	if (!bCaseSensitive)
	{
		whatNormalized.MakeLower();
	}

	CStringA whatNormalizedUtf8 = CUnicodeUtils::GetUTF8(whatNormalized);

	int numberOfLines = GetNumberOfLines();
	int i = line;
	if (direction == SearchPrevious)
	{
		i -= 2;
		if (i < 0)
			i = numberOfLines - 1;
	}
	else if (line < 0 || line + 1 >= numberOfLines)
		i = 0;

	do
	{
		if (bCaseSensitive)
		{
			if (m_Authors[i].Find(whatNormalized) >= 0)
				return i;
			else if (m_Utf8Lines[i].Find(whatNormalizedUtf8) >=0)
				return i;
		}
		else
		{
			if (CString(m_Authors[i]).MakeLower().Find(whatNormalized) >= 0)
				return i;
			else if (FindUtf8Lower(m_Utf8Lines[i], allAscii, whatNormalized, whatNormalizedUtf8) >= 0)
				return i;
		}

		if (direction == SearchNext)
		{
			++i;
			if (i >= numberOfLines)
				i = 0;
		}
		else if (direction == SearchPrevious)
		{
			--i;
			if (i < 0)
				i = numberOfLines - 2;
		}
	} while (i != line);

	return -1;
}
Пример #25
0
void TreatVariations(char *fileName)
{
	char line[LineSize];	// pointer to the line read from the netlist file
	FILE *inputFd;			// file descriptor, used to access its contents
	
	if ((inputFd = fopen(fileName, "r")) == NULL) 
		perror("Failed to open file!");
	
	int numberOfLines = GetNumberOfLines(inputFd);	// counts the number of comment lines to set the size of the variables's vectors
	int indexVectorVariables = 0;					// vectorVariables' iterator
	int indexSteppedVariables = 0;					// steppedVariables' iterator
	
	int steppedVarsIndex = 0;
	int vectorVarsIndex = 0;
	
	int tempFilesIndex = 0;
	int tempFilesIndexHelper = 0;
	FILE *tempFiles[numberOfLines];
	
	VectorVariable vectorVariables[numberOfLines];			// vector for the vector variables
	SteppedVariable steppedVariables[numberOfLines];		// vector for the stepped variables
	
	while (fgets(line, LineSize, inputFd) != NULL)
	{
		if (strstr(strchr(line, '{'), ":") != NULL)
		{
			steppedVariables[indexSteppedVariables] = (SteppedVariable)
			{
				.preffix = "\0",
				.start = 0,
				.end = 0,
				.step = 0,
				.suffix = "\0"
			};
			
			GetRangeFromLine(line, &steppedVariables[indexSteppedVariables++]);
		}
		else
		{
			vectorVariables[indexVectorVariables] = (VectorVariable)
			{
				.preffix = "\0",
				.values = { "\0" },
				.suffix = "\0",
				.numberOfValues = 0
			};
			
			GetVectorFromLine(line, &vectorVariables[indexVectorVariables++]);
		}
	}
	
	if (fclose(inputFd))
		perror("Failed to close file!");
	
	while (vectorVarsIndex < indexVectorVariables)
	{
		tempFiles[tempFilesIndex++] = CreateVectorStructure(&vectorVariables[vectorVarsIndex]);
		vectorVarsIndex++;
	}
	
	while (steppedVarsIndex < indexSteppedVariables)
	{
		tempFiles[tempFilesIndex++] = CreateSteppedStructure(&steppedVariables[steppedVarsIndex]);
		steppedVarsIndex++;
	}
	
	int fileIsEmpty = 1;
	char outputFileName[strlen(fileName) + 10];		// sums the quantities of characters in the file name and in "_alters.sp"
	
	strcpy(outputFileName, fileName);
	strcat(outputFileName, "_alters.sp");
	
	while (tempFilesIndexHelper < tempFilesIndex)
	{
		FillOutFile(tempFiles[tempFilesIndexHelper++], outputFileName, fileIsEmpty);
		fileIsEmpty = 0;
	}
}