⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scintillaeditview.cpp.svn-base

📁 Notepad++ is a generic source code editor (it tries to be anyway) and Notepad replacement written in
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:

	COLORREF foldMarginColor = grey;
	COLORREF foldMarginHiColor = white;
	i = stylers.getStylerIndexByName("Fold margin");
	if (i != -1)
	{
		Style & style = stylers.getStyler(i);
		foldMarginHiColor = style._fgColor;
		foldMarginColor = style._bgColor;
	}
	execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor);
	execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor);

	//StyleArray & stylers = _pParameter->getMiscStylerArray();
	COLORREF foldfgColor = white;
	COLORREF foldbgColor = grey;
	i = stylers.getStylerIndexByName("Fold");

	if (i != -1)
	{
		Style & style = stylers.getStyler(i);
		foldfgColor = style._bgColor;
		foldbgColor = style._fgColor;
	}
	for (int j = 0 ; j < NB_FOLDER_STATE ; j++)
        defineMarker(_markersArray[FOLDER_TYPE][j], _markersArray[_folderStyle][j], foldfgColor, foldbgColor);

	COLORREF wsSymbolFgColor = black;
	//COLORREF wsSymbolBgColor = white;
	i = stylers.getStylerIndexByName("White space symbol");
	if (i != -1)
	{
		Style & style = stylers.getStyler(i);
		wsSymbolFgColor = style._fgColor;
		//wsSymbolBgColor = style._bgColor;
	}
	execute(SCI_SETWHITESPACEFORE, true, wsSymbolFgColor);
	//execute(SCI_SETWHITESPACEBACK, true, wsSymbolBgColor);

}

void ScintillaEditView::setLineIndent(int line, int indent) const {
	if (indent < 0)
		return;
	CharacterRange crange = getSelection();
	int posBefore = execute(SCI_GETLINEINDENTPOSITION, line);
	execute(SCI_SETLINEINDENTATION, line, indent);
	int posAfter = execute(SCI_GETLINEINDENTPOSITION, line);
	int posDifference = posAfter - posBefore;
	if (posAfter > posBefore) {
		// Move selection on
		if (crange.cpMin >= posBefore) {
			crange.cpMin += posDifference;
		}
		if (crange.cpMax >= posBefore) {
			crange.cpMax += posDifference;
		}
	} else if (posAfter < posBefore) {
		// Move selection back
		if (crange.cpMin >= posAfter) {
			if (crange.cpMin >= posBefore)
				crange.cpMin += posDifference;
			else
				crange.cpMin = posAfter;
		}
		if (crange.cpMax >= posAfter) {
			if (crange.cpMax >= posBefore)
				crange.cpMax += posDifference;
			else
				crange.cpMax = posAfter;
		}
	}
	execute(SCI_SETSEL, crange.cpMin, crange.cpMax);
}

const char * ScintillaEditView::getCompleteKeywordList(std::string & kwl, LangType langType, int keywordIndex)
{
	kwl += " ";
	const char *defKwl = _pParameter->getWordList(langType, keywordIndex);
	kwl += defKwl?defKwl:"";
	return kwl.c_str();
}

