ReactOS 0.4.17-dev-116-ga4b6fe9
notepad.h File Reference
#include <windef.h>
#include <winbase.h>
#include <winuser.h>
#include <winnls.h>
#include <wingdi.h>
#include <shellapi.h>
#include <commdlg.h>
#include <tchar.h>
#include <stdlib.h>
#include <malloc.h>
#include "dialog.h"
#include "notepad_res.h"
Include dependency graph for notepad.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 STRSAFE_NO_DEPRECATE
 
#define EDIT_STYLE_WRAP   (WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL)
 
#define EDIT_STYLE   (EDIT_STYLE_WRAP | WS_HSCROLL | ES_AUTOHSCROLL)
 
#define EDIT_CLASS   _T("EDIT")
 
#define MAX_STRING_LEN   255
 
#define ENCODING_DEFAULT   ENCODING_UTF8
 

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

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

Variables

NOTEPAD_GLOBALS Globals
 

Macro Definition Documentation

◆ EDIT_CLASS

#define EDIT_CLASS   _T("EDIT")

Definition at line 34 of file notepad.h.

◆ EDIT_STYLE

Definition at line 33 of file notepad.h.

◆ EDIT_STYLE_WRAP

Definition at line 32 of file notepad.h.

◆ ENCODING_DEFAULT

#define ENCODING_DEFAULT   ENCODING_UTF8

Definition at line 49 of file notepad.h.

◆ MAX_STRING_LEN

#define MAX_STRING_LEN   255

Definition at line 36 of file notepad.h.

◆ STRSAFE_NO_DEPRECATE

#define STRSAFE_NO_DEPRECATE

Definition at line 15 of file notepad.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 39 of file notepad.h.

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

◆ EOLN

Enumerator
EOLN_CRLF 
EOLN_LF 
EOLN_CR 

Definition at line 51 of file notepad.h.

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

Function Documentation

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( VOID  )

◆ NOTEPAD_FindNext()

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

Definition at line 132 of file main.c.

133{
134 int iTextLength, iTargetLength;
135 size_t iAdjustment = 0;
136 LPTSTR pszText = NULL;
137 DWORD dwPosition, dwBegin, dwEnd;
138 BOOL bMatches = FALSE;
139 TCHAR szResource[128], szText[128];
140 BOOL bSuccess;
141
142 iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
143
144 /* Retrieve the window text */
145 iTextLength = GetWindowTextLength(Globals.hEdit);
146 if (iTextLength > 0)
147 {
148 pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
149 if (!pszText)
150 return FALSE;
151
152 GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
153 }
154
155 SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
156 if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
157 {
158 if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
159 {
161 iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
162 }
163 }
164
165 if (pFindReplace->Flags & FR_DOWN)
166 {
167 /* Find Down */
168 dwPosition = dwEnd;
169 while(dwPosition < (DWORD) iTextLength)
170 {
171 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
172 if (bMatches)
173 break;
174 dwPosition++;
175 }
176 }
177 else
178 {
179 /* Find Up */
180 dwPosition = dwBegin;
181 while(dwPosition > 0)
182 {
183 dwPosition--;
184 bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
185 if (bMatches)
186 break;
187 }
188 }
189
190 if (bMatches)
191 {
192 /* Found target */
193 if (dwPosition > dwBegin)
194 dwPosition += (DWORD) iAdjustment;
195 SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
197 bSuccess = TRUE;
198 }
199 else
200 {
201 /* Can't find target */
202 if (bShowAlert)
203 {
204 LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, _countof(szResource));
205 StringCchPrintf(szText, _countof(szText), szResource, pFindReplace->lpstrFindWhat);
206 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, _countof(szResource));
207 MessageBox(Globals.hFindReplaceDlg, szText, szResource, MB_OK);
208 }
209 bSuccess = FALSE;
210 }
211
212 if (pszText)
213 HeapFree(GetProcessHeap(), 0, pszText);
214 return bSuccess;
215}
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, INT iTextLength, DWORD dwPosition)
Definition: main.c:94
NOTEPAD_GLOBALS Globals
Definition: main.c:17
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
char TCHAR
Definition: tchar.h:1402
#define _tcslen
Definition: tchar.h:626
LONG_PTR LPARAM
Definition: minwindef.h:175
UINT_PTR WPARAM
Definition: minwindef.h:174
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
#define STRING_CANNOTFIND
Definition: notepad_res.h:77
#define STRING_NOTEPAD
Definition: notepad_res.h:63
#define DWORD
Definition: nt_native.h:44
#define EM_SCROLLCARET
Definition: richedit.h:81
#define _countof(array)
Definition: sndvol32.h:70
#define StringCchPrintf
Definition: strsafe.h:517
LPSTR lpstrFindWhat
Definition: commdlg.h:307
LPSTR lpstrReplaceWith
Definition: commdlg.h:308
DWORD Flags
Definition: commdlg.h:306
HWND hFindReplaceDlg
Definition: notepad.h:62
HINSTANCE hInstance
Definition: notepad.h:60
#define GetWindowTextLength
Definition: winuser.h:5965
#define EM_GETSEL
Definition: winuser.h:2026
#define EM_REPLACESEL
Definition: winuser.h:2035
#define SendMessage
Definition: winuser.h:6009
#define EM_SETSEL
Definition: winuser.h:2047
#define MB_OK
Definition: winuser.h:801
#define GetWindowText
Definition: winuser.h:5964
#define LoadString
Definition: winuser.h:5985
#define MessageBox
Definition: winuser.h:5988

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

◆ NOTEPAD_LoadSettingsFromRegistry()

void NOTEPAD_LoadSettingsFromRegistry ( PWINDOWPLACEMENT  pWP)

Definition at line 105 of file settings.c.

106{
107 HKEY hKey;
108 HFONT hFont;
109 DWORD dwPointSize;
110 DWORD x = CW_USEDEFAULT, y = CW_USEDEFAULT, cx = 0, cy = 0;
111
112 /* Set the default values */
113 Globals.bShowStatusBar = TRUE;
114 Globals.bWrapLongLines = FALSE;
115 SetRect(&Globals.lMargins, 750, 1000, 750, 1000);
116 ZeroMemory(&Globals.lfFont, sizeof(Globals.lfFont));
117 Globals.lfFont.lfCharSet = DEFAULT_CHARSET;
118 dwPointSize = 100;
119 Globals.lfFont.lfWeight = FW_NORMAL;
120 Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
121
122 /* FIXME: Globals.fSaveWindowPositions = FALSE; */
123 /* FIXME: Globals.fMLE_is_broken = FALSE; */
124
125 /* Open the target registry key */
127 hKey = NULL;
128
129 /* Load the values from registry */
130 if (hKey)
131 {
132 QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
133 QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
134 QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
135 QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
136 QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
137 QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
138 QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
139 QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
140 QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
141 QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
142 QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
143 QueryDword(hKey, _T("iPointSize"), &dwPointSize);
144
145 QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
146 QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
147
148 QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
149 QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
150 QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
151 QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
152
153 QueryDword(hKey, _T("iWindowPosX"), &x);
154 QueryDword(hKey, _T("iWindowPosY"), &y);
155 QueryDword(hKey, _T("iWindowPosDX"), &cx);
156 QueryDword(hKey, _T("iWindowPosDY"), &cy);
157
158 QueryString(hKey, _T("searchString"), Globals.szFindText, _countof(Globals.szFindText));
159 QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
160 }
161
162 pWP->length = sizeof(*pWP);
163 pWP->flags = 0;
164 pWP->showCmd = SW_SHOWDEFAULT;
165 if (cy & 0x80000000)
166 {
167 cy &= ~0x80000000;
170 }
171 pWP->rcNormalPosition.left = x;
172 pWP->rcNormalPosition.right = x + cx;
173 pWP->rcNormalPosition.top = y;
174 pWP->rcNormalPosition.bottom = y + cy;
175 pWP->ptMaxPosition.x = x;
176 pWP->ptMaxPosition.y = y;
177
178 Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
179 if (!hKey || !QueryString(hKey, _T("lfFaceName"),
180 Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
181 {
183 _countof(Globals.lfFont.lfFaceName));
184 }
185
186 if (!hKey || !QueryString(hKey, _T("szHeader"), Globals.szHeader, _countof(Globals.szHeader)))
187 {
189 _countof(Globals.szHeader));
190 }
191
192 if (!hKey || !QueryString(hKey, _T("szTrailer"), Globals.szFooter, _countof(Globals.szFooter)))
193 {
195 _countof(Globals.szFooter));
196 }
197
198 if (hKey)
200
201 /* WORKAROUND: Far East Asian users may not have suitable fixed-pitch fonts. */
203 {
204 case LANG_CHINESE:
205 case LANG_JAPANESE:
206 case LANG_KOREAN:
207 Globals.lfFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
208 break;
209 }
210
213 if (hFont)
214 {
215 if (Globals.hFont)
216 DeleteObject(Globals.hFont);
217 Globals.hFont = hFont;
218 }
219}
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
Definition: settings.c:70
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
Definition: settings.c:81
static LPCTSTR s_szRegistryKey
Definition: settings.c:14
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultLength)
Definition: settings.c:90
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:65
static LONG HeightFromPointSize(DWORD dwPointSize)
Definition: settings.c:17
HFONT hFont
Definition: main.c:53
#define RegCloseKey(hKey)
Definition: registry.h:49
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
LANGID WINAPI GetUserDefaultLangID(void)
Definition: locale.c:1182
FxAutoRegKey hKey
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define ZeroMemory
Definition: minwinbase.h:31
#define STRING_PAGESETUP_FOOTERVALUE
Definition: notepad_res.h:61
#define STRING_DEFAULTFONT
Definition: notepad_res.h:91
#define STRING_PAGESETUP_HEADERVALUE
Definition: notepad_res.h:60
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#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
POINT ptMaxPosition
Definition: winuser.h:3402
RECT rcNormalPosition
Definition: winuser.h:3403
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:108
LONG bottom
Definition: windef.h:109
LONG top
Definition: windef.h:107
LONG left
Definition: windef.h:106
#define _T(x)
Definition: vfdio.h:22
#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 FW_NORMAL
Definition: wingdi.h:373
#define CreateFontIndirect
Definition: wingdi.h:4890
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKey
Definition: winreg.h:551
#define SW_SHOWMAXIMIZED
Definition: winuser.h:784
#define SW_SHOWDEFAULT
Definition: winuser.h:791
#define WM_SETFONT
Definition: winuser.h:1678
#define CW_USEDEFAULT
Definition: winuser.h:225
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2568
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 236 of file settings.c.

237{
238 HKEY hKey;
239 DWORD dwDisposition;
241 UINT x, y, cx, cy;
242
243 wp.length = sizeof(wp);
247 cx = wp.rcNormalPosition.right - x;
250 cy |= 0x80000000;
251
252
254 0, NULL, 0, KEY_SET_VALUE, NULL,
255 &hKey, &dwDisposition) == ERROR_SUCCESS)
256 {
257 SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet);
258 SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision);
259 SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement);
260 SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName);
261 SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic);
262 SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation);
263 SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision);
264 SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily);
265 SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality);
266 SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut);
267 SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline);
268 SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight);
269 SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
270 SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
271 SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
272 SaveString(hKey, _T("szHeader"), Globals.szHeader);
273 SaveString(hKey, _T("szTrailer"), Globals.szFooter);
274 SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
275 SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
276 SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
277 SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
278 SaveDword(hKey, _T("iWindowPosX"), x);
279 SaveDword(hKey, _T("iWindowPosY"), y);
280 SaveDword(hKey, _T("iWindowPosDX"), cx);
281 SaveDword(hKey, _T("iWindowPosDY"), cy);
282 SaveString(hKey, _T("searchString"), Globals.szFindText);
283 SaveString(hKey, _T("replaceString"), Globals.szReplaceText);
284
286 }
287}
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:29
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:226
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:221
unsigned int UINT
Definition: ndis.h:50
#define KEY_SET_VALUE
Definition: nt_native.h:1020
#define RegCreateKeyEx
Definition: winreg.h:532
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)

Referenced by NOTEPAD_WndProc().

◆ ReadText()

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

Definition at line 161 of file text.c.

162{
163 LPBYTE pBytes = NULL;
164 LPWSTR pszText, pszNewText = NULL;
165 DWORD dwSize, dwPos;
166 SIZE_T i, cchText, cbContent;
167 BOOL bSuccess = FALSE;
168 ENCODING encFile;
169 UINT iCodePage;
170 HANDLE hMapping = INVALID_HANDLE_VALUE;
171 HLOCAL hNewLocal = NULL;
172
175 goto done;
176
177 if (dwSize == 0) // If file is empty
178 {
179 hNewLocal = LocalAlloc(LMEM_MOVEABLE, sizeof(UNICODE_NULL));
180 if (!hNewLocal)
181 {
183 goto done;
184 }
185
186 pszNewText = LocalLock(hNewLocal);
187 if (!pszNewText)
188 {
190 goto done;
191 }
192
193 *pszNewText = UNICODE_NULL;
194 LocalUnlock(hNewLocal);
195
196 *piEoln = EOLN_CRLF;
197 *pencFile = ENCODING_DEFAULT;
198 return hNewLocal;
199 }
200
201 hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
202 if (hMapping == NULL)
203 goto done;
204
205 pBytes = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, dwSize);
206 if (!pBytes)
207 goto done;
208
209 /* Look for Byte Order Marks */
210 dwPos = 0;
211 if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
212 {
213 encFile = ENCODING_UTF16LE;
214 dwPos += 2;
215 }
216 else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
217 {
218 encFile = ENCODING_UTF16BE;
219 dwPos += 2;
220 }
221 else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
222 {
223 encFile = ENCODING_UTF8BOM;
224 dwPos += 3;
225 }
226 else
227 {
228 encFile = AnalyzeEncoding(pBytes, dwSize);
229 }
230
231 switch(encFile)
232 {
233 case ENCODING_UTF16BE:
234 case ENCODING_UTF16LE:
235 {
236 /* Allocate the buffer for EM_SETHANDLE */
237 pszText = (LPWSTR)&pBytes[dwPos];
238 cchText = (dwSize - dwPos) / sizeof(WCHAR);
239 if (cchText >= MAXLONG / sizeof(WCHAR))
240 {
242 goto done;
243 }
244
245 hNewLocal = LocalAlloc(LMEM_MOVEABLE, (cchText + 1) * sizeof(WCHAR));
246 if (!hNewLocal)
247 {
249 goto done;
250 }
251
252 pszNewText = LocalLock(hNewLocal);
253 if (!pszNewText)
254 {
256 goto done;
257 }
258
259 CopyMemory(pszNewText, pszText, cchText * sizeof(WCHAR));
260
261 if (encFile == ENCODING_UTF16BE) /* big endian; Swap bytes */
262 {
263 BYTE tmp, *pb = (LPBYTE)pszNewText;
264 for (i = 0; i < cchText * 2; i += 2)
265 {
266 tmp = pb[i];
267 pb[i] = pb[i + 1];
268 pb[i + 1] = tmp;
269 }
270 }
271 break;
272 }
273
274 case ENCODING_ANSI:
275 case ENCODING_UTF8:
276 case ENCODING_UTF8BOM:
277 {
278 iCodePage = ((encFile == ENCODING_UTF8 || encFile == ENCODING_UTF8BOM)
279 ? CP_UTF8 : CP_ACP);
280 cbContent = dwSize - dwPos;
281 if (cbContent >= MAXLONG / sizeof(WCHAR))
282 {
284 goto done;
285 }
286
287 /* Allocate the buffer for EM_SETHANDLE */
288 hNewLocal = LocalAlloc(LMEM_MOVEABLE, (cbContent + 1) * sizeof(WCHAR));
289 if (!hNewLocal)
290 {
292 goto done;
293 }
294
295 pszNewText = LocalLock(hNewLocal);
296 if (!pszNewText)
297 {
299 goto done;
300 }
301
302 /* Do conversion */
303 cchText = 0;
304 if (cbContent > 0)
305 {
306 cchText = MultiByteToWideChar(iCodePage, 0,
307 (LPCSTR)&pBytes[dwPos], (INT)cbContent,
308 pszNewText, (INT)cbContent);
309 if (!cchText)
310 goto done;
311 }
312 break;
313 }
314
316 }
317
318 pszNewText[cchText] = UNICODE_NULL;
319
320 if (!ProcessNewLinesAndNulls(&hNewLocal, &pszNewText, &cchText, piEoln))
321 goto done;
322
323 *pencFile = encFile;
324 bSuccess = TRUE;
325
326done:
327 if (pBytes)
328 UnmapViewOfFile(pBytes);
329 if (hMapping != INVALID_HANDLE_VALUE)
330 CloseHandle(hMapping);
331 if (pszNewText)
332 LocalUnlock(hNewLocal);
333 if (!bSuccess && hNewLocal)
334 {
335 LocalFree(hNewLocal);
336 hNewLocal = NULL;
337 }
338 return hNewLocal;
339}
static BOOL ProcessNewLinesAndNulls(HLOCAL *phLocal, LPWSTR *ppszText, SIZE_T *pcchText, EOLN *piEoln)
Definition: text.c:83
static ENCODING AnalyzeEncoding(const BYTE *pBytes, DWORD dwSize)
Definition: text.c:27
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#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 SetLastError(x)
Definition: compat.h:752
#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 LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1616
BOOL NTAPI LocalUnlock(HLOCAL hMem)
Definition: heapmem.c:1805
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define LMEM_MOVEABLE
Definition: minwinbase.h:82
#define CopyMemory
Definition: minwinbase.h:29
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
#define ENCODING_DEFAULT
Definition: notepad.h:49
#define DEFAULT_UNREACHABLE
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
#define CP_UTF8
Definition: nls.h:20
const char * LPCSTR
Definition: typedefs.h:52
unsigned char * LPBYTE
Definition: typedefs.h:53
uint16_t * LPWSTR
Definition: typedefs.h:56
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define MAXLONG
Definition: umtypes.h:116
#define INVALID_FILE_SIZE
Definition: winbase.h:528
#define ERROR_FILE_TOO_LARGE
Definition: winerror.h:399
_In_ int cchText
Definition: winuser.h:4619
unsigned char BYTE
Definition: xxhash.c:193

Referenced by DoOpenFile().

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 34 of file main.c.

35{
37 Globals.szFileTitle[0] = 0;
39
40 if (szFileName && szFileName[0])
41 SHAddToRecentDocs(SHARD_PATHW, szFileName);
42}
#define GetFileTitle
Definition: commdlg.h:664
void WINAPI SHAddToRecentDocs(UINT uFlags, LPCVOID pv)
Definition: shellord.c:1011
#define SHARD_PATHW
Definition: shlobj.h:1183
#define StringCchCopy
Definition: strsafe.h:139
TCHAR szFileName[MAX_PATH]
Definition: notepad.h:74
TCHAR szFileTitle[MAX_PATH]
Definition: notepad.h:75

◆ WriteText()

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

Definition at line 436 of file text.c.

437{
438 WCHAR wcBom;
439 LPCWSTR pszLF = L"\n";
440 DWORD dwPos, dwNext;
441
442 /* Write the proper byte order marks if not ANSI or UTF-8 without BOM */
443 if (encFile != ENCODING_ANSI && encFile != ENCODING_UTF8)
444 {
445 wcBom = 0xFEFF;
446 if (!WriteEncodedText(hFile, &wcBom, 1, encFile))
447 return FALSE;
448 }
449
450 dwPos = 0;
451
452 /* pszText eoln are always \r\n */
453
454 do
455 {
456 /* Find the next eoln */
457 dwNext = dwPos;
458 while(dwNext < dwTextLen)
459 {
460 if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n')
461 break;
462 dwNext++;
463 }
464
465 if (dwNext != dwTextLen)
466 {
467 switch (iEoln)
468 {
469 case EOLN_LF:
470 /* Write text (without eoln) */
471 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
472 return FALSE;
473 /* Write eoln */
474 if (!WriteEncodedText(hFile, pszLF, 1, encFile))
475 return FALSE;
476 break;
477 case EOLN_CR:
478 /* Write text (including \r as eoln) */
479 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1, encFile))
480 return FALSE;
481 break;
482 case EOLN_CRLF:
483 /* Write text (including \r\n as eoln) */
484 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2, encFile))
485 return FALSE;
486 break;
487 default:
488 return FALSE;
489 }
490 }
491 else
492 {
493 /* Write text (without eoln, since this is the end of the file) */
494 if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
495 return FALSE;
496 }
497
498 /* Skip \r\n */
499 dwPos = dwNext + 2;
500 }
501 while (dwPos < dwTextLen);
502
503 return TRUE;
504}
static BOOL WriteEncodedText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile)
Definition: text.c:341
#define L(x)
Definition: resources.c:13
const uint16_t * LPCWSTR
Definition: typedefs.h:57

Referenced by DoSaveFile().

Variable Documentation

◆ Globals

NOTEPAD_GLOBALS Globals
extern

Definition at line 13 of file clipbrd.c.