Exemplo n.º 1
0
void SheetView::redrawCell(CellAddress addr,bool dorefresh){
	if(addr.row<scroll.row||addr.column<scroll.column||
	   addr.row>=scroll.row+LINES-1||addr.column>=scroll.column+COLS/8-1){
		return;
	}
	sheet.ensureSheetSize(addr.column+1,addr.row+1);
	int leftx;
	string dispvalue,value;
	dispvalue=sheet.getCellDisplayString(addr).fromJust();
	if(addr==cursor){
		value=sheet.getCellEditString(addr).fromJust();
		if(dispvalue.size()>8&&dispvalue!=value){
			displayStatusString(dispvalue); //inform of full display value
		}
		attron(A_REVERSE);
		leftx=min(columnToX(addr.column),COLS/8*8-(int)value.size());
	} else {
		value=sheet.getCellDisplayString(addr).fromJust();
		if(value.size()>8)value.erase(value.begin()+8,value.end());
		leftx=columnToX(addr.column);
	}
	string blankstr(max(8,(int)value.size()),' ');
	mvaddstr(rowToY(addr.row),leftx,blankstr.data());
	mvaddstr(rowToY(addr.row),leftx,value.data());
	if(addr==cursor){
		attroff(A_REVERSE);
		cursordispval=value;
	}
	if(dorefresh){
		refresh();
		move(rowToY(cursor.row),columnToX(cursor.column));
	}
}
Exemplo n.º 2
0
void SheetView::redraw(bool full){
	if(full){
		clear();
	}
	int i,j;
	move(0,0);
	addstr("        ");
	attron(A_REVERSE);
	for(i=0;i<COLS/8-1;i++){
		string label=centreString(columnLabel(i+scroll.column),8);
		mvaddstr(0,columnToX(i+scroll.column),label.data());
	}
	for(i=0;i<LINES-2;i++){
		string label=centreString(to_string(i+1+scroll.row),8);
		mvaddstr(rowToY(i+scroll.row),0,label.data());
	}
	attroff(A_REVERSE);
	for(i=0;i<COLS/8-1;i++){
		for(j=0;j<LINES-2;j++){
			if(CellAddress(j+scroll.row,i+scroll.column)==cursor)continue;
			redrawCell(CellAddress(j+scroll.row,i+scroll.column),false);
		}
	}
	redrawCell(cursor,true);
}
Exemplo n.º 3
0
Maybe<string> SheetView::getStringWithEditWindowOverCell(CellAddress loc,string defval){
	const int cellx=columnToX(loc.column),celly=rowToY(loc.row);
	const int popupx=min(cellx,COLS-17);
	drawBoxAround(popupx,celly,16,1);
	move(celly,popupx);
	Maybe<string> ret=getTextBoxString(16,defval);
	redraw(true); //full redraw to remove any artifacts right of the cells, possibly
	return ret;
}
Exemplo n.º 4
0
	void TextEditor::draw(DrawingSurface::Ptr& surface, float xOffset, float yOffset) const
	{
		if (!pVisible)
			return;

		Point2D<float> pos(pPosition.x + xOffset, pPosition.y + yOffset);

		// Draw background
		surface->drawFilledRectangle(pBackColor, pBackColor, pos.x, pos.y, pSize.x, pSize.y, 0.0f);

		surface->beginRectangleClipping(pos.x, pos.y, pSize.x, pSize.y);

		// Draw the text
		float pixelLineHeight = pLineHeight(pConversion);
		float x = pos.x + pHorizMargin;
		float y = pos.y + pVertMargin;
		const uint lastVisibleLine = YToLine(pSize.y - pVertMargin);
		// Loop on lines of text
		uint lineNb = pScrollPos.y;
		AnyString text(pText, cursorToByte(pScrollPos));
		text.words("\n", [&](AnyString& line) -> bool
		{
			if (lineNb++ > lastVisibleLine)
				return false;
			// TODO : x scroll offset ?
			if (!line.empty())
			{
				// Crop trailing `\r` (CR) if necessary
				if ('\r' == line[line.length() - 1])
					line.truncate(line.length() - 1);
				// Ignore empty lines (test a second time to catch single "\r" lines)
				if (!line.empty())
				{
					// y is the baseline position, not the top
					surface->drawText(line, pFont, pColor, x, y - pixelLineHeight / 2, pTabWidth, true);
				}
			}
			y += pixelLineHeight;
			return true;
		}, true);

		// Draw the cursor
		if (pCursorPos.y >= pScrollPos.y && pCursorPos.y <= lastVisibleLine)
		{
			float cx = columnToX(pCursorPos.x);
			float cy = lineToY(pCursorPos.y);
			surface->drawLine(pColor, cx, cy, cx, cy + pixelLineHeight, 1.0f);
		}

		// Draw line and column numbers
		surface->drawText(String(pCursorPos.y + 1) << ':' << pCursorPos.x, pFont, pColor, pSize.x - 50, pSize.y - 15);

		surface->endClipping();
		pModified = false;
	}