void ScintillaEditView::convertSelectedTextTo(bool Case) 
{
	unsigned int codepage = _codepage;
	UniMode um = getCurrentBuffer().getUnicodeMode();
	if (um != uni8Bit)
		codepage = CP_UTF8;

	if (execute(SCI_SELECTIONISRECTANGLE))
	{
		execute(SCI_BEGINUNDOACTION);

		ColumnModeInfo cmi = getColumnModeSelectInfo();
		const int len = cmi[0].second - cmi[0].first;
		char *srcStr = new char[len];
		wchar_t *destStr = new wchar_t[len];
		for (size_t i = 0 ; i < cmi.size() ; i++)
		{
			int start = cmi[i].first;
			int end = cmi[i].second;
			getText(srcStr, start, end);

			int nbChar = ::MultiByteToWideChar(codepage, 0, srcStr, len, destStr, len);

			for (int j = 0 ; j < nbChar ; j++)
			{
				if (Case == UPPERCASE)
					destStr[j] = (wchar_t)::CharUpperW((LPWSTR)destStr[j]);
				else
					destStr[j] = (wchar_t)::CharLowerW((LPWSTR)destStr[j]);
			}
			::WideCharToMultiByte(codepage, 0, destStr, len, srcStr, len, NULL, NULL);

			execute(SCI_SETTARGETSTART, start);
			execute(SCI_SETTARGETEND, end);
			execute(SCI_REPLACETARGET, -1, (LPARAM)srcStr);
		}

		delete [] srcStr;
		delete [] destStr;

		execute(SCI_ENDUNDOACTION);
		return;
	}

	size_t selectionStart = execute(SCI_GETSELECTIONSTART);
	size_t selectionEnd = execute(SCI_GETSELECTIONEND);
	
	int strSize = ((selectionEnd > selectionStart)?(selectionEnd - selectionStart):(selectionStart - selectionEnd))+1;
	
	if (strSize)
	{
		char *selectedStr = new char[strSize];
		int strWSize = strSize * 2;
		WCHAR *selectedStrW = new WCHAR[strWSize];

		execute(SCI_GETSELTEXT, 0, (LPARAM)selectedStr);

		int nbChar = ::MultiByteToWideChar(codepage, 0, selectedStr, strSize, selectedStrW, strWSize);

		for (int i = 0 ; i < nbChar ; i++)
		{
			if (Case == UPPERCASE)
				selectedStrW[i] = (WCHAR)::CharUpperW((LPWSTR)selectedStrW[i]);
			else
				selectedStrW[i] = (WCHAR)::CharLowerW((LPWSTR)selectedStrW[i]);
		}
		::WideCharToMultiByte(codepage, 0, selectedStrW, strWSize, selectedStr, strSize, NULL, NULL);

		execute(SCI_REPLACESEL, strSize, (LPARAM)selectedStr);
		execute(SCI_SETSEL, selectionStart, selectionEnd);
		delete [] selectedStr;
		delete [] selectedStrW;
	}
}

bool ScintillaEditView::expandWordSelection()
{
	int caretPos = execute(SCI_GETCURRENTPOS, 0, 0);
	int startPos = static_cast<int>(execute(SCI_WORDSTARTPOSITION, caretPos, true));
	int endPos = static_cast<int>(execute(SCI_WORDENDPOSITION, caretPos, true));
	if (startPos != endPos) {
		execute(SCI_SETSELECTIONSTART, startPos);
		execute(SCI_SETSELECTIONEND, endPos);
		return true;
	}
	return false;
}


void ScintillaEditView::arrangeBuffers(UINT nItems, UINT *items) {
	// Do nothing if item size mismatches
	if (nItems != getNbDoc())
		return;
	int ncurpos = getCurrentDocIndex();
	int newpos = 0;
	UINT i;
	buf_vec_t tmp;
	for (i=0; i<nItems; ++i) 
	{
		tmp.push_back(_buffers[items[i]]);
	}
	for (i=0; i<nItems; ++i) 
	{
		if (tmp[i]._fullPathName[0] == 0)
			return; // abort if we find an invalid buffer.
		if (items[i] == ncurpos)
			newpos = i;
	}
	tmp.swap(_buffers);
	setCurrentIndex(newpos);
}

char * int2str(char *str, int strLen, int number, int base, int nbChiffre, bool isZeroLeading) 
{
	if (nbChiffre >= strLen) return NULL;
	char f[64];
	char fStr[2] = "d";
	if (base == 16)
		fStr[0] = 'X';
	else if (base == 8)
		fStr[0] = 'o';
	else if (base == 2)
	{
		//printInt(nbChiffre);
		const unsigned int MASK_ULONG_BITFORT = 0x80000000;
		int nbBits = sizeof(unsigned int) * 8;
		int nbBit2Shift = (nbChiffre >= nbBits)?nbBits:(nbBits - nbChiffre);
		unsigned long mask = MASK_ULONG_BITFORT >> nbBit2Shift;
		int i = 0; 
		for (; mask > 0 ; i++)
		{
			str[i] = (mask & number)?'1':'0';
			mask >>= 1;
		}
		str[i] = '\0';
	}

	if (!isZeroLeading)
	{
		if (base == 2)
		{
			char *j = str;
			for ( ; *j != '\0' ; j++)
				if (*j == '1')
					break;
			strcpy(str, j);
		}
		else
		{
			sprintf(f, "%%%s", fStr);
			sprintf(str, f, number);
		}
		int i = strlen(str);
		for ( ; i < nbChiffre ; i++)
			str[i] = ' ';
		str[i] = '\0';
	}
	else
	{
		if (base != 2)
		{
			sprintf(f, "%%.%d%s", nbChiffre, fStr);
			sprintf(str, f, number);
		}
		// else already done.
	}
	return str;
}

ColumnModeInfo ScintillaEditView::getColumnModeSelectInfo()
{
	ColumnModeInfo columnModeInfo;
	if (execute(SCI_SELECTIONISRECTANGLE))
	{
		int selStartAbsPos = execute(SCI_GETSELECTIONSTART);
		int selEndAbsPos = execute(SCI_GETSELECTIONEND);

		int startCol = execute(SCI_GETCOLUMN, selStartAbsPos);
		int endCol = execute(SCI_GETCOLUMN, selEndAbsPos);

		int startLine = execute(SCI_LINEFROMPOSITION, selStartAbsPos);
		int endLine = execute(SCI_LINEFROMPOSITION, selEndAbsPos);
		
		if (endCol < startCol)// another way of selection
		{
			int tmp = startCol;
			startCol = endCol;
			endCol = tmp;

			selStartAbsPos = execute(SCI_FINDCOLUMN, startLine, startCol);
			selEndAbsPos = execute(SCI_FINDCOLUMN, endLine, endCol);
		}

		bool zeroCharSelMode = true;
		for (int i = startLine ; i <= endLine ; i++)
		{		
			int absPosSelStartPerLine =  execute(SCI_FINDCOLUMN, i, startCol);
			int absPosSelEndPerLine = execute(SCI_FINDCOLUMN, i, endCol);

			if (absPosSelStartPerLine != absPosSelEndPerLine)
			{	
				zeroCharSelMode = false;
			}
			columnModeInfo.push_back(pair<int, int>(absPosSelStartPerLine, absPosSelEndPerLine));
		}

		if (!zeroCharSelMode)
		{
			for (int i = columnModeInfo.size() - 1 ; i >= 0 ; i--)
			{
				ColumnModeInfo::iterator it = columnModeInfo.begin() + i;
				if (it->first == it->second)
					columnModeInfo.erase(it);
			}
		}
	}
	return columnModeInfo;
}

void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, const char *str)
{
	//for (int i = (int)cmi.size() - 1 ; i >= 0 ; i--)
	int totalDiff = 0;
	for (size_t i = 0 ; i < cmi.size() ; i++)
	{
		int len2beReplace = cmi[i].second - cmi[i].first;
		int diff = strlen(str) - len2beReplace;

		cmi[i].first += totalDiff;
		cmi[i].second += totalDiff;

		execute(SCI_SETTARGETSTART, cmi[i].first);
		execute(SCI_SETTARGETEND, cmi[i].second);
		execute(SCI_REPLACETARGET, -1, (LPARAM)str);

		totalDiff += diff;
		cmi[i].second += diff;
		//printStr("fin");
	}
}






void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int incr, unsigned char format)
{
	// 0000 00 00 : Dec BASE_10
	// 0000 00 01 : Hex BASE_16
	// 0000 00 10 : Oct BASE_08
	// 0000 00 11 : Bin BASE_02

	// 0000 01 00 : 0 leading

	//Defined in ScintillaEditView.h :
	//const unsigned char MASK_FORMAT = 0x03;
	//const unsigned char MASK_ZERO_LEADING = 0x04;

	unsigned char f = format & MASK_FORMAT;
	bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0;
	
	int base = 10;
	if (f == BASE_16)
		base = 16;
	else if (f == BASE_08)
		base = 8;
	else if (f == BASE_02)
		base = 2;

	int endNumber = initial + incr * (cmi.size() - 1);
	int nbEnd = getNbChiffre(endNumber, base);
	int nbInit = getNbChiffre(initial, base);
	int nb = max(nbInit, nbEnd);

	char str[512];

	int totalDiff = 0;
	for (size_t i = 0 ; i < cmi.size() ; i++)
	{
		int len2beReplace = cmi[i].second - cmi[i].first;
		int diff = nb - len2beReplace;

		cmi[i].first += totalDiff;
		cmi[i].second += totalDiff;

		int2str(str, sizeof(str), initial, base, nb, isZeroLeading);
		
		execute(SCI_SETTARGETSTART, cmi[i].first);
		execute(SCI_SETTARGETEND, cmi[i].second);
		execute(SCI_REPLACETARGET, -1, (LPARAM)str);

		initial += incr;
		
		totalDiff += diff;
		cmi[i].second += diff;
	}
}


void ScintillaEditView::columnReplace(const ColumnModeInfo & cmi, const char ch)
{
	for (size_t i = 0 ; i < cmi.size() ; i++)
	{
		int len = cmi[i].second - cmi[i].first;
		string str(len, ch);
		execute(SCI_SETTARGETSTART, cmi[i].first);
		execute(SCI_SETTARGETEND, cmi[i].second);
		execute(SCI_REPLACETARGET, -1, (LPARAM)str.c_str());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -