Пример #1
0
	//--------------------------------------------------------------------------------
	CUTF16String& CUTF16String::Remove( unsigned short usPos, unsigned short usCount )
	{
		CUTF16Char Begin = CharAt( usPos );
		CUTF16Char End = CharAt( usPos + usCount );

		m_String.Remove( static_cast< unsigned short >( Begin.ptr() - m_String.GetBuffer() ), static_cast< unsigned short >( End.ptr() - Begin.ptr() ) );
		m_String.ReleaseBuffer();
		CountChars();
		return *this;
	}
Пример #2
0
static void
cleartoel (GtkViScreen *vi, guint row, guint col)
{
    CHAR_T *p, *e;

    if (MEMCMP(p = CharAt(vi,row,col), e = CharAt(vi,vi->rows,0), 
		vi->cols - col)) {
	MEMMOVE(p, e, vi->cols - col);
	memset(FlagAt(vi,row,col), COLOR_STANDARD, vi->cols - col);
	mark_lines(vi, row, col, row+1, vi->cols);
    }
}
Пример #3
0
void
gtk_vi_screen_insertln(GtkViScreen *vi)
{
    gint y = vi->cury;
    gint rows = vi->rows - (y+1);

    MEMMOVE(CharAt(vi,y+1,0), CharAt(vi,y,0), rows * vi->cols);
    cleartoel(vi,y,0);
    memmove(FlagAt(vi,y+1,0), FlagAt(vi,y,0), rows * vi->cols);
    memmove(ColAt(vi,y+1,0), ColAt(vi,y,0), rows * vi->cols);
    mark_lines(vi, y+1, 0, vi->rows, vi->cols);
}
Пример #4
0
	//--------------------------------------------------------------------------------
	CUTF16String CUTF16String::Mid( unsigned short usPos, short usLen )
	{
		CUTF16Char Begin = CharAt( usPos );
		CUTF16Char End( Begin );
		End += usLen;
		return CUTF16String( m_String.Mid( static_cast< unsigned short >( Begin.ptr() - m_String.GetBuffer() ), static_cast< unsigned short >( End.ptr() - Begin.ptr() ) ) );
	}
Пример #5
0
void
gtk_vi_screen_addstr(GtkViScreen *vi, const char *str, int len)
{
    CHAR_T *p, *end;
    CHAR_T *line;
    guchar *endcol;
    gint col, startcol;
    gint x;

    line = vi->chars + vi->cury*vi->cols; 
    endcol = vi->endcol + vi->cury*vi->cols;
    x = vi->curx;
    startcol = x ? endcol[x-1] : -1;
    for (p = CharAt(vi,vi->cury,vi->curx), end = p + len, col = startcol; 
		 p < end; ++x) {
	*p++ = *str++;
	endcol[x] = ++col;
    }
    memset(FlagAt(vi,vi->cury,vi->curx), vi->color, len);

    mark_lines(vi, vi->cury, startcol+1, vi->cury+1, endcol[x-1]+1);

    if (endcol[x-1] >= vi->cols) {
	if (++vi->cury >= vi->rows) {
	    vi->cury = vi->rows-1;
	    vi->curx = x-1;
	} else {
	    vi->curx = 0;
	}
    } else vi->curx += len;
    if (x < vi->cols) endcol[x] = vi->cols;
}
Пример #6
0
void
gtk_vi_screen_waddstr(GtkViScreen *vi, const CHAR_T *str, int len)
{
    CHAR_T *p, *end;
    CHAR_T *line;
    guchar *endcol;
    gint col, startcol;
    gint x;

    MEMMOVE(CharAt(vi,vi->cury,vi->curx),str,len);
    memset(FlagAt(vi,vi->cury,vi->curx), vi->color, len);

    line = vi->chars + vi->cury*vi->cols; 
    endcol = vi->endcol + vi->cury*vi->cols;
    x = vi->curx;
    startcol = x ? endcol[x-1] : -1;
    for (col = startcol; x < vi->curx + len; ++x)
	endcol[x] = col += CHAR_WIDTH(NULL, *(line+x));

    mark_lines(vi, vi->cury, startcol+1, vi->cury+1, endcol[x-1]+1);

    if (endcol[x-1] >= vi->cols) {
	if (++vi->cury >= vi->rows) {
	    vi->cury = vi->rows-1;
	    vi->curx = x-1;
	} else {
	    vi->curx = 0;
	}
    } else vi->curx += len;
    if (x < vi->cols) endcol[x] = vi->cols;
}
Пример #7
0
	//--------------------------------------------------------------------------------
	CUTF16String CUTF16String::Left( unsigned short usLen )
	{
		CUTF16Char Pos = CharAt( usLen );
		CUTF16String Result( m_String.Left( static_cast< unsigned short >( Pos.ptr() - m_String.GetBuffer() ) ) );
		m_String.ReleaseBuffer();
		return Result;
	}
Пример #8
0
	//--------------------------------------------------------------------------------
	//Process the string through a functor one character at a time in reverse
	CUTF16String CUTF16String::ReverseProcessByChar( CCharProcessorFunctor& ProcessFunctor, unsigned short usPos )
	{
		CUTF16String strResult;
		CUTF16Char Pos = CharAt( usPos );
		while( Pos.ptr() >= begin() && ProcessFunctor( strResult, Pos ) == eProcessResultMore )
		{
			--Pos;
		}
		return strResult;
	}
Пример #9
0
	//--------------------------------------------------------------------------------
	CUTF16String& CUTF16String::Insert(  unsigned short usPos, CUTF16String& Src )
	{
		if( usPos > m_usCharCount )
		{
			usPos = m_usCharCount;
		}
		CUTF16Char Ref = CharAt( usPos );
		m_String.Insert( static_cast< unsigned short >( Ref.ptr() - m_String.GetBuffer() ), Src.m_String );
		m_String.ReleaseBuffer();
		CountChars();
		return *this;
	}
Пример #10
0
static int Match(fz_text_page *page, const char *str, int n)
{
	int orig = n;
	int c;
	while (*str) 
	{
		str += fz_chartorune(&c, (char *)str);
		if (c == ' ' && CharAt(page, n) == ' ') 
		{
			while (CharAt(page, n) == ' ')
				n++;
		} 
		else 
		{
			if (tolower(c) != tolower(CharAt(page, n)))
				return 0;
			n++;
		}
	}
	return n - orig;
}
Пример #11
0
//
// LoadAEArtFile
// Purpose: Loads a .AEArt file and places it into the table of image files
//
IMAGE *LoadAEArtFile( const char *folder, const char *fileName )
{
  FILE *fp;
  IMAGE *image = NULL;

  // Allocate space to concatenate the folder and the fileName together
  int size = strlen( folder ) + strlen( fileName ) + 2;
  char *pathName = (char *)malloc( size );

  // Copy the folder and fileName into the pathName array
  strcpy_s( pathName, size, folder );
  strcat_s( pathName, size, fileName );

  fopen_s( &fp, pathName, "r" );

  if(fp) // read image contents in file
  {
    int x, y;
    CHAR *thisChar;
    COL *thisColor;
    AE_COORD bottomRight = { 0 };

    fscanf_s( fp, "%d", &bottomRight.x_ );
    fscanf_s( fp, "%d", &bottomRight.y_ );

    image = AllocateImage( fileName, bottomRight.x_, bottomRight.y_ );
    
    for(y = 0; y < bottomRight.y_; ++y)
    {
      for(x = 0; x < bottomRight.x_; ++x)
      {
        int copy = 0;
        thisChar = CharAt( image, x, y );
        fscanf_s( fp, "%d", &copy );
        *thisChar = (char)copy;
      }
    }

    for(y = 0; y < bottomRight.y_; ++y)
    {
      for(x = 0; x < bottomRight.x_; ++x)
      {
        int copy = 0;
        thisColor = ColorAt( image, x, y );
        fscanf_s( fp, "%d", &copy );
        *thisColor = (char)copy;
      }
    }
    fclose( fp );
  }
  return image;
}
Пример #12
0
	SliceString::SliceString(String* _src, unsigned int _begin, unsigned int _end):
		source(_src), begin(_begin), end(_end)
	{
		_hash = 5381;
		int c = 0;

		for (size_type i = 0; i < GetLength(); ++i)
		{
			c = CharAt(i);
			_hash = ((_hash << 5) + _hash) + c;
		}

	}
Пример #13
0
bool
BString::CharAt(int32 charIndex, char* buffer, int32* bytes) const
{
	int32 length;
	const char* charAt = CharAt(charIndex, &length);
	if (bytes != NULL) {
		if (*bytes < length)
			return false;
		*bytes = length;
	}

	memcpy(buffer, charAt, length);
	return true;
}
Пример #14
0
	//--------------------------------------------------------------------------------
	//Process the string through a functor to find the beginning and end of substrings and then process each substring through a second functor
	//This can be used as the basis for tokenizing a string, the beginning of language parsing.
	void CUTF16String::ProcessForSubString( CCharProcessorFunctor& CharFunctor, CStringProcessorFunctor& StringFunctor, unsigned short usPos )
	{
		CUTF16String strResult;
		CUTF16Char Pos = CharAt( usPos );
		do
		{				
			strResult.Clear();
			while( Pos.ptr() != end() && CharFunctor( strResult, Pos ) != eProcessResultBegin )
			{
				++Pos;
			}
			
			while( Pos.ptr() != end() && CharFunctor( strResult, Pos ) == eProcessResultMore )
			{
			}
		}while( StringFunctor( strResult ) != eProcessResultEnd );
	}
Пример #15
0
BString&
BString::ReplaceCharsSet(const char* setOfChars, const char* with)
{
	if (!setOfChars || !with)
		return *this;

	int32 setCharCount = UTF8CountChars(setOfChars, -1);
	if ((uint32)setCharCount == strlen(setOfChars)) {
		// no multi-byte chars at all
		return ReplaceSet(setOfChars, with);
	}

	BString setString(setOfChars);
	BString result;

	int32 withLength = strlen(with);
	int32 charCount = CountChars();
	for (int32 i = 0; i < charCount; i++) {
		int32 charLength;
		const char* sourceChar = CharAt(i, &charLength);
		bool match = false;

		for (int32 j = 0; j < setCharCount; j++) {
			int32 setCharLength;
			const char* setChar = setString.CharAt(j, &setCharLength);
			if (charLength == setCharLength
				&& memcmp(sourceChar, setChar, charLength) == 0) {
				match = true;
				break;
			}
		}

		if (match)
			result.Append(with, withLength);
		else
			result.Append(sourceChar, charLength);
	}

	*this = result;
	return *this;
}
Пример #16
0
	unsigned int ConsString::GetHash() const
	{
		if (_hash != nullptr)
			return *_hash;
		else
		{
			auto mThis = const_cast<ConsString*>(this);
			mThis->_hash = new unsigned int(0);

			*mThis->_hash = 5381;
			int c = 0;

			for (size_type i = 0; i < GetLength(); ++i)
			{
				c = CharAt(i);
				*mThis->_hash = ((*mThis->_hash << 5) + *mThis->_hash) + c;
			}
			return *mThis->_hash;

		}
	}
Пример #17
0
	//--------------------------------------------------------------------------------
	bool CUTF16String::Set( unsigned short usPos, CUTF16Char ch )
	{
		bool bResult = false;
		CUTF16Char Ref = CharAt( usPos );
		if( ValidateReference( Ref ) )
		{
			short sShift = Ref.Len() - ch.Len();

			if( sShift > 0 )
			{
				m_String.Remove( static_cast< unsigned short >( Ref.ptr() - m_String.GetBuffer() ), sShift );	
				m_String.ReleaseBuffer();
			}		
			else if( sShift < 0 )
			{
				CUTF16String strInsert( const_cast< CChar16* >( ch.ptr() ), static_cast< unsigned short >( 0 - sShift ) );
			}
			memcpy( Ref.ptr(), ch.ptr(), Ref.Len() - sShift );
			bResult = true;
		}
		return bResult;
	}
Пример #18
0
void InsertChar(INT Char) {
	INT space = CharSize(Char);

	if (IsViewOnly()) return;
	SetUnsafe();
	if (Mode != ReplaceMode || (HexEditMode ? CharAt(&CurrPos) == C_EOF
											: CharFlags(CharAt(&CurrPos)) & 1))
		Reserve(&CurrPos, space, 0);
	else {
		INT oldspace = CharSize(CharAt(&CurrPos));

		if (space != oldspace) {
			Reserve(&CurrPos, -oldspace, 0);
			Reserve(&CurrPos, space, 0);
		} else {
			EnterDeleteForUndo(&CurrPos, oldspace, 0);
			EnterInsertForUndo(&CurrPos, space);
		}
		ByteAt(&CurrPos);
	}
	++InsertCount;
	if (!SuppressMap) switch (CharSet) {
		case CS_EBCDIC:
			if ((unsigned)Char >= 0x100) Char = 0x1a;
			else Char = MapAnsiToEbcdic[Char];
			break;

		case CS_OEM:
			Char = UnicodeToOemChar(Char);
			break;
	}
	assert(CurrPos.p->PageBuf);
	if (space > 1) {
		POSITION Pos = CurrPos;

		UnsafePage(&CurrPos);
		if (Char == C_CRLF) {
			if (UtfEncoding == 16) {
				assert((Pos.i & 1) == 0 && Pos.i + 1 < Pos.p->Fill);
				if (UtfLsbFirst) {
					Pos.p->PageBuf[Pos.i]	= '\r';
					Pos.p->PageBuf[Pos.i+1]	= '\0';
					Advance(&Pos, 2);
					Pos.p->PageBuf[Pos.i]	= '\n';
					Pos.p->PageBuf[Pos.i+1]	= '\0';
				} else {
					Pos.p->PageBuf[Pos.i]	= '\0';
					Pos.p->PageBuf[Pos.i+1]	= '\r';
					Advance(&Pos, 2);
					Pos.p->PageBuf[Pos.i]	= '\0';
					Pos.p->PageBuf[Pos.i+1]	= '\n';
				}
				assert(Pos.i + 1 < Pos.p->Fill);
			} else {
				Pos.p->PageBuf[Pos.i] = '\r';
				Advance(&Pos, 1);
				Pos.p->PageBuf[Pos.i] = '\n';
			}
		} else if (UtfEncoding == 16) {
			assert(Pos.i + 1 < Pos.p->Fill);
			if (UtfLsbFirst) {
				Pos.p->PageBuf[Pos.i]	= Char;
				Pos.p->PageBuf[Pos.i+1]	= Char >> 8;
			} else {
Пример #19
0
BOOL ClipboardCopy(void)
{	HGLOBAL	  hMem;
	char huge *pMem;
	LONG	  lSize;
	BOOL	  WideCharConvert = FALSE;
	UINT	  Codepage = 0;

	/*prepare resources...*/
	if (!SelectCount) {
		Error(209);
		return (FALSE);
	}
	if (!OpenClipboard(hwndMain)) {
		ErrorBox(MB_ICONEXCLAMATION, 302);
		return (FALSE);
	}
	lSize = SelectCount + sizeof(BinaryPart);
	if (!(GetVersion() & 0x80000000U))
		if (UtfEncoding || CharSet == CS_OEM || AnsiCodePage != CP_ACP) {
			/*copy as wide chars...*/
			Codepage = CharSet == CS_OEM ? OemCodePage : AnsiCodePage;
			if (UtfEncoding != 16)
				lSize <<= 1;
			WideCharConvert = TRUE;
		}
	hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, lSize);
	if (!hMem) {
		CloseClipboard();
		ErrorBox(MB_ICONEXCLAMATION, 304);
		return (FALSE);
	}
	pMem = GlobalLock(hMem);
	if (pMem == NULL) {
		CloseClipboard();
		GlobalFree(hMem);
		ErrorBox(MB_ICONEXCLAMATION, 305);
		return (FALSE);
	}

	/*copy into memory...*/
	{	POSITION Pos;
		ULONG    Bytes = SelectCount;
		UINT     i;
		BOOL	 NullbyteFound = FALSE;

		Pos = SelectStart;
		if (UtfEncoding && WideCharConvert) {
			POSITION EndPos = Pos;
			WCHAR	 *pw = (WCHAR *)pMem;

			Advance(&EndPos, Bytes);
			//if (CountBytes(&Pos) != 0 || (i = CharAndAdvance(&Pos)) == C_BOM)
			i = CharAndAdvance(&Pos);
			for (;;) {
				if (ComparePos(&Pos, &EndPos) > 0)
					break;
				if (i == C_EOF) break;
				if (i == C_CRLF) {
					if ((char *)pw + 6 > pMem + lSize)
						break;
					*pw++ = '\r';
					i = '\n';
				}
				if ((char *)pw + 4 > pMem + lSize)
					break;
				*pw++ = i;
				i = CharAndAdvance(&Pos);
			}
			*pw = '\0';
		} else while (Bytes) {
			LPSTR p, pNull;

			CharAt(&Pos);	/*normalize position and enforce page load*/
			i = Pos.p->Fill - Pos.i;
			if (i > Bytes) i = (UINT)Bytes;
			p = Pos.p->PageBuf + Pos.i;
			if (!NullbyteFound && (pNull = _fmemchr(p, '\0', i)) != NULL) {
				if (ErrorBox(MB_ICONINFORMATION|MB_OKCANCEL, 328) == IDCANCEL) {
					CloseClipboard();
					GlobalUnlock(hMem);
					GlobalFree(hMem);
					return (FALSE);
				}
				NullbyteFound = TRUE;
				i = pNull - p + 1;
				if (CharSet == CS_EBCDIC) EbcdicConvert(pMem, p, i);
				else if (WideCharConvert) {
					MultiByteToWideChar(Codepage, 0, p, i, (WCHAR*)pMem, i);
					pMem += i;
				} else hmemcpy(pMem, p, i);
				pMem  += i;
				Bytes -= --i;
				Pos.i += i;
				i = wsprintf(BinaryPart, BinaryFormat, Bytes);
				if (WideCharConvert) {
					MultiByteToWideChar(Codepage, 0, BinaryPart, i,
													 (WCHAR*)pMem, i);
					pMem += i;
				} else hmemcpy(pMem, BinaryPart, i);
				pMem += i;
				continue;
			}
			if (CharSet == CS_EBCDIC)
				EbcdicConvert(pMem, Pos.p->PageBuf + Pos.i, i);
			else if (WideCharConvert) {
				MultiByteToWideChar(Codepage, 0, Pos.p->PageBuf + Pos.i, i,
												 (WCHAR*)pMem, i);
				if (CharSet == CS_OEM) {
					extern WCHAR const MapLowOemToUtf16[33];
					PWSTR			   pw = (WCHAR*)pMem;
					INT				   j;

					for (j=i; j>0; --j) {
						if (*pw < ' ') {
							switch (*pw) {
							case '\0':
							case '\t':
							case '\n':
							case '\r':	break;
							default:	*pw = MapLowOemToUtf16[*pw];
							}
						}
						++pw;
					}
				}
				pMem += i;
			} else hmemcpy(pMem, Pos.p->PageBuf + Pos.i, i);
			pMem  += i;
			Bytes -= i;
			Pos.i += i;
		}
	}

	/*unlock...*/
	GlobalUnlock(hMem);

	/*clear previous clipboard contents...*/
	if (!EmptyClipboard()) {
		CloseClipboard();
		GlobalFree(hMem);
		ErrorBox(MB_ICONEXCLAMATION, 303);
		return (FALSE);
	}

	/*finally, publish...*/
	SetClipboardData(WideCharConvert ? CF_UNICODETEXT
									 : CharSet == CS_OEM ? CF_OEMTEXT
														 : CF_TEXT, hMem);
	CloseClipboard();
	CheckClipboard();
	return (TRUE);
}
Пример #20
0
BOOL CALLBACK SearchCallback(HWND hDlg, UINT uMsg, WPARAM wPar, LPARAM lPar)
{	extern BOOL SearchBoxPosition, HexEditTextSide;
	extern INT  SearchBoxX, SearchBoxY;
	static RECT DlgRect;
	static BOOL Enabled;
	static CHAR CloseString[10];

	PARAM_NOT_USED(lPar);
	switch (uMsg) {
		RECT r;

		case WM_INITDIALOG:
			GetWindowRect(hDlg, &DlgRect);
			GetWindowRect(GetDlgItem(hDlg, IDC_REPLACE), &r);
			SetWindowPos(hDlg, 0, SearchBoxX, SearchBoxY,
								  DlgRect.right - DlgRect.left,
								  r.top - DlgRect.top,
						 SearchBoxPosition ? SWP_NOZORDER
										   : SWP_NOZORDER | SWP_NOMOVE);
			SendMessage(hDlg, DM_REPOSITION, 0, 0);
			EnableWindow(GetDlgItem(hDlg, IDC_SHOWREPLACE), FALSE);
			if (HexInput != (HexEditMode && !HexEditTextSide)) {
				HexInput ^= TRUE;
				*SearchBuf = '\0';
			}
			if (SelectCount && (HexInput ? 3 : 1) * SelectCount
							   < WSIZE(SearchBuf)) {
				POSITION SelPos;
				INT		 i, c;
				PWSTR	 p = SearchBuf;

				SelPos = SelectStart;
				for (i=(INT)SelectCount; i; --i) {
					if (HexInput) {
						c = ByteAt(&SelPos);
						if (Advance(&SelPos, 1) != 1) break;
						if (UtfEncoding == 16 && i > 1) {
							if (UtfLsbFirst)
								c |= ByteAt(&SelPos) << 8;
							else c = (c << 8) | ByteAt(&SelPos);
							if (Advance(&SelPos, 1) != 1) break;
							--i;
						}
						p += _snwprintf(p, WSIZE(SearchBuf) - (p-SearchBuf),
										UtfEncoding == 16 ? L"%04x " : L"%02x ",
										c);
					} else {
						if ((c = CharAt(&SelPos)) == C_CRLF) c = '\r';
						else if (!UtfEncoding) c = CharSetToUnicode(c);
						if (UtfEncoding == 16) {
							if (i > 1) --i;
							if (Advance(&SelPos, 2) != 2) break;
						} else if (Advance(&SelPos, 1) != 1) break;
						*p++ = c;
					}
				}
				if (HexInput) --p;
				*p = '\0';
				if (*SearchBuf && !ViewOnlyFlag)
					EnableWindow(GetDlgItem(hDlg, IDC_SHOWREPLACE), TRUE);
			} else {
				PWSTR p;

				if ((p = ExtractIdentifier(NULL)) != NULL)
					wcsncpy(SearchBuf, p, WSIZE(SearchBuf));
			}
			Enabled = *SearchBuf!='\0';
			if (Enabled) {
				EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
				SetDlgItemTextW(hDlg, IDC_SEARCHSTRING, SearchBuf);
				SendMessage(hDlg, DM_SETDEFID, IDOK, 0L);
			} else {
				SendMessage(hDlg, DM_SETDEFID, IDCANCEL, 0L);
				EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
			}
			EnableWindow(GetDlgItem(hDlg, IDC_REPLACESTRING), FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_REPLACE),       FALSE);
			EnableWindow(GetDlgItem(hDlg, IDC_REPLACEALL),    FALSE);
			CheckDlgButton(hDlg, *SrchDispBuf=='?' ? IDC_BACKWARD : IDC_FORWARD,
								 TRUE);
			CheckDlgButton(hDlg, IDC_MATCHCASE,	!IgnoreCaseFlag);
			CheckDlgButton(hDlg, IDC_MAGIC,		Magic);
			CheckDlgButton(hDlg, IDC_HEXSEARCH, HexInput);
			CheckDlgButton(hDlg, IDC_WHOLEWORD,	WholeWord);
			CheckDlgButton(hDlg, IDC_WRAPSCAN,	WrapScanFlag);
			LOADSTRING(hInst, 909, CloseString, sizeof(CloseString));
			ReplaceOpen = FALSE;
			PostMessage(hDlg, WM_COMMAND, 4569, 0);	/*for Wine*/
			return (TRUE);

		case WM_COMMAND:
			switch (COMMAND) {
				case 4569:
					/*Disable/enable again for Wine...*/
					EnableWindow(GetDlgItem(hDlg, IDOK), Enabled);
					break;
				case IDOK:
					SearchOk(hDlg);
					break;
				case IDCANCEL:
					if (ReplacingAll) Interrupted = TRUE;
					PostMessage(hDlg, WM_CLOSE, 0, 0);
					break;
				case IDC_SEARCHSTRING:
					GetDlgItemTextW(hDlg, IDC_SEARCHSTRING, CommandBuf, 4);
					if (Enabled != (*CommandBuf != '\0')) {
						if (Enabled ^= TRUE) {
							EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
							SendMessage(hDlg, DM_SETDEFID, IDOK, 0L);
						} else {
							SendMessage(hDlg, DM_SETDEFID, IDCANCEL, 0L);
							EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
						}
						if (ReplaceOpen) {
						  EnableWindow(GetDlgItem(hDlg,IDC_REPLACE),   Enabled);
						  EnableWindow(GetDlgItem(hDlg,IDC_REPLACEALL),Enabled);
						}
					}
					break;
				case IDC_SHOWREPLACE:
					EnableWindow(GetDlgItem(hDlg, IDC_REPLACESTRING), TRUE);
					EnableWindow(GetDlgItem(hDlg, IDC_REPLACE), SelectCount!=0);
					EnableWindow(GetDlgItem(hDlg, IDC_REPLACEALL),	  TRUE);
					SetWindowPos(hDlg, 0,0,0, DlgRect.right-DlgRect.left,
											  DlgRect.bottom-DlgRect.top,
								 SWP_NOZORDER | SWP_NOMOVE);
					SendMessage(hDlg, DM_REPOSITION, 0, 0);
					SetFocus(GetDlgItem(hDlg, IDC_REPLACESTRING));
					SendMessage(hDlg, DM_SETDEFID, IDC_REPLACE, 0L);
					EnableWindow(GetDlgItem(hDlg, IDC_SHOWREPLACE),  FALSE);
					ReplaceOpen = TRUE;
					break;
				case IDC_REPLACE:
					ReplaceSearched(hDlg);
					SetDlgItemText(hDlg, IDCANCEL, CloseString);
					break;
				case IDC_REPLACEALL:
					SetupSearchString(hDlg, NULL);
					GlobalSubst(hDlg);
					SetDlgItemText(hDlg, IDCANCEL, CloseString);
			}
			return (TRUE);

		case WM_MOVE:
		case WM_CLOSE:
			SearchBoxPosition = TRUE;
			GetWindowRect(hDlg, &r);
			SearchBoxX = r.left;
			SearchBoxY = r.top;
			if (uMsg == WM_CLOSE) {
				DestroyWindow(hDlg);
				hwndSearch = NULL;
			}
			return (TRUE);
	}
	return (FALSE);
}
Пример #21
0
void SaveToHTML(SciDoc*sci, FILE *fp )
{
  sci->sendMessage(SCI_COLOURISE, 0, -1);
  int tabSize = 4;
  int lengthDoc = sci->GetTextLength();


  bool styleIsUsed[STYLE_MAX + 1];
  bool onlyStylesUsed=true;
  if (onlyStylesUsed) {
    int i;
    for (i = 0; i <= STYLE_MAX; i++) {
      styleIsUsed[i] = false;
    }
    // check the used styles
    for (i = 0; i < lengthDoc; i++) {
      styleIsUsed[sci->sendMessage(SCI_GETSTYLEAT,i,0) & 0x7F] = true;
    }
  } else {
    for (int i = 0; i <= STYLE_MAX; i++) {
      styleIsUsed[i] = true;
    }
  }
  styleIsUsed[STYLE_DEFAULT] = true;

  fputs( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", fp);

  fputs("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n", fp);
  fputs("<head>\n", fp);
  fprintf(fp, "<title>%s</title>\n", FXPath::name(sci->Filename()).text());
  // Probably not used by robots, but making a little advertisement for those looking
  // at the source code doesn't hurt...
  fputs("<meta name=\"Generator\" content=\""APP_NAME" HTML export\" />\n", fp);
  if ( sci->sendMessage(SCI_GETCODEPAGE,0,0) == SC_CP_UTF8) {
    fputs("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n", fp);
  }
  fputs("<style type=\"text/css\">\n", fp);

  char* bgColour=Settings::globalStyle()->bg;
  LangStyle* ls = sci->getLanguage();

  for (int istyle = 0; istyle <= STYLE_MAX; istyle++) {
    if ((istyle > STYLE_DEFAULT) && (istyle <= STYLE_LASTPREDEFINED)) { continue; }
    if (styleIsUsed[istyle]) {
      StyleDef*sd=GetStyleFromId(ls?ls->styles:Settings::globalStyle(), istyle);
     if (!sd) { sd=Settings::globalStyle(); }
      if (istyle == STYLE_DEFAULT) {
        fprintf(fp, "span {\n");
      } else {
        fprintf(fp, ".S%0d {\n", istyle);
      }
      if (sd->style & Italic) { fprintf(fp, "  font-style: italic;\n"); }
      if (sd->style & Bold) { fprintf(fp, "  font-weight: bold;\n"); }
      if (sd->fg[0]) {
        fprintf(fp, "  color: %s;\n", sd->fg);
      } else if (istyle == STYLE_DEFAULT) {
        fprintf(fp, "  color: #000000;\n");
      }
      if (sd->bg[0]) {
        if (istyle != STYLE_DEFAULT && (strcmp(bgColour,sd->bg)!=0)) {
          fprintf(fp, "  background: %s;\n", sd->bg);
          fprintf(fp, "  text-decoration: inherit;\n");
        }
      }
      fprintf(fp, "}\n");
    }
  }
  fputs("</style>\n", fp);
  fputs("</head>\n", fp);
  if (bgColour[0]) {
    fprintf(fp, "<body bgcolor=\"%s\">\n", bgColour);
  } else {
    fputs("<body>\n", fp);
  }

  int styleCurrent = sci->sendMessage(SCI_GETSTYLEAT,0,0);
  bool inStyleSpan = false;
  bool inFoldSpan = false;
  // Global span for default attributes
  fputs("<pre>", fp);

  if (styleIsUsed[styleCurrent]) {
    fprintf(fp, "<span class=\"S%0d\">", styleCurrent);
    inStyleSpan = true;
  }
  // Else, this style has no definition (beside default one):
  // no span for it, except the global one

  int column = 0;
  for (int i = 0; i < lengthDoc; i++) {
    char ch = sci->sendMessage(SCI_GETCHARAT,i,0);
    int style = sci->sendMessage(SCI_GETSTYLEAT,i,0);

    if (style != styleCurrent) {
      if (inStyleSpan) {
        fputs("</span>", fp);
        inStyleSpan = false;
      }
      if (ch != '\r' && ch != '\n') {  // No need of a span for the EOL
        if (styleIsUsed[style]) {
          fprintf(fp, "<span class=\"S%0d\">", style);
          inStyleSpan = true;
        }
        styleCurrent = style;
      }
    }
    if (ch == ' ') {
    fputc(' ', fp);
    column++;

    } else if (ch == '\t') {
      int ts = tabSize - (column % tabSize);
      for (int itab = 0; itab < ts; itab++) { fputc(' ', fp);  }
      column += ts;
    } else if (ch == '\r' || ch == '\n') {
      if (inStyleSpan) {
        fputs("</span>", fp);
        inStyleSpan = false;
      }
      if (inFoldSpan) {
        fputs("</span>", fp);
        inFoldSpan = false;
      }
      if ((ch == '\r') && (sci->sendMessage(SCI_GETCHARAT, i + 1, 0) == '\n')) {
        i++;  // CR+LF line ending, skip the "extra" EOL char
      }
      column = 0;
      styleCurrent = sci->sendMessage(SCI_GETSTYLEAT, i + 1, 0);
      fputc('\n', fp);
      if (styleIsUsed[styleCurrent] && (CharAt(i+1) != '\r') && (CharAt(i+1) != '\n')) {
        // We know it's the correct next style,
        // but no (empty) span for an empty line
        fprintf(fp, "<span class=\"S%0d\">", styleCurrent);
        inStyleSpan = true;
      }
    } else {
      switch (ch) {
      case '<':
        fputs("&lt;", fp);
        break;
      case '>':
        fputs("&gt;", fp);
        break;
      case '&':
        fputs("&amp;", fp);
        break;
      default:
        fputc(ch, fp);
      }
      column++;
    }
  }
  if (inStyleSpan) {
    fputs("</span>", fp);
  }
  fputs("</pre>", fp);
  fputs("\n</body>\n</html>\n", fp);
}
Пример #22
0
void HTMLExporter::InternalExport(int start, int end)
{
	CString strFontFace(_T("Courier New"));
	int  fontSize = 10;
	bool useTabs = false;

	int tabSize = SendEditor(SCI_GETTABWIDTH, 0, 0);
	if (tabSize == 0)
		tabSize = 4;
	if (!strFontFace.GetLength())
		strFontFace = HTML_FONTFACE;

	// Define a class name lookup table.
	CStringA cssClassNames[STYLE_MAX + 1];
	
	// Write the HTML header...
	//@todo: add a way to select the DOCTYPE
	m_out->puts(HTML_XHTML11STRICT);
	m_out->puts(HTML_STARTXHTML);
	m_out->puts(HTML_HEADOPEN);
	m_out->puts(HTML_TITLEOPEN);
	//@todo: add title
	m_out->puts(HTML_TITLECLOSE);
	m_out->puts(HTML_CSSOPEN);

	CStringA strTemp;

	// Dump the styles into CSS classes
	//@todo: add support for CSS files

	StyleDetails* pDefStyle = GetStyle(STYLE_DEFAULT);
	if(pDefStyle)
	{
		// Apply Default style to the pre block (class name: pn2code)
		strTemp.Format("pre.%scode\n", m_pSchemeName);
		cssClassNames[STYLE_DEFAULT] = strTemp;
		m_out->puts(cssClassNames[STYLE_DEFAULT]);

		m_out->puts(HTML_CSSCLASSOPEN HTML_CSSBKGNDCOLOR);
		strTemp.Format("#%02X%02X%02X",
			GetRValue(pDefStyle->BackColor),
			GetGValue(pDefStyle->BackColor),
			GetBValue(pDefStyle->BackColor));
		m_out->puts(strTemp);
		m_out->puts(HTML_CSSPROPERTYEND);

		m_out->puts(HTML_CSSFORECOLOR);
		strTemp.Format("#%02X%02X%02X;",
			GetRValue(pDefStyle->ForeColor),
			GetGValue(pDefStyle->ForeColor),
			GetBValue(pDefStyle->ForeColor));
		m_out->puts(strTemp);
		m_out->puts(HTML_CSSPROPERTYEND);

		// SF Bug #107412 points to http://www.w3.org/TR/REC-CSS2/fonts.html#font-shorthand
		// defining the (simplified) use of font shorthand as: 
		//    style weight size font-family
		
		m_out->puts(HTML_CSSFONTSHORT);
		
		if(pDefStyle->Italic)
			m_out->puts("italic ");

		if(pDefStyle->Bold)
			m_out->puts("bold ");

		strTemp.Format("%dpt ", pDefStyle->FontSize ? pDefStyle->FontSize : fontSize);
		m_out->puts(strTemp);

		m_out->putc('"');
		if(pDefStyle->FontName.length())
        {
            strTemp = pDefStyle->FontName.c_str();
			m_out->puts(strTemp);
        }
		else
			m_out->puts(HTML_FONTFACE);
		m_out->putc('"');

		m_out->puts(HTML_CSSPROPERTYEND);

		if(pDefStyle->Underline)
			m_out->puts(HTML_CSSUNDERLINE);

		m_out->puts(HTML_CSSCLASSCLOSE);
	}

	for(int istyle = 0; istyle < STYLE_MAX; istyle++)
	{
		StyleDetails* pStyle = GetStyle(istyle);
		if(pStyle)
		{
			// Use the styles classname as CSS class name (if any), or create a
			// generic one
			if(pStyle->classname.length())
				strTemp = pStyle->classname.c_str();
			else
				strTemp.Format("%s%02d", m_pSchemeName, istyle);
			cssClassNames[istyle] = strTemp;
			m_out->putc('.');
			m_out->puts(cssClassNames[istyle]);
			m_out->puts(HTML_CSSCLASSOPEN);

			// Add properties if they differ from the default style only

			if(!pDefStyle || pStyle->BackColor != pDefStyle->BackColor)
			{
				m_out->puts(HTML_CSSBKGNDCOLOR);
				strTemp.Format("#%02X%02X%02X",
					GetRValue(pStyle->BackColor),
					GetGValue(pStyle->BackColor),
					GetBValue(pStyle->BackColor));
				m_out->puts(strTemp);
				m_out->puts(HTML_CSSPROPERTYEND);
			}

			if(!pDefStyle || pStyle->ForeColor != pDefStyle->ForeColor)
			{
				m_out->puts(HTML_CSSFORECOLOR);
				strTemp.Format("#%02X%02X%02X",
					GetRValue(pStyle->ForeColor),
					GetGValue(pStyle->ForeColor),
					GetBValue(pStyle->ForeColor));
				m_out->puts(strTemp);
				m_out->puts(HTML_CSSPROPERTYEND);
			}

			//CString strFont;
			if(pStyle->FontName.length() &&
				(!pDefStyle || pStyle->FontName != pDefStyle->FontName))
			{
				m_out->puts(HTML_CSSFONT);
                strTemp = pStyle->FontName.c_str();
				m_out->puts(strTemp);
				m_out->puts(HTML_CSSENDFONT);
			}

			if(pStyle->FontSize > 0 &&
				(!pDefStyle || pDefStyle->FontSize != pStyle->FontSize))
			{
				m_out->puts(HTML_CSSFONTSIZE);
				strTemp.Format("%dpt", pStyle->FontSize);
				m_out->puts(strTemp);
				m_out->puts(HTML_CSSPROPERTYEND);
			}

			if(pStyle->Bold &&
				(!pDefStyle || pDefStyle->Bold != pStyle->Bold))
			{
				m_out->puts(HTML_CSSFONTBOLD);
			}

			if(pStyle->Italic &&
				(!pDefStyle || pDefStyle->Italic != pStyle->Italic))
			{
				m_out->puts(HTML_CSSFONTITALIC);
			}

			if(pStyle->Underline &&
				(!pDefStyle || pDefStyle->Underline != pStyle->Underline))
				m_out->puts(HTML_CSSUNDERLINE);

			m_out->puts(HTML_CSSCLASSCLOSE);
		}
	}

	m_out->puts(HTML_CSSCLOSE);
	m_out->puts(HTML_HEADCLOSE);
	m_out->puts(HTML_BODYOPEN);

	strTemp.Format(HTML_PREOPEN, m_pSchemeName);
	m_out->puts((LPCSTR)strTemp);

	int styleCurrent = -1;
	bool closePrevious = false;
	for(int i = start; i < end; i++)
	{
		char ch = CharAt(i);
		int style = StyleAt(i);
		if(style > STYLE_DEFAULT)
			style = 0;
		if(style != styleCurrent && style != STYLE_DEFAULT)
		{
			//@todo: check for empty/white space tags
			if(closePrevious == true)
				m_out->puts("</span>");

			if(cssClassNames[style].GetLength() > 0)
			{
				strTemp.Format("<span class='%s'>", cssClassNames[style]);
				m_out->puts(strTemp);
				closePrevious = true;
/*				// inline styles; not recommend
				m_out->puts("<span");
				StyleDetails* pNext = GetStyle(style);
				if(pNext == NULL)
					pNext = pDefStyle;

				GetStyleChange(pCurrent, pNext, NULL);
				pCurrent = pNext;
				m_out->puts(">");*/
			}
			else
				closePrevious = false;

			styleCurrent = style;
		}

		// Deal with special characters:
		if(ch == '&')
			m_out->puts("&amp;");
		else if(ch == '"')
			m_out->puts("&quot;");
		else if(ch == '<')
			m_out->puts("&lt;");
		else if(ch == '>')
			m_out->puts("&gt;");
		else if(ch == '\t')
		{
			if(useTabs)
				m_out->putc(ch);
			else
				for(int itab = 0; itab < tabSize; itab++)
					m_out->putc(' ');
		}
		else if(ch == '\r')
			;
		else if(ch == '\n')
			m_out->putc(ch);
		else
			m_out->putc(ch);
	}

	if(closePrevious == true)
		m_out->puts("</span>");

	m_out->puts(HTML_PRECLOSE HTML_BODYCLOSE HTML_END);
}
Пример #23
0
BOOL EnterDeleteForUndo(PPOSITION Pos, ULONG Length, WORD Flags)
	/*Flags: 1=enter as selected, reselect after undo
	 *		 2=remove last undo information, cannot be undone later
	 */
{	LPBYTE   NewBuf = NULL;
	HGLOBAL  NewMem = 0;
	POSITION p;
	ULONG	 Inx;
	ULONG	 ByteCount = CountBytes(Pos);
	ULONG	 OldSize;
	LPUNDO	 Reallocated = NULL;

	if (Flags & 2) {
		if (!LastUndo->Inserted) return (FALSE);
		--LastUndo->Inserted;
		return (TRUE);
	}
	CheckForUndoneToRelease(TRUE);
	EnableUndo();
	if (!LastUndo ||
		(LastUndo->Pos != (ULONG)-1
		 && (LastUndo->Pos != ByteCount - LastUndo->Inserted
			 || (int)(Flags & 1) != ((LastUndo->Flags & UD_SELECT) != 0)
			 || !(LastUndo->Flags & UD_GLOBALMEM
				  && LastUndo->DelFill+Length > 64000))))
		if (!NewUndo()) return (FALSE);
	if (LastUndo->Pos == (ULONG)-1) LastUndo->Pos = ByteCount;
	if (!LastUndo->DelFill) {
		OldSize = 0;
		if (Length > 64000) {
			LastUndo->Flags |= UD_GLOBALMEM;
			NewMem = GlobalAlloc(GMEM_MOVEABLE, Length);
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			assert(!(LastUndo->Flags & UD_GLOBALMEM));
			LastUndo->Flags &= ~UD_GLOBALMEM;
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO)+Length));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
		}
	} else {
		if (LastUndo->Flags & UD_GLOBALMEM) {
			OldSize = GlobalSize(LastUndo->DelMem);
			if (LastUndo->DelFill + Length > OldSize) {
				NewMem = GlobalReAlloc(LastUndo->DelMem,
									   LastUndo->DelFill + Length,
									   GMEM_MOVEABLE);
			} else NewMem = LastUndo->DelMem;
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO) + Length
														  + LastUndo->DelFill));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
			OldSize = 0;
		}
	}
	UndoMemUsed -= OldSize;
	if (NewBuf == NULL) {
		if (NewMem) GlobalFree(NewMem);
		return (FALSE);
	}
	if (Reallocated!=NULL && Reallocated!=LastUndo) {
		/*correct any references to this object...*/
		if (NextSequenceUndo == LastUndo) NextSequenceUndo = Reallocated;
		if (Reallocated->Prev != NULL) Reallocated->Prev->Next = Reallocated;
		if (FirstUndo == LastUndo) FirstUndo = Reallocated;
		LastUndo = Reallocated;
	}
	Inx = LastUndo->DelFill;
	if (NewMem) {
		UndoMemUsed += GlobalSize(NewMem);
		LastUndo->DelMem = NewMem;
	} else UndoMemUsed += Length;
	LastUndo->DelFill += Length;
	if (Flags & 1) LastUndo->Flags |= UD_SELECT;
	p = *Pos;
	while (Length) {
		UINT n, c = CharAt(&p);

		if (c == C_EOF) {
			/*should not occur!...*/
			assert(c != C_EOF);		/*!?*/
			LastUndo->DelFill -= Length;
			break;
		}
		if (Length > p.p->Fill - p.i) n = p.p->Fill - p.i;
		else n = (UINT)Length;
		assert(p.p->PageBuf);
		assert(n > 0);
		assert(n <= PAGESIZE);
		assert(p.i+n <= PAGESIZE);
		hmemcpy(NewBuf + Inx, p.p->PageBuf + p.i, n);
		Inx += n;
		p.i += n;
		Length -= n;
	}
	if (NewMem) GlobalUnlock(NewMem);
	return (TRUE);
}
Пример #24
0
	//--------------------------------------------------------------------------------
	CUTF16String CUTF16String::Right( unsigned short usLen )
	{
		CUTF16Char Pos = CharAt( m_usCharCount - usLen );
		CUTF16Char End = --end();
		return CUTF16String( m_String.Right( static_cast< unsigned short >( End.ptr() - Pos.ptr() ) ) );
	}