ReactOS 0.4.15-dev-5666-gc548b97
main.h File Reference
#include "notepad_res.h"
Include dependency graph for main.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  NOTEPAD_GLOBALS
 

Macros

#define ARRAY_SIZE(a)   (sizeof(a)/sizeof((a)[0]))
 
#define EDIT_STYLE_WRAP
 
#define EDIT_STYLE   (EDIT_STYLE_WRAP | WS_HSCROLL | ES_AUTOHSCROLL)
 
#define EDIT_CLASS   _T("EDIT")
 
#define MAX_STRING_LEN   255
 

Enumerations

enum  ENCODING {
  ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 , ENCODING_UTF16BE = 2 , ENCODING_UTF8 = 3 ,
  ENCODING_AUTO = -1 , ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 , ENCODING_UTF16BE = 2 ,
  ENCODING_UTF8 = 3 , ENCODING_UTF8BOM = 4 , ENCODING_ANSI = 0 , ENCODING_UTF16LE = 1 ,
  ENCODING_UTF16BE = 2 , ENCODING_UTF8 = 3 , ENCODING_ANSI = 1 , ENCODING_UTF8 ,
  ENCODING_UTF16LE , ENCODING_UTF16BE
}
 
enum  EOLN { EOLN_CRLF = 0 , EOLN_LF = 1 , EOLN_CR = 2 }
 

Functions

VOID SetFileName (LPCTSTR szFileName)
 
BOOL ReadText (HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN *piEoln)
 
BOOL WriteText (HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, EOLN iEoln)
 
void NOTEPAD_LoadSettingsFromRegistry (void)
 
void NOTEPAD_SaveSettingsToRegistry (void)
 
BOOL NOTEPAD_FindNext (FINDREPLACE *, BOOL, BOOL)
 
VOID NOTEPAD_EnableSearchMenu (VOID)
 

Variables

NOTEPAD_GLOBALS Globals
 

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   a)    (sizeof(a)/sizeof((a)[0]))

Definition at line 24 of file main.h.

◆ EDIT_CLASS

#define EDIT_CLASS   _T("EDIT")

Definition at line 32 of file main.h.

◆ EDIT_STYLE

Definition at line 30 of file main.h.

◆ EDIT_STYLE_WRAP

#define EDIT_STYLE_WRAP
Value:
#define WS_CHILD
Definition: pedump.c:617
#define ES_AUTOVSCROLL
Definition: pedump.c:671
#define ES_NOHIDESEL
Definition: pedump.c:673
#define WS_VSCROLL
Definition: pedump.c:627
#define ES_MULTILINE
Definition: pedump.c:667

Definition at line 28 of file main.h.

◆ MAX_STRING_LEN

#define MAX_STRING_LEN   255

Definition at line 34 of file main.h.

Enumeration Type Documentation

◆ ENCODING

Enumerator
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_AUTO 
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_UTF8BOM 
ENCODING_ANSI 
ENCODING_UTF16LE 
ENCODING_UTF16BE 
ENCODING_UTF8 
ENCODING_ANSI 
ENCODING_UTF8 
ENCODING_UTF16LE 
ENCODING_UTF16BE 

Definition at line 37 of file main.h.

38{
39 ENCODING_AUTO = -1,
40 ENCODING_ANSI = 0,
43 ENCODING_UTF8 = 3,
45} ENCODING;
ENCODING
Definition: main.h:38
@ ENCODING_AUTO
Definition: main.h:39
@ ENCODING_UTF16BE
Definition: main.h:42
@ ENCODING_UTF8BOM
Definition: main.h:44
@ ENCODING_UTF8
Definition: main.h:43
@ ENCODING_UTF16LE
Definition: main.h:41
@ ENCODING_ANSI
Definition: main.h:40

◆ EOLN

Enumerator
EOLN_CRLF 
EOLN_LF 
EOLN_CR 

Definition at line 50 of file main.h.

51{
52 EOLN_CRLF = 0, /* "\r\n" */
53 EOLN_LF = 1, /* "\n" */
54 EOLN_CR = 2 /* "\r" */
55} EOLN; /* End of line (NewLine) type */
EOLN
Definition: main.h:51
@ EOLN_LF
Definition: main.h:53
@ EOLN_CR
Definition: main.h:54
@ EOLN_CRLF
Definition: main.h:52

Function Documentation

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( VOID  )

◆ NOTEPAD_FindNext()

BOOL NOTEPAD_FindNext ( FINDREPLACE pFindReplace,
BOOL  bReplace,
BOOL  bShowAlert 
)

Definition at line 144 of file main.c.

145{
146 int iTextLength, iTargetLength;
147 size_t iAdjustment = 0;
148 LPTSTR pszText = NULL;
149 DWORD dwPosition, dwBegin, dwEnd;
150 BOOL bMatches = FALSE;
151 TCHAR szResource[128], szText[128];
153
154 iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
155
156 /* Retrieve the window text */
157 iTextLength = GetWindowTextLength(Globals.hEdit);
158 if (iTextLength > 0)
159 {
160 pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
161 if (!pszText)
162 return FALSE;
163
164 GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
165 }
166
167 SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
168 if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
169 {
170 if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
171 {
173 iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
174 }
175 }
176
177 if (pFindReplace->Flags & FR_DOWN)
178 {
179 /* Find Down */
180 dwPosition = dwEnd;
181 while(dwPosition < (DWORD) iTextLength)
182 {
183 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
184 if (bMatches)
185 break;
186 dwPosition++;
187 }
188 }
189 else
190 {
191 /* Find Up */
192 dwPosition = dwBegin;
193 while(dwPosition > 0)
194 {
195 dwPosition--;
196 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
197 if (bMatches)
198 break;
199 }
200 }
201
202 if (bMatches)
203 {
204 /* Found target */
205 if (dwPosition > dwBegin)
206 dwPosition += (DWORD) iAdjustment;
207 SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
209 bSuccess = TRUE;
210 }
211 else
212 {
213 /* Can't find target */
214 if (bShowAlert)
215 {
216 LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, ARRAY_SIZE(szResource));
217 _sntprintf(szText, ARRAY_SIZE(szText), szResource, pFindReplace->lpstrFindWhat);
218 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
219 MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
220 }
221 bSuccess = FALSE;
222 }
223
224 if (pszText)
225 HeapFree(GetProcessHeap(), 0, pszText);
226 return bSuccess;
227}
NOTEPAD_GLOBALS Globals
Definition: main.c:31
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
Definition: main.c:110
#define ARRAY_SIZE(a)
Definition: main.h:24
#define FR_DOWN
Definition: commdlg.h:127
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static BOOLEAN bSuccess
Definition: drive.cpp:433
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STRING_CANNOTFIND
Definition: notepad_res.h:89
#define STRING_NOTEPAD
Definition: notepad_res.h:75
#define DWORD
Definition: nt_native.h:44
#define EM_SCROLLCARET
Definition: richedit.h:81
LPSTR lpstrFindWhat
Definition: commdlg.h:307
LPSTR lpstrReplaceWith
Definition: commdlg.h:308
DWORD Flags
Definition: commdlg.h:306
HWND hEdit
Definition: main.h:62
HWND hFindReplaceDlg
Definition: main.h:61
HINSTANCE hInstance
Definition: main.h:59
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowTextLength
Definition: winuser.h:5789
#define EM_GETSEL
Definition: winuser.h:1987
#define EM_REPLACESEL
Definition: winuser.h:1996
#define SendMessage
Definition: winuser.h:5833
#define EM_SETSEL
Definition: winuser.h:2008
#define MB_OK
Definition: winuser.h:784
#define GetWindowText
Definition: winuser.h:5788
#define LoadString
Definition: winuser.h:5809
#define MessageBox
Definition: winuser.h:5812
char TCHAR
Definition: xmlstorage.h:189
#define _sntprintf
Definition: xmlstorage.h:201
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198

Referenced by DIALOG_SearchNext(), NOTEPAD_ReplaceAll(), and NOTEPAD_WndProc().

◆ NOTEPAD_LoadSettingsFromRegistry()

void NOTEPAD_LoadSettingsFromRegistry ( void  )

Definition at line 114 of file settings.c.

115{
116 HKEY hKey = NULL;
117 HFONT hFont;
118 DWORD dwPointSize = 0;
120
123
124 dx = (INT)(base_length * .95);
125 dy = dx * 3 / 4;
126 SetRect(&Globals.main_rect, 0, 0, dx, dy);
127
129 {
130 QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
131 QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
132 QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
133 QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, ARRAY_SIZE(Globals.lfFont.lfFaceName));
134 QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
135 QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
136 QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
137 QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
138 QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
139 QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
140 QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
141 QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
142 QueryDword(hKey, _T("iPointSize"), &dwPointSize);
143 QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
144 QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
145 QueryString(hKey, _T("szHeader"), Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
146 QueryString(hKey, _T("szTrailer"), Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
147 QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
148 QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
149 QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
150 QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
151
152 QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
153 QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
154 QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx);
155 QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy);
156
157 Globals.main_rect.right = Globals.main_rect.left + dx;
158 Globals.main_rect.bottom = Globals.main_rect.top + dy;
159
160 /* invert value because DIALOG_ViewStatusBar will be called to show it */
161 Globals.bShowStatusBar = !Globals.bShowStatusBar;
162
163 if (dwPointSize != 0)
164 Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
165 else
166 Globals.lfFont.lfHeight = HeightFromPointSize(100);
167
169 }
170 else
171 {
172 /* If no settings are found in the registry, then use default values */
173 Globals.bShowStatusBar = FALSE;
174 Globals.bWrapLongLines = FALSE;
175 SetRect(&Globals.lMargins, 750, 1000, 750, 1000);
176
177 /* FIXME: Globals.fSaveWindowPositions = FALSE; */
178 /* FIXME: Globals.fMLE_is_broken = FALSE; */
179
181 ARRAY_SIZE(Globals.szHeader));
183 ARRAY_SIZE(Globals.szFooter));
184
185 ZeroMemory(&Globals.lfFont, sizeof(Globals.lfFont));
186 Globals.lfFont.lfCharSet = DEFAULT_CHARSET;
187 Globals.lfFont.lfClipPrecision = CLIP_STROKE_PRECIS;
188 Globals.lfFont.lfEscapement = 0;
190 ARRAY_SIZE(Globals.lfFont.lfFaceName));
191 Globals.lfFont.lfItalic = FALSE;
192 Globals.lfFont.lfOrientation = 0;
193 Globals.lfFont.lfOutPrecision = OUT_STRING_PRECIS;
194
195 /* WORKAROUND: Far East Asian users may not have suitable fixed-pitch fonts. */
197 {
198 case LANG_CHINESE:
199 case LANG_JAPANESE:
200 case LANG_KOREAN:
201 Globals.lfFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
202 break;
203 default:
204 Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
205 break;
206 }
207
208 Globals.lfFont.lfQuality = PROOF_QUALITY;
209 Globals.lfFont.lfStrikeOut = FALSE;
210 Globals.lfFont.lfUnderline = FALSE;
211 Globals.lfFont.lfWeight = FW_NORMAL;
212 Globals.lfFont.lfHeight = HeightFromPointSize(100);
213 }
214
217 if (hFont)
218 {
219 if (Globals.hFont)
220 DeleteObject(Globals.hFont);
221 Globals.hFont = hFont;
222 }
223}
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
Definition: settings.c:83
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
Definition: settings.c:94
static LPCTSTR s_szRegistryKey
Definition: settings.c:27
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize)
Definition: settings.c:103
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:78
static LONG HeightFromPointSize(DWORD dwPointSize)
Definition: settings.c:30
HFONT hFont
Definition: main.c:53
#define RegCloseKey(hKey)
Definition: registry.h:47
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
FxAutoRegKey hKey
pKey DeleteObject()
LANGID WINAPI GetUserDefaultLangID(void)
Definition: lang.c:738
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define STRING_PAGESETUP_FOOTERVALUE
Definition: notepad_res.h:69
#define STRING_DEFAULTFONT
Definition: notepad_res.h:103
#define STRING_PAGESETUP_HEADERVALUE
Definition: notepad_res.h:68
#define INT
Definition: polytest.cpp:20
#define LANG_CHINESE
Definition: nls.h:42
#define LANG_JAPANESE
Definition: nls.h:76
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define LANG_KOREAN
Definition: nls.h:84
HINSTANCE hInstance
Definition: precomp.h:43
int base_length[LENGTH_CODES]
Definition: trees.c:107
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define ZeroMemory
Definition: winbase.h:1670
#define FIXED_PITCH
Definition: wingdi.h:444
#define DEFAULT_PITCH
Definition: wingdi.h:443
#define FF_MODERN
Definition: wingdi.h:449
#define FF_DONTCARE
Definition: wingdi.h:448
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define OUT_STRING_PRECIS
Definition: wingdi.h:416
#define PROOF_QUALITY
Definition: wingdi.h:438
#define FW_NORMAL
Definition: wingdi.h:373
#define CLIP_STROKE_PRECIS
Definition: wingdi.h:428
#define CreateFontIndirect
Definition: wingdi.h:4444
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKey
Definition: winreg.h:519
#define SM_CYSCREEN
Definition: winuser.h:954
#define WM_SETFONT
Definition: winuser.h:1640
#define SM_CXSCREEN
Definition: winuser.h:953
int WINAPI GetSystemMetrics(_In_ int)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by _tWinMain().

◆ NOTEPAD_SaveSettingsToRegistry()

void NOTEPAD_SaveSettingsToRegistry ( void  )

Definition at line 241 of file settings.c.

242{
243 HKEY hKey;
244 DWORD dwDisposition;
245
247
249 0, NULL, 0, KEY_SET_VALUE, NULL,
250 &hKey, &dwDisposition) == ERROR_SUCCESS)
251 {
252 SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet);
253 SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision);
254 SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement);
255 SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName);
256 SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic);
257 SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation);
258 SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision);
259 SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily);
260 SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality);
261 SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut);
262 SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline);
263 SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight);
264 SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
265 SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
266 SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
267 SaveString(hKey, _T("szHeader"), Globals.szHeader);
268 SaveString(hKey, _T("szTrailer"), Globals.szFooter);
269 SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
270 SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
271 SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
272 SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
273 SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
274 SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
275 SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);
276 SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top);
277
279 }
280}
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:42
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:230
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:225
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define RegCreateKeyEx
Definition: winreg.h:501
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)

Referenced by NOTEPAD_WndProc().

◆ ReadText()

BOOL ReadText ( HANDLE  hFile,
HLOCAL phLocal,
ENCODING pencFile,
EOLN piEoln 
)

Definition at line 166 of file text.c.

167{
168 PCHAR pBytes = NULL;
169 LPWSTR pszText, pszNewText = NULL;
170 DWORD dwSize, dwPos;
171 SIZE_T i, cchText, cbContent;
173 ENCODING encFile = ENCODING_ANSI;
174 UINT iCodePage;
175 HANDLE hMapping = INVALID_HANDLE_VALUE;
176 HLOCAL hNewLocal;
177
180 goto done;
181
182 hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
183 if (hMapping == NULL)
184 goto done;
185
186 pBytes = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, dwSize);
187 if (!pBytes)
188 goto done;
189
190 /* Look for Byte Order Marks */
191 dwPos = 0;
192 if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
193 {
194 encFile = ENCODING_UTF16LE;
195 dwPos += 2;
196 }
197 else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
198 {
199 encFile = ENCODING_UTF16BE;
200 dwPos += 2;
201 }
202 else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
203 {
204 encFile = ENCODING_UTF8BOM;
205 dwPos += 3;
206 }
207 else
208 {
209 encFile = AnalyzeEncoding((const char *)pBytes, dwSize);
210 }
211
212 switch(encFile)
213 {
214 case ENCODING_UTF16BE:
215 case ENCODING_UTF16LE:
216 {
217 /* Re-allocate the buffer for EM_SETHANDLE */
218 pszText = (LPWSTR) &pBytes[dwPos];
219 cchText = (dwSize - dwPos) / sizeof(WCHAR);
220 hNewLocal = LocalReAlloc(*phLocal, (cchText + 1) * sizeof(WCHAR), LMEM_MOVEABLE);
221 pszNewText = LocalLock(hNewLocal);
222 if (pszNewText == NULL)
223 goto done;
224
225 *phLocal = hNewLocal;
226 CopyMemory(pszNewText, pszText, cchText * sizeof(WCHAR));
227
228 if (encFile == ENCODING_UTF16BE) /* big endian; Swap bytes */
229 {
230 BYTE tmp, *pb = (LPBYTE)pszNewText;
231 for (i = 0; i < cchText * 2; i += 2)
232 {
233 tmp = pb[i];
234 pb[i] = pb[i + 1];
235 pb[i + 1] = tmp;
236 }
237 }
238 break;
239 }
240
241 case ENCODING_ANSI:
242 case ENCODING_UTF8:
243 case ENCODING_UTF8BOM:
244 {
245 iCodePage = ((encFile == ENCODING_UTF8 || encFile == ENCODING_UTF8BOM) ? CP_UTF8 : CP_ACP);
246
247 /* Get ready for ANSI-to-Wide conversion */
248 cbContent = dwSize - dwPos;
249 cchText = 0;
250 if (cbContent > 0)
251 {
252 cchText = MultiByteToWideChar(iCodePage, 0, &pBytes[dwPos], (INT)cbContent, NULL, 0);
253 if (cchText == 0)
254 goto done;
255 }
256
257 /* Re-allocate the buffer for EM_SETHANDLE */
258 hNewLocal = LocalReAlloc(*phLocal, (cchText + 1) * sizeof(WCHAR), LMEM_MOVEABLE);
259 pszNewText = LocalLock(hNewLocal);
260 if (!pszNewText)
261 goto done;
262 *phLocal = hNewLocal;
263
264 /* Do ANSI-to-Wide conversion */
265 if (cbContent > 0)
266 {
267 if (!MultiByteToWideChar(iCodePage, 0,
268 &pBytes[dwPos], (INT)cbContent, pszNewText, (INT)cchText))
269 {
270 goto done;
271 }
272 }
273 break;
274 }
275
277 }
278
279 pszNewText[cchText] = UNICODE_NULL;
280
281 if (!ProcessNewLinesAndNulls(phLocal, &pszNewText, &cchText, piEoln))
282 goto done;
283
284 *pencFile = encFile;
285 bSuccess = TRUE;
286
287done:
288 if (pBytes)
289 UnmapViewOfFile(pBytes);
290 if (hMapping != INVALID_HANDLE_VALUE)
291 CloseHandle(hMapping);
292 if (pszNewText)
293 LocalUnlock(*phLocal);
294 return bSuccess;
295}
ENCODING AnalyzeEncoding(const char *pBytes, DWORD dwSize)
Definition: text.c:40
static BOOL ProcessNewLinesAndNulls(HLOCAL *phLocal, LPWSTR *ppszText, SIZE_T *pcchText, EOLN *piEoln)
Definition: text.c:96
#define CloseHandle
Definition: compat.h:739
#define PAGE_READONLY
Definition: compat.h:138
#define UnmapViewOfFile
Definition: compat.h:746
#define CP_ACP
Definition: compat.h:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define FILE_MAP_READ
Definition: compat.h:776
#define MapViewOfFile
Definition: compat.h:745
#define MultiByteToWideChar
Definition: compat.h:110
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalReAlloc(HLOCAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:1608
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1599
BOOL NTAPI LocalUnlock(HLOCAL hMem)
Definition: heapmem.c:1788
signed char * PCHAR
Definition: retypes.h:7
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
ENCODING
Definition: more.c:492
@ ENCODING_UTF16BE
Definition: more.c:495
@ ENCODING_UTF8
Definition: more.c:496
@ ENCODING_UTF16LE
Definition: more.c:494
@ ENCODING_ANSI
Definition: more.c:493
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define DEFAULT_UNREACHABLE
#define UNICODE_NULL
#define CP_UTF8
Definition: nls.h:20
unsigned char * LPBYTE
Definition: typedefs.h:53
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define LMEM_MOVEABLE
Definition: winbase.h:369
#define CopyMemory
Definition: winbase.h:1668
#define INVALID_FILE_SIZE
Definition: winbase.h:548
_In_ int cchText
Definition: winuser.h:4455
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DoOpenFile().

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 48 of file main.c.

49{
51 Globals.szFileTitle[0] = 0;
53
54 if (szFileName && szFileName[0])
55 SHAddToRecentDocs(SHARD_PATHW, szFileName);
56}
#define GetFileTitle
Definition: commdlg.h:664
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:809
#define SHARD_PATHW
Definition: shlobj.h:1103
#define StringCchCopy
Definition: strsafe.h:139
TCHAR szFileName[MAX_PATH]
Definition: main.h:73
TCHAR szFileTitle[MAX_PATH]
Definition: main.h:74

◆ WriteText()

BOOL WriteText ( HANDLE  hFile,
LPCWSTR  pszText,
DWORD  dwTextLen,
ENCODING  encFile,
EOLN  iEoln 
)

Definition at line 392 of file text.c.

393{
394 WCHAR wcBom;
395 LPCWSTR pszLF = L"\n";
396 DWORD dwPos, dwNext;
397
398 /* Write the proper byte order marks if not ANSI or UTF-8 without BOM */
399 if (encFile != ENCODING_ANSI && encFile != ENCODING_UTF8)
400 {
401 wcBom = 0xFEFF;
402 if (!WriteEncodedText(hFile, &wcBom, 1, encFile))
403 return FALSE;
404 }
405
406 dwPos = 0;
407
408 /* pszText eoln are always \r\n */
409
410 do
411 {
412 /* Find the next eoln */
413 dwNext = dwPos;
414 while(dwNext < dwTextLen)
415 {
416 if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n')
417 break;
418 dwNext++;
419 }
420
421 if (dwNext != dwTextLen)
422 {
423 switch (iEoln)
424 {
425 case EOLN_LF:
426 /* Write text (without eoln) */
427 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
428 return FALSE;
429 /* Write eoln */
430 if (!WriteEncodedText(hFile, pszLF, 1, encFile))
431 return FALSE;
432 break;
433 case EOLN_CR:
434 /* Write text (including \r as eoln) */
435 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1, encFile))
436 return FALSE;
437 break;
438 case EOLN_CRLF:
439 /* Write text (including \r\n as eoln) */
440 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2, encFile))
441 return FALSE;
442 break;
443 default:
444 return FALSE;
445 }
446 }
447 else
448 {
449 /* Write text (without eoln, since this is the end of the file) */
450 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
451 return FALSE;
452 }
453
454 /* Skip \r\n */
455 dwPos = dwNext + 2;
456 }
457 while (dwPos < dwTextLen);
458
459 return TRUE;
460}
static BOOL WriteEncodedText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile)
Definition: text.c:297
#define L(x)
Definition: ntvdm.h:50
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by DoSaveFile().

Variable Documentation

◆ Globals

NOTEPAD_GLOBALS Globals
extern

Definition at line 13 of file clipbrd.c.