ReactOS 0.4.15-dev-7942-gd23573b
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

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 *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];
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
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: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:68
#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
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowTextLength
Definition: winuser.h:5799
#define EM_GETSEL
Definition: winuser.h:1997
#define EM_REPLACESEL
Definition: winuser.h:2006
#define SendMessage
Definition: winuser.h:5843
#define EM_SETSEL
Definition: winuser.h:2018
#define MB_OK
Definition: winuser.h:790
#define GetWindowText
Definition: winuser.h:5798
#define LoadString
Definition: winuser.h:5819
#define MessageBox
Definition: winuser.h:5822
char TCHAR
Definition: xmlstorage.h:189
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 105 of file settings.c.

106{
107 HKEY hKey;
108 HFONT hFont;
109 DWORD dwPointSize, cx, cy;
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 Globals.main_rect.left = CW_USEDEFAULT;
122 Globals.main_rect.top = CW_USEDEFAULT;
123 cx = min((cxScreen * 3) / 4, 640);
124 cy = min((cyScreen * 3) / 4, 480);
125
126 /* FIXME: Globals.fSaveWindowPositions = FALSE; */
127 /* FIXME: Globals.fMLE_is_broken = FALSE; */
128
129 /* Open the target registry key */
131 hKey = NULL;
132
133 /* Load the values from registry */
134 if (hKey)
135 {
136 QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
137 QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
138 QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
139 QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
140 QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
141 QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
142 QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
143 QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
144 QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
145 QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
146 QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
147 QueryDword(hKey, _T("iPointSize"), &dwPointSize);
148
149 QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
150 QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
151
152 QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
153 QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
154 QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
155 QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
156
157 QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
158 QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
159 QueryDword(hKey, _T("iWindowPosDX"), &cx);
160 QueryDword(hKey, _T("iWindowPosDY"), &cy);
161
162 QueryString(hKey, _T("searchString"), Globals.szFindText, _countof(Globals.szFindText));
163 QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
164 }
165
166 Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
167 Globals.main_rect.right = Globals.main_rect.left + cx;
168 Globals.main_rect.bottom = Globals.main_rect.top + cy;
169
170 if (!hKey || !QueryString(hKey, _T("lfFaceName"),
171 Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
172 {
174 _countof(Globals.lfFont.lfFaceName));
175 }
176
177 if (!hKey || !QueryString(hKey, _T("szHeader"), Globals.szHeader, _countof(Globals.szHeader)))
178 {
180 _countof(Globals.szHeader));
181 }
182
183 if (!hKey || !QueryString(hKey, _T("szTrailer"), Globals.szFooter, _countof(Globals.szFooter)))
184 {
186 _countof(Globals.szFooter));
187 }
188
189 if (hKey)
191
192 /* WORKAROUND: Far East Asian users may not have suitable fixed-pitch fonts. */
194 {
195 case LANG_CHINESE:
196 case LANG_JAPANESE:
197 case LANG_KOREAN:
198 Globals.lfFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
199 break;
200 }
201
204 if (hFont)
205 {
206 if (Globals.hFont)
207 DeleteObject(Globals.hFont);
208 Globals.hFont = hFont;
209 }
210}
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
FxAutoRegKey hKey
pKey DeleteObject()
LANGID WINAPI GetUserDefaultLangID(void)
Definition: lang.c:744
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define min(a, b)
Definition: monoChain.cc:55
#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
#define _T(x)
Definition: vfdio.h:22
#define ZeroMemory
Definition: winbase.h:1712
#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:4444
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKey
Definition: winreg.h:519
#define SM_CYSCREEN
Definition: winuser.h:960
#define WM_SETFONT
Definition: winuser.h:1650
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SM_CXSCREEN
Definition: winuser.h:959
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 227 of file settings.c.

228{
229 HKEY hKey;
230 DWORD dwDisposition;
231
233
235 0, NULL, 0, KEY_SET_VALUE, NULL,
236 &hKey, &dwDisposition) == ERROR_SUCCESS)
237 {
238 SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet);
239 SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision);
240 SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement);
241 SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName);
242 SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic);
243 SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation);
244 SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision);
245 SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily);
246 SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality);
247 SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut);
248 SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline);
249 SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight);
250 SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
251 SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
252 SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
253 SaveString(hKey, _T("szHeader"), Globals.szHeader);
254 SaveString(hKey, _T("szTrailer"), Globals.szFooter);
255 SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
256 SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
257 SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
258 SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
259 SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
260 SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
261 SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);
262 SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top);
263 SaveString(hKey, _T("searchString"), Globals.szFindText);
264 SaveString(hKey, _T("replaceString"), Globals.szReplaceText);
265
267 }
268}
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:29
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:217
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:212
#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 153 of file text.c.

154{
155 LPBYTE pBytes = NULL;
156 LPWSTR pszText, pszNewText = NULL;
157 DWORD dwSize, dwPos;
158 SIZE_T i, cchText, cbContent;
160 ENCODING encFile;
161 UINT iCodePage;
162 HANDLE hMapping = INVALID_HANDLE_VALUE;
163 HLOCAL hNewLocal;
164
167 goto done;
168
169 if (dwSize == 0) // If file is empty
170 {
171 hNewLocal = LocalReAlloc(*phLocal, sizeof(UNICODE_NULL), LMEM_MOVEABLE);
172 pszNewText = LocalLock(hNewLocal);
173 if (hNewLocal == NULL || pszNewText == NULL)
174 goto done;
175
176 *pszNewText = UNICODE_NULL;
177 LocalUnlock(hNewLocal);
178
179 *phLocal = hNewLocal;
180 *piEoln = EOLN_CRLF;
181 *pencFile = ENCODING_DEFAULT;
182 return TRUE;
183 }
184
185 hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
186 if (hMapping == NULL)
187 goto done;
188
189 pBytes = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, dwSize);
190 if (!pBytes)
191 goto done;
192
193 /* Look for Byte Order Marks */
194 dwPos = 0;
195 if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
196 {
197 encFile = ENCODING_UTF16LE;
198 dwPos += 2;
199 }
200 else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
201 {
202 encFile = ENCODING_UTF16BE;
203 dwPos += 2;
204 }
205 else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
206 {
207 encFile = ENCODING_UTF8BOM;
208 dwPos += 3;
209 }
210 else
211 {
212 encFile = AnalyzeEncoding(pBytes, dwSize);
213 }
214
215 switch(encFile)
216 {
217 case ENCODING_UTF16BE:
218 case ENCODING_UTF16LE:
219 {
220 /* Re-allocate the buffer for EM_SETHANDLE */
221 pszText = (LPWSTR) &pBytes[dwPos];
222 cchText = (dwSize - dwPos) / sizeof(WCHAR);
223 hNewLocal = LocalReAlloc(*phLocal, (cchText + 1) * sizeof(WCHAR), LMEM_MOVEABLE);
224 pszNewText = LocalLock(hNewLocal);
225 if (pszNewText == NULL)
226 goto done;
227
228 *phLocal = hNewLocal;
229 CopyMemory(pszNewText, pszText, cchText * sizeof(WCHAR));
230
231 if (encFile == ENCODING_UTF16BE) /* big endian; Swap bytes */
232 {
233 BYTE tmp, *pb = (LPBYTE)pszNewText;
234 for (i = 0; i < cchText * 2; i += 2)
235 {
236 tmp = pb[i];
237 pb[i] = pb[i + 1];
238 pb[i + 1] = tmp;
239 }
240 }
241 break;
242 }
243
244 case ENCODING_ANSI:
245 case ENCODING_UTF8:
246 case ENCODING_UTF8BOM:
247 {
248 iCodePage = ((encFile == ENCODING_UTF8 || encFile == ENCODING_UTF8BOM) ? CP_UTF8 : CP_ACP);
249
250 /* Get ready for ANSI-to-Wide conversion */
251 cbContent = dwSize - dwPos;
252 cchText = 0;
253 if (cbContent > 0)
254 {
255 cchText = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], (INT)cbContent, NULL, 0);
256 if (cchText == 0)
257 goto done;
258 }
259
260 /* Re-allocate the buffer for EM_SETHANDLE */
261 hNewLocal = LocalReAlloc(*phLocal, (cchText + 1) * sizeof(WCHAR), LMEM_MOVEABLE);
262 pszNewText = LocalLock(hNewLocal);
263 if (!pszNewText)
264 goto done;
265 *phLocal = hNewLocal;
266
267 /* Do ANSI-to-Wide conversion */
268 if (cbContent > 0)
269 {
270 if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], (INT)cbContent,
271 pszNewText, (INT)cchText))
272 {
273 goto done;
274 }
275 }
276 break;
277 }
278
280 }
281
282 pszNewText[cchText] = UNICODE_NULL;
283
284 if (!ProcessNewLinesAndNulls(phLocal, &pszNewText, &cchText, piEoln))
285 goto done;
286
287 *pencFile = encFile;
288 bSuccess = TRUE;
289
290done:
291 if (pBytes)
292 UnmapViewOfFile(pBytes);
293 if (hMapping != INVALID_HANDLE_VALUE)
294 CloseHandle(hMapping);
295 if (pszNewText)
296 LocalUnlock(*phLocal);
297 return bSuccess;
298}
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 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:1625
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1616
BOOL NTAPI LocalUnlock(HLOCAL hMem)
Definition: heapmem.c:1805
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 ENCODING_DEFAULT
Definition: notepad.h:49
#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
int32_t INT
Definition: typedefs.h:58
#define LMEM_MOVEABLE
Definition: winbase.h:369
#define CopyMemory
Definition: winbase.h:1710
#define INVALID_FILE_SIZE
Definition: winbase.h:548
_In_ int cchText
Definition: winuser.h:4465
const char * LPCSTR
Definition: xmlstorage.h:183
__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 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:813
#define SHARD_PATHW
Definition: shlobj.h:1169
#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 395 of file text.c.

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