Example #1
0
void
TextContent::handleMouse(const InputEvent &e) { 

    _inp.setEvent(e, _viewport.vpToLocal(e.pos));
    
    //_inp.lastPos.printnl();
    if ( e.state == ae_input_DOWN ) { 
        _selected = e.checkID(_id);
    }

    //check the parse tree?
    if ( _selected ) { 

        if ( _inp.isDepressed ) { 
            _loc = mouseToLoc( _inp.lastPos );
            _magicCharPos = _loc.chr;
            _markLoc = _loc;
        }

        _markSpan = TextSpan(_loc, _markLoc );
    
        _buf->closeEdit();

    }
}
Example #2
0
void
ShellContent::processLine() { 

    _history.push_back( _entry );
    _hpos = _history.size();
//    _output->addTextLine ( (string) _prompt + _entry.str() );
    TextSpan end = TextSpan ( _output->end(), _output->end() );
    _output->insertSpan ( _prompt + _entry.str() + "\n", end );
    
    if ( _entry.substr(0,1) != "/" ) { 
        if ( _entry.size() > 0 ) 
			if ( _console ) { 
				_console->send_command( _entry.str() );
			}
            else { 
				make_system_call(_entry.str() );        
			}
    }
    else { 
		if ( _entry.str() == "/shell" ) { 
			start_shell();
		}
		else { 
			ClientSessionManagerImp::instance()->console_request( _entry.str() );
		}
    }
    _entry = TextLine();
    _loc.chr = 0;

}
Example #3
0
void
TextContent::handleSpec( const InputEvent &e) { 
    _inp.setEvent(e);
   
    switch(_inp.lastSpec) { 

    case KEY_UPARROW:
        moveToLine(_loc.line-1);
        break;
    case KEY_DOWNARROW:
        moveToLine(_loc.line+1);
        break;
    case KEY_LEFTARROW:
        moveToChar(_loc.chr-1 );
        break;
    case KEY_RIGHTARROW:
        moveToChar(_loc.chr+1 );
        break;
    case KEY_F2:
        parse();
    
    }

    if ( !_inp.shiftDown ) _markLoc  = _loc;
    _markSpan = TextSpan(_loc, _markLoc );
    _buf->closeEdit();
}
Example #4
0
void
MarkupParser::_FinishParagraph(bool isLast)
{
	if (!isLast)
		fCurrentParagraph.Append(TextSpan("\n", *fCurrentCharacterStyle));

	if (fCurrentParagraph.IsEmpty()) {
		// Append empty span
		fCurrentParagraph.Append(TextSpan("", fNormalStyle));
	}

	fTextDocument->Append(fCurrentParagraph);
	fCurrentParagraph.Clear();
	fCurrentParagraph.SetStyle(fParagraphStyle);
	fCurrentCharacterStyle = &fNormalStyle;
}
Example #5
0
TextSpan
TextSpan::SubSpan(int32 start, int32 count) const
{
	_TruncateRemove(start, count);

	BString subString;
	if (count > 0)
		fText.CopyCharsInto(subString, start, count);

	return TextSpan(subString, fStyle);
}
Example #6
0
void
MarkupParser::_CopySpan(const BString& text, int32& start, int32 end)
{
	if (start >= end)
		return;

	BString subString;
	text.CopyCharsInto(subString, start, end - start);
	fCurrentParagraph.Append(TextSpan(subString, *fCurrentCharacterStyle));

	start = end;
}
Example #7
0
void
TextContent::handleMotion(const InputEvent &e) { 

    _inp.setEvent( e, _viewport.vpToLocal(e.pos) );

    if ( _inp.isDepressed ) { 
        _loc = mouseToLoc( _inp.lastPos );
        _magicCharPos = _loc.chr;
        _buf->closeEdit();
    }

    _markSpan = TextSpan(_loc, _markLoc );
}
Example #8
0
bool
Paragraph::Append(const TextSpan& span)
{
	// Try to merge with last span if the TextStyles are equal
	if (fTextSpans.CountItems() > 0) {
		const TextSpan& lastSpan = fTextSpans.LastItem();
		if (lastSpan.Style() == span.Style()) {
			BString text(lastSpan.Text());
			text.Append(span.Text());
			fTextSpans.Remove();
			return fTextSpans.Add(TextSpan(text, span.Style()));
		}
	}
	return fTextSpans.Add(span);
}
Example #9
0
bool
Paragraph::Prepend(const TextSpan& span)
{
	_InvalidateCachedLength();

	// Try to merge with first span if the TextStyles are equal
	if (fTextSpans.CountItems() > 0) {
		const TextSpan& firstSpan = fTextSpans.ItemAtFast(0);
		if (firstSpan.Style() == span.Style()) {
			BString text(span.Text());
			text.Append(firstSpan.Text());
			return fTextSpans.Replace(0, TextSpan(text, span.Style()));
		}
	}
	return fTextSpans.Add(span, 0);
}
Example #10
0
void
TextBuffer::endEdit(TextLoc toB, TextLoc toE) { 
	if ( _curEdit.state == EDIT_OPEN ) { 
		_curEdit.to = TextSpan(toB, toE); //always save last span, in case of closeEdit?
		if ( _editDepth > 0 ) --_editDepth;
		else { 
			fillSpan(_curEdit.to);
			_edits.push_back(_curEdit);

			if ( !_inUndo ) mergeEdits(); //possible disaster here. warning! 

			_curEdit.state = EDIT_NEW;
			if ( !_inUndo ) _undoPos = _edits.size() - 1;
		}
	}
	else { fprintf(stderr,"error, edit not opened\n");  return; }
	
}
Example #11
0
void
TextBuffer::startEdit( TextLoc fromB , TextLoc fromE ) { 
	if ( _curEdit.state == EDIT_NEW )  
	{
		_curEdit.from = TextSpan(fromB, fromE);
		fillSpan(_curEdit.from);
		_curEdit.state = EDIT_OPEN;
		_editDepth = 0;
	}
	else if ( _curEdit.state == EDIT_OPEN ) { 
		//as long as successive edits don't modify the original range ( remove, then add...) 
		//this is okay...but we need to check for those cases!
		_editDepth++;
	}
	else { 
		fprintf(stderr,"error, edit not finished\n");  return; 
	}
}
Example #12
0
status_t
TextDocument::Insert(int32 textOffset, const BString& text,
	const CharacterStyle& characterStyle, const ParagraphStyle& paragraphStyle)
{
	int32 paragraphOffset;
	int32 index = ParagraphIndexFor(textOffset, paragraphOffset);
	if (index < 0)
		return B_BAD_VALUE;

	textOffset -= paragraphOffset;

	bool hasLineBreaks = text.FindFirst('\n', 0) >= 0;

	if (hasLineBreaks) {
		// Split paragraph at textOffset
		Paragraph paragraph1(ParagraphAt(index).Style());
		Paragraph paragraph2(paragraphStyle);
		const TextSpanList& textSpans = ParagraphAt(index).TextSpans();
		int32 spanCount = textSpans.CountItems();
		for (int32 i = 0; i < spanCount; i++) {
			const TextSpan& span = textSpans.ItemAtFast(i);
			int32 spanLength = span.CountChars();
			if (textOffset >= spanLength) {
				paragraph1.Append(span);
				textOffset -= spanLength;
			} else if (textOffset > 0) {
				paragraph1.Append(
					span.SubSpan(0, textOffset));
				paragraph2.Append(
					span.SubSpan(textOffset, spanLength - textOffset));
				textOffset = 0;
			} else {
				paragraph2.Append(span);
			}
		}

		fParagraphs.Remove(index);

		// Insert TextSpans, splitting 'text' into Paragraphs at line breaks.
		int32 length = text.CountChars();
		int32 chunkStart = 0;
		while (chunkStart < length) {
			int32 chunkEnd = text.FindFirst('\n', chunkStart);
			bool foundLineBreak = chunkEnd >= chunkStart;
			if (foundLineBreak)
				chunkEnd++;
			else
				chunkEnd = length;

			BString chunk;
			text.CopyCharsInto(chunk, chunkStart, chunkEnd - chunkStart);
			TextSpan span(chunk, characterStyle);

			if (foundLineBreak) {
				if (!paragraph1.Append(span))
					return B_NO_MEMORY;
				if (paragraph1.Length() > 0) {
					if (!fParagraphs.Add(paragraph1, index))
						return B_NO_MEMORY;
					index++;
				}
				paragraph1 = Paragraph(paragraphStyle);
			} else {
				if (!paragraph2.Prepend(span))
					return B_NO_MEMORY;
			}

			chunkStart = chunkEnd + 1;
		}

		if (paragraph2.IsEmpty()) {
			// Make sure Paragraph has at least one TextSpan, even
			// if its empty.
			const TextSpanList& spans = paragraph1.TextSpans();
			const TextSpan& span = spans.LastItem();
			paragraph2.Append(TextSpan("", span.Style()));
		}

		if (!fParagraphs.Add(paragraph2, index))
			return B_NO_MEMORY;
	} else {
		Paragraph paragraph(ParagraphAt(index));
		paragraph.Insert(textOffset, TextSpan(text, characterStyle));
		if (!fParagraphs.Replace(index, paragraph))
			return B_NO_MEMORY;
	}

	return B_OK;
}
Example #13
0
TextSpan
TextBuffer::all() { return TextSpan (begin(), end()); }