MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / EditTabsToSpaces

Function EditTabsToSpaces

src/Edit.c:2077–2184  ·  view source on GitHub ↗

============================================================================= EditTabsToSpaces()

Source from the content-addressed store, hash-verified

2075// EditTabsToSpaces()
2076//
2077void EditTabsToSpaces ( HWND hwnd, int nTabWidth, BOOL bOnlyIndentingWS )
2078{
2079 char *pszText;
2080 LPWSTR pszTextW;
2081 int cchTextW;
2082 int iTextW;
2083 LPWSTR pszConvW;
2084 int cchConvW;
2085 int cchConvM;
2086 int i, j;
2087 int iLine;
2088 int iCurPos;
2089 int iAnchorPos;
2090 int iSelStart;
2091 int iSelEnd;
2092 int iSelCount;
2093 UINT cpEdit;
2094 struct TextRange tr;
2095 BOOL bIsLineStart = TRUE;
2096 BOOL bModified = FALSE;
2097 if ( SC_SEL_RECTANGLE == SendMessage ( hwnd, SCI_GETSELECTIONMODE, 0, 0 ) ) {
2098 MsgBox ( MBINFO, IDS_SELRECT );
2099 return;
2100 }
2101 iCurPos = ( int ) SendMessage ( hwnd, SCI_GETCURRENTPOS, 0, 0 );
2102 iAnchorPos = ( int ) SendMessage ( hwnd, SCI_GETANCHOR, 0, 0 );
2103 if ( iCurPos == iAnchorPos ) /*{
2104 iSelStart = 0;
2105 iSelEnd = SendMessage(hwnd,SCI_GETLENGTH,0,0);
2106 }*/
2107 {
2108 return;
2109 } else {
2110 iSelStart = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONSTART, 0, 0 );
2111 iSelEnd = ( int ) SendMessage ( hwnd, SCI_GETSELECTIONEND, 0, 0 );
2112 }
2113 iLine = ( int ) SendMessage ( hwnd, SCI_LINEFROMPOSITION, ( WPARAM ) iSelStart, 0 );
2114 iSelStart = ( int ) SendMessage ( hwnd, SCI_POSITIONFROMLINE, ( WPARAM ) iLine, 0 );
2115 iSelCount = iSelEnd - iSelStart;
2116 pszText = GlobalAlloc ( GPTR, ( iSelCount ) + 2 );
2117 if ( pszText == NULL ) {
2118 return;
2119 }
2120 pszTextW = GlobalAlloc ( GPTR, ( iSelCount * 2 ) + 2 );
2121 if ( pszTextW == NULL ) {
2122 GlobalFree ( pszText );
2123 return;
2124 }
2125 tr.chrg.cpMin = iSelStart;
2126 tr.chrg.cpMax = iSelEnd;
2127 tr.lpstrText = pszText;
2128 SendMessage ( hwnd, SCI_GETTEXTRANGE, 0, ( LPARAM ) &tr );
2129 cpEdit = ( UINT ) SendMessage ( hwnd, SCI_GETCODEPAGE, 0, 0 );
2130 cchTextW = MultiByteToWideChar ( cpEdit, 0, pszText, iSelCount, pszTextW, ( int ) GlobalSize ( pszTextW ) / sizeof ( WCHAR ) );
2131 GlobalFree ( pszText );
2132 pszConvW = GlobalAlloc ( GPTR, cchTextW * sizeof ( WCHAR ) * nTabWidth + 2 );
2133 if ( pszConvW == NULL ) {
2134 GlobalFree ( pszTextW );

Callers 1

MsgCommandFunction · 0.85

Calls 1

MsgBoxFunction · 0.85

Tested by

no test coverage detected