void FixedHeightLayoutManager::moveCaretEnd(bool isControlPressed)
{
	PlainDocumentLeafElementRefPtr theElement;

	if(isControlPressed)
	{
		_CaretLine = rootElement->getElementCount()-1;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		_CaretIndex = theElement->getTextLength()-2;
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getDocumentModel()->getEndPosition()-2);
		recalculateCaretPositions();
	}
	else
	{
		UInt32 prevIndex = _CaretIndex;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		_CaretIndex = theElement->getTextLength()-2;
		if(_CaretIndex<0)
		{
			SWARNING << "_CaretIndex < 0 .. Setting it to 0"<<std::endl;
			_CaretIndex = 0;
		}
		if(_CaretIndex>prevIndex)
			recalculateCaretPositions();
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ (_CaretIndex - prevIndex));
	}
}
void FixedHeightLayoutManager::moveCaretLeft(void)
{
	PlainDocumentLeafElementRefPtr theElement; 
	if(_CaretIndex>0)
	{
		// set caret line
		// set caret index

		_CaretIndex--;
		// set caret x,y position
		recalculateCaretPositions();
		// set the caret position wrt DOM
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-1);
	}
	else
	{
		if(_CaretLine>0)
		{
			_CaretLine--;
			theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
			_CaretIndex = theElement->getTextLength()-2;
			if(_CaretIndex<0)_CaretIndex = 0;
			recalculateCaretPositions();
			getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-2);
		}
	}
}
void FixedHeightLayoutManager::doubleClickHandler(void)
{
	UInt32 initIndex = _CaretIndex;
	PlainDocumentLeafElementRefPtr theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
	std::string theString = theElement->getText();

	Int32 BeginWord = 0;
	Int32 EndWord = theElement->getTextLength();

	if(isPunctuationChar(theString[_CaretIndex]))
	{
		EndWord = _CaretIndex + 1;
		BeginWord = _CaretIndex;
	}
	else
	{
		for(Int32 i = _CaretIndex; i < theElement->getTextLength(); i++)
		{
			if(!isWordChar(theString[i]))
			{
				EndWord = i;
				break;
			}
		}
		for(Int32 i = _CaretIndex; i >= 0; i--)
		{
			if(!isWordChar(theString[i]))
			{
				BeginWord = i + 1;
				break;
			}
		}
	}

	HEL = HSL = _CaretLine;
	HSI = BeginWord;
	HEI = EndWord;

	_CaretIndex = EndWord;

	recalculateCaretPositions();

	getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ (EndWord - initIndex));

}
bool FixedHeightLayoutManager::isLastCharacterOfDocument() const
{
	if(_CaretLine == rootElement->getElementCount()-1)
	{
		PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		if(_CaretIndex >= temp->getTextLength()-2) return true;
	}
	return  false;
}
void FixedHeightLayoutManager::moveCaretUp(void)
{
	PlainDocumentLeafElementRefPtr theElement;
	
	if(_CaretLine > 0) 
	{
		UInt32 prevIndex = _CaretIndex;
		UInt32 prevLine = _CaretLine;
		_CaretLine--;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		if(_CaretIndex> theElement->getTextLength()-2)_CaretIndex = theElement->getTextLength()-2;
		if(_CaretIndex<0)_CaretIndex=0;
		recalculateCaretPositions();
		UInt32 charactersToBeRewinded=0;
		charactersToBeRewinded += prevIndex;
		charactersToBeRewinded += (theElement->getTextLength() - _CaretIndex);
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-charactersToBeRewinded);
	}
}
void FixedHeightLayoutManager::moveCaretDown(void)
{
	PlainDocumentLeafElementRefPtr theElement;
	if(_CaretLine < rootElement->getElementCount()-1)
	{
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		UInt32 prevIndex = _CaretIndex;
		UInt32 prevLineLength = theElement->getTextLength();
		_CaretLine++;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		if(_CaretIndex> theElement->getTextLength()-2)_CaretIndex = theElement->getTextLength()-2;
		if(_CaretIndex<0)_CaretIndex=0;
		recalculateCaretPositions();
		UInt32 charactersToBeForwarded=0;
		charactersToBeForwarded += _CaretIndex;
		charactersToBeForwarded += (prevLineLength - prevIndex);
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+charactersToBeForwarded);
	}
}
void FixedHeightLayoutManager::selectAll(void)
{
	HSL = 0;
	HSI = 0;
	HEL = rootElement->getElementCount()-1;
	PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(HEL));
	HEI = temp->getTextLength()-2;

	_CaretLine = HEL;
	_CaretIndex = HEI;
	
	recalculateCaretPositions();
}
UInt32 FixedHeightLayoutManager::CaretLineAndIndexToCaretOffsetInDOM(UInt32 CaretLine,UInt32 CaretIndex)
{
	UInt32 offset = 0;
	if(rootElement)
	{
		for(UInt32 i=0;i<CaretLine;i++)
		{
			PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(i));
			offset += temp->getTextLength();
		}
		offset += CaretIndex;
	}
	return offset;
}
char FixedHeightLayoutManager::getNextCharacter(UInt32 _theOriginalCaretIndex,UInt32 _theOriginalCaretLine)
{
	PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_theOriginalCaretLine));
	if(temp->getTextLength()-2 == _theOriginalCaretIndex)
	{
		temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_theOriginalCaretLine+1));
		std::string tempstring = temp->getText();
		return tempstring[0];
	}
	else
	{
		std::string tempstring = temp->getText();
		return tempstring[_theOriginalCaretIndex];
	}
	
}
bool FixedHeightLayoutManager::isLastCharacterOfLine(UInt32 _theOriginalCaretIndex,UInt32 _theOriginalCaretLine)
{
	if(rootElement)
	{
		PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_theOriginalCaretLine));
		if(temp->getTextLength()-2 == _theOriginalCaretIndex)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else 
	{
		return true;
	}
}
void FixedHeightLayoutManager::moveCaretRight(void)
{
	PlainDocumentLeafElementRefPtr theElement; 
	theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
	if(_CaretIndex>=theElement->getTextLength()-2) 
	{
		if(_CaretLine<rootElement->getElementCount()-1)
		{
			_CaretLine++;
			_CaretIndex = 0;
			recalculateCaretPositions();
			getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+2);
		}
	}
	else 
	{
		_CaretIndex++;
		recalculateCaretPositions();
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+1);
	}
}
void FixedHeightLayoutManager::populateCache(void)
{
	// cache exists only when the word wrap is enabled
	if(getParentTextDomArea()->getWrapStyleWord()) 
	{
		linesToElements.clear();

		if(getParentTextDomArea()->getDocumentModel())
		{
			ElementRefPtr defaultRoot=getParentTextDomArea()->getDocumentModel()->getDefaultRootElement();
			if(defaultRoot)
			{
				PlainDocumentBranchElementRefPtr rootElement = dynamic_pointer_cast<PlainDocumentBranchElement>(defaultRoot);

				Pnt2f init = getParentTextDomArea()->getPosition();
				Vec2f dimensions = getParentTextDomArea()->getPreferredSize();
				
			
				for(UInt32 i=0;i<rootElement->getElementCount();i++)
				{
					//GlyphViewRefPtr view = GlyphView::create();
					PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(i));
					//view->setElement(ElementRefPtr(temp));
					UInt32 noOfCharacters= temp->getTextLength();

					/* to be edited............
					Real32 totalLengthOfAllCharacters = noOfCharacters * widthOfCharacter;
					UInt32 noOfLines = UInt32(ceil(totalLengthOfAllCharacters / dimensions.x()));

					for(UInt32 j=0;j<noOfLines;j++)
						linesToElements.push_back(i);
					*/
				}
			}
		}

	}
}
Пример #13
0
void TextDomArea::drawBraceHighlight(Graphics * const TheGraphics, Real32 Opacity) const
{
	if(getLayoutManager()->getBracesHighlightFlag())
	{
		if(getLayoutManager()->getStartingBraceLine() != -1 && getLayoutManager()->getStartingBraceIndex() != -1)
		{
			Pnt2f thePosition = getLayoutManager()->getXYPosition(getLayoutManager()->getStartingBraceLine(),getLayoutManager()->getStartingBraceIndex(),true);
			TheGraphics->drawRect(thePosition,Pnt2f(thePosition.x()+5,thePosition.y()+getLayoutManager()->getHeightOfLine()),Color4f(0.7,0.7,0.0,1.0),Opacity);
		}
		if(getLayoutManager()->getEndingBraceLine() != -1 && getLayoutManager()->getEndingBraceIndex() != -1)
		{
			if(getLayoutManager()->getEndingBraceLine()<getLayoutManager()->getRootElement()->getElementCount())
			{
				PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(getLayoutManager()->getRootElement()->getElement(getLayoutManager()->getEndingBraceLine()));
				if(getLayoutManager()->getEndingBraceIndex() < temp->getTextLength())
				{
					Pnt2f thePosition = getLayoutManager()->getXYPosition(getLayoutManager()->getEndingBraceLine(),getLayoutManager()->getEndingBraceIndex(),true);
					TheGraphics->drawRect(thePosition,Pnt2f(thePosition.x()+5,thePosition.y()+getLayoutManager()->getHeightOfLine()),Color4f(0.7,0.7,0.0,1.0),Opacity);
				}
			}
		}
	}
}
bool PlainTextFileType::write(Document* const Doc, std::ostream &OutputStream,
                    const std::string& FileNameOrExtension)
{
    PlainDocumentRefPtr TheDocument = dynamic_cast<PlainDocument*>(Doc);
    std::vector<Element*> GenericRoots;
    GenericRoots = TheDocument->getRootElements();
    for(UInt32 i=0;i<GenericRoots.size();i++)
    {
        PlainDocumentBranchElementRefPtr RootElement;
        RootElement = dynamic_cast<PlainDocumentBranchElement*>(GenericRoots[i]);    
        
        for(UInt32 j=0;j<RootElement->getElementCount()-1;j++)
        {    
            PlainDocumentLeafElementRefPtr LeafElement;
            LeafElement = dynamic_cast<PlainDocumentLeafElement*>(RootElement->getElement(j));
            OutputStream<<LeafElement->getText();
        }
        PlainDocumentLeafElementRefPtr LeafElement;
        LeafElement = dynamic_cast<PlainDocumentLeafElement*>(RootElement->getElement(RootElement->getElementCount()-1));
        OutputStream<<LeafElement->getText().substr(0,LeafElement->getTextLength()-2);

    }
    return false;
}
void FixedHeightLayoutManager::moveTheCaret(UInt32 dir,bool isShiftPressed,bool isControlPressed)
{

	if(!rootElement || !rootElement->getElementCount()) return;
	UInt32 charactersToBeForwarded;
	PlainDocumentLeafElementRefPtr theElement;
	Int32 tempIndex;
	Int32 tempLine;
	switch(dir)
	{
	case LEFT:
		if(!isShiftPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HSL;					// set caret position to the Highlight Starting position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				else
				{
					_CaretLine = HEL;					// set caret position to the Highlight Ending position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				recalculateCaretPositions();
			}
			else	// nothing was highlighted before this
			{
				if(!isControlPressed)moveCaretLeft();
				else	moveAndHighlightWord(LEFT);

				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else	// if shift is pressed
		{
			if(!isControlPressed)moveCaretLeft();
			else	moveAndHighlightWord(LEFT);

			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;
	case RIGHT:	
		if(!isShiftPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HEL;					// set caret position to the Highlight Starting position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				else
				{
					_CaretLine = HSL;					// set caret position to the Highlight Ending position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				recalculateCaretPositions();
			}
			else	// nothing was highlighted before this
			{
				if(!isControlPressed)moveCaretRight();
				else	moveAndHighlightWord(RIGHT);

				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else	// if shift is pressed
		{
			if(!isControlPressed)moveCaretRight();
			else	moveAndHighlightWord(RIGHT);

			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case UP:
		if(!isShiftPressed && !isControlPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HSL;					// set caret position to the Highlight Starting position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				else
				{
					_CaretLine = HEL;					// set caret position to the Highlight Ending position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				moveCaretUp();
			}
			else	// nothing was highlighted before this
			{
				moveCaretUp();
				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else if(isShiftPressed && !isControlPressed)	// if shift is pressed
		{
			moveCaretUp();
			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case DOWN:	

		if(!isShiftPressed && !isControlPressed)
		{
			if(HSL != HEL || HSI != HEI) // something was highlighted before this
			{
				if(isStartLocationBeforeEndLocation())	
				{					
					_CaretLine = HEL;					// set caret position to the Highlight Starting position
					_CaretIndex = HEI;
					HSI = HEI;
					HSL = HEL;
				}
				else
				{
					_CaretLine = HSL;					// set caret position to the Highlight Ending position
					_CaretIndex = HSI;
					HEI = HSI;
					HEL = HSL;
				}
				moveCaretDown();
			}
			else // nothing was highlighted before this
			{
				moveCaretDown();
				HSI = HEI = _CaretIndex;
				HSL = HEL = _CaretLine;
			}
		}
		else if(isShiftPressed && !isControlPressed)	// if shift is pressed
		{
			moveCaretDown();
			HEI = _CaretIndex;
			HEL = _CaretLine;
		}
		break;

	case HOME:
		moveCaretHome(isControlPressed);
		HEI = _CaretIndex;
		HEL = _CaretLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		break;

	case HOMEOFNEXTLINE:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
		 charactersToBeForwarded = theElement->getTextLength()-_CaretIndex;
		_CaretIndex = 0;
		_CaretLine++;
		recalculateCaretPositions();
		getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ charactersToBeForwarded);

		break;

	case END:
		moveCaretEnd(isControlPressed);
		HEI = _CaretIndex;
		HEL = _CaretLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		break;

	case PAGEUP:
		tempIndex = _CaretIndex;
		tempLine = _CaretLine;
		tempLine -= getLinesToBeDisplayed();
		if(tempLine<0)tempLine = 0;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(tempLine));
		if(tempIndex > theElement->getTextLength()-2)tempIndex = theElement->getTextLength()-2;

		HEI = tempIndex;
		HEL = tempLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		_CaretLine = HEL;					// set caret position to the Highlight Ending position
		_CaretIndex = HEI;
		recalculateCaretPositions();

		break;

	case PAGEDOWN:
		tempIndex = _CaretIndex;
		tempLine = _CaretLine;
		tempLine += getLinesToBeDisplayed();
		if(tempLine>=rootElement->getElementCount())tempLine = rootElement->getElementCount()-1;
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(tempLine));
		if(tempIndex > theElement->getTextLength()-2)tempIndex = theElement->getTextLength()-2;

		HEI = tempIndex;
		HEL = tempLine;
		if(!isShiftPressed)
		{
			HSI = HEI;
			HSL = HEL;
		}
		_CaretLine = HEL;					// set caret position to the Highlight Ending position
		_CaretIndex = HEI;
		recalculateCaretPositions();

		break;
	}
	checkCaretVisibility(dir);
}
bool FixedHeightLayoutManager::isLastCharacter(void)
{
	PlainDocumentLeafElementRefPtr theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
	return (_CaretIndex == theElement->getTextLength()-2);
}
Пример #17
0
void TextDomArea::tabHandler(bool isShiftPressed)
{
	UInt32 lesserLine,greaterLine,lesserIndex;
	DocumentElementAttribute temp;
	UInt32 oldHSI = getLayoutManager()->getHSI();
	UInt32 oldHSL = getLayoutManager()->getHSL();
	UInt32 oldHEI = getLayoutManager()->getHEI();
	UInt32 oldHEL = getLayoutManager()->getHEL();

	PlainDocumentLeafElementRefPtr theElement;
	if(getLayoutManager()->getHSL() <= getLayoutManager()->getHEL())
	{
		lesserLine = getLayoutManager()->getHSL();
		lesserIndex = getLayoutManager()->getHSI();
		greaterLine = getLayoutManager()->getHEL();
	}
	else
	{
		lesserLine = getLayoutManager()->getHEL();
		lesserIndex = getLayoutManager()->getHEI();
		greaterLine = getLayoutManager()->getHSL();
	}

	UInt32 count=0;
	if(getLayoutManager()->isSomethingSelected())
	{
		if(!isShiftPressed)
		{
			for(UInt32 caretLine = lesserLine;caretLine<=greaterLine;caretLine++)
			{
				for(UInt32 i=0;i<getTabSize();i++)
				{
					//getDocumentModel()->insertCharacter(0,caretLine,' ',temp);
					insertCharacterUsingCommandManager(' ',caretLine,0);
				}
				//getLayoutManager()->DoIfLineLongerThanPreferredSize();
			}
		
		}
		else
		{
			for(UInt32 caretLine = lesserLine;caretLine<=greaterLine;caretLine++)
			{
				theElement = dynamic_cast<PlainDocumentLeafElement*>(getLayoutManager()->getRootElement()->getElement(caretLine));
				std::string theString = theElement->getText();
				Int32 i;
				for(i=0;i<theElement->getTextLength()-2,i<getTabSize();i++)
				{
					if(theString[i]!=' ')break;
					if(caretLine == getLayoutManager()->getCaretLine())getLayoutManager()->moveTheCaret(LEFT,false,false);
					if(caretLine == lesserLine)count--;
				}
				theString = theString.substr(i);
				setTextUsingCommandManager(theElement,theString);
				//theElement->setText(theString);
				
			}
			getLayoutManager()->setHSI(0);
			getLayoutManager()->setHSL(lesserLine);
			getLayoutManager()->setHEI(0);
			getLayoutManager()->setHEL(greaterLine);
		}
	}
	else
	{
		if(!isShiftPressed)
		{
			for(UInt32 i=0;i<getTabSize();i++)
			{
				//getDocumentModel()->insertCharacter(getLayoutManager()->getCaretIndex(),getLayoutManager()->getCaretLine(),' ',temp);
				insertCharacterUsingCommandManager(' ',-1,-1);
				//getLayoutManager()->moveTheCaret(RIGHT,false,false);
			}
			//getLayoutManager()->DoIfLineLongerThanPreferredSize();	
		}
		else
		{
			theElement = dynamic_cast<PlainDocumentLeafElement*>(getLayoutManager()->getRootElement()->getElement(getLayoutManager()->getCaretLine()));
			std::string theString = theElement->getText();
			Int32 i,count=0;
			Int32 initIndex = getLayoutManager()->getCaretIndex();
			for(i=getLayoutManager()->getCaretIndex()-1;i>=0,count<getTabSize();i--,count++)
			{
				if(i<0 || theString[i]!=' ')break;
				getLayoutManager()->moveTheCaret(LEFT,false,false);
			}
			theString = theString.substr(0,getLayoutManager()->getCaretIndex())+theString.substr(initIndex);
			setTextUsingCommandManager(theElement,theString);
			//theElement->setText(theString);
		}
	}
}
void FixedHeightLayoutManager::moveAndHighlightWord(UInt32 dir)
{
	Int32 prevIndex= _CaretIndex;
	Int32 prevLine= _CaretLine;
	bool fromPrevElement = false;
	PlainDocumentLeafElementRefPtr theElement; 
	std::string theString;

	switch(dir)
	{

	case LEFT:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));

		if(prevIndex == 0)
		{
			if(prevLine>0)
			{
				prevLine--;
				theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));
				prevIndex = theElement->getTextLength()-2;
				_CaretLine = prevLine;
				_CaretIndex = prevIndex;
				fromPrevElement = true;
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-2);
			}
			else break;
		}

		theString = theElement->getText();

		if(prevIndex>0 && isWordChar(theString[prevIndex-1]) == false)fromPrevElement = true;

		for(Int32 i=prevIndex-1; i>=0;)
		{
			if(isWordChar(theString[i]) != fromPrevElement) // this means that when prevIndex is 0, it would indicate the beginning of the line and hence, the ctrl action should take the cursor until a wordchar is found
			{
				_CaretLine = prevLine;
				_CaretIndex = i;	
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()-1);
				i--;
			}
			else
			{
				break;
			}
		}
		recalculateCaretPositions();
		break;	// case left complete.

	case RIGHT:
		
		theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));

		if(prevIndex >=theElement->getTextLength()-2)
		{
			if(prevLine<rootElement->getElementCount()-1)
			{
				prevLine++;
				prevIndex = 0;
				_CaretLine = prevLine;
				_CaretIndex = prevIndex;
				fromPrevElement = true;
				theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(prevLine));
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+2);
			}
			else break;
		}

		theString = theElement->getText();

		if(isWordChar(theString[prevIndex]) == false)fromPrevElement = true;

		for(UInt32 i=prevIndex; i<theElement->getTextLength()-2;)
		{
			if(isWordChar(theString[i]) != fromPrevElement) // this means that when prevIndex is 0, it would indicate the beginning of the line and hence, the ctrl action should take the cursor until a wordchar is found
			{
				i++;
				_CaretLine = prevLine;
				_CaretIndex = i;	
				getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+1);
			}
			else
			{
				break;
			}
		}
		recalculateCaretPositions();
		break;	// Case Right complete.
	}
}
UInt32 FixedHeightLayoutManager::calculateCaretPosition(Pnt2f PointOnComponent,bool isDragging)
{
	if(!insideGutterRegion(PointOnComponent.x()))
	{

		UInt32 pos = 0, noOfCharacters =0;
		UInt32 row = (UInt32(floor((PointOnComponent.y()/* - getParentTextDomArea()->getPosition().y() */) / heightOfLine)));

		_CaretLine = row;
		// calculating the caret line and caret y position
		_CaretYPosition = row * heightOfLine;
		
		Real32 xpos = PointOnComponent.x() - _GutterSpace - _GutterSeparation ;

		if(row>=rootElement->getElementCount())
		{
			_CaretLine = rootElement->getElementCount()-1;
			PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
			_CaretIndex = temp->getTextLength()-2;

			recalculateCaretPositions();

			HEL = _CaretLine;
			HEI = _CaretIndex;

			if(!isDragging)
			{
				HSL = HEL;
				HSI = HEI;
			}

			printDebugInformation();

			getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getDocumentModel()->getEndPosition()-2);
			return 0;	
		}
		for(UInt32 i=0;i<_CaretLine;i++)
		{
			PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(i));
			noOfCharacters= temp->getTextLength();
			pos += noOfCharacters;
		}
		PlainDocumentLeafElementRefPtr temp = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(row));

		noOfCharacters = 0;

		std::string temptext = temp->getText();
		Pnt2f topLeft,bottomRight;

		std::string ttemp = ""; 

		Real32 widthSoFar = 0.0;
		_CaretIndex = 0;

		for(UInt32 i=0;i<temp->getTextLength()-2;i++)
		{
			ttemp = temptext[i];
			getParentTextDomArea()->getFont()->getBounds(ttemp,topLeft,bottomRight);

			if(widthSoFar + bottomRight.x() <= xpos) 
			{
				noOfCharacters++;
				widthSoFar += bottomRight.x();
				_CaretIndex++;
			}
			else
			{
				break;
			}
			
		}

		_CaretXPosition = _GutterSpace + _GutterSeparation + widthSoFar;
		pos += noOfCharacters;

		HEL = _CaretLine;
		HEI = _CaretIndex;

		if(!isDragging)
		{
			HSL = HEL;
			HSI = HEI;
		}

		printDebugInformation();

		getParentTextDomArea()->setCaretPosition(pos);
		return pos;
	}
}