Example #1
0
SchemeEditor::SchemeEditor(int X, int Y, int W, int H, const char *l) : Fl_Text_Editor(X, Y, W, H, l) {
	pmatch = true;

	/* setup buffers */
	textbuf = new Fl_Text_Buffer();
	stylebuf = new Fl_Text_Buffer();

	buffer(textbuf);

	textbuf->add_modify_callback(style_update, this);
	textbuf->call_modify_callbacks();

	highlight_data(stylebuf, styletable,
				   sizeof(styletable) / sizeof(styletable[0]),
				   'A', style_unfinished_cb, 0);

	style_init(textbuf, stylebuf);
}
Example #2
0
/*
	Function which sets text into main text buffer, and creates
	appropriate text which puts into style text buffer, and then if
	highlight array is passed, creates array of styles which is used
	to style original text.

	@param lineNum -> (int) number of lines to be set as text
	@param text -> (const char **) array of strings (creation and deletion handled elsewhere).
	@param highlight -> (const int *) (has default) array of indexes which should
						be highlighted, creation and deletion handled elsewhere.
*/
void ListDisplay::setText(int lineNum, const char** text, const int* highlight)
{
	txtBuff -> text("");
	styleBuff -> text("");

	char* temp;

	for (int i = 0; i < lineNum; i++)
	{
		// write as much characters to style buffer
		int j = 0;
		for (; j < 100; j++)
			if (text[i][j] == '\n')
				break;
		
		temp = new char[j + 2];

		for (int k = 0; k < j; k++)
			temp[k] = ListDisplay::styles[i % 24];		
		temp[j] = '\n';
		temp[j + 1] = '\0';

		txtBuff -> append(text[i]);
		// txtBuff -> append(temp);
		styleBuff -> append(temp);

		delete[] temp;
	}

	if (style != nullptr)
		delete[] style;

	style = new Fl_Text_Display::Style_Table_Entry[lineNum];
	for (int i = 0; i < lineNum; i++)
	{
		style[i].color = (highlight != nullptr ? (i == highlight[0] || i == highlight[1] ? FL_RED : FL_BLACK) : FL_BLACK);
		style[i].font = FL_BOLD_ITALIC; style[i].size = 16; // A - Red
	}

	int style_size = sizeof((*style))* lineNum/sizeof(style[0]);
	highlight_data(styleBuff, style, style_size, 'A', 0, 0);

	redraw();
}