ReactOS  0.4.12-dev-720-g6accaef
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
 
#define EOLN_CRLF   0
 
#define EOLN_LF   1
 
#define EOLN_CR   2
 

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_ANSI = 1, ENCODING_UTF8, ENCODING_UTF16LE,
  ENCODING_UTF16BE
}
 

Functions

VOID SetFileName (LPCTSTR szFileName)
 
BOOL ReadText (HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, ENCODING *pencFile, int *piEoln)
 
BOOL WriteText (HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile, int 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 ES_MULTILINE
Definition: pedump.c:667
#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

Definition at line 28 of file main.h.

◆ EOLN_CR

#define EOLN_CR   2

Definition at line 51 of file main.h.

◆ EOLN_CRLF

#define EOLN_CRLF   0

Definition at line 49 of file main.h.

◆ EOLN_LF

#define EOLN_LF   1

Definition at line 50 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_ANSI 
ENCODING_UTF8 
ENCODING_UTF16LE 
ENCODING_UTF16BE 

Definition at line 37 of file main.h.

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

Function Documentation

◆ NOTEPAD_EnableSearchMenu()

VOID NOTEPAD_EnableSearchMenu ( VOID  )

◆ NOTEPAD_FindNext()

BOOL NOTEPAD_FindNext ( FINDREPLACE ,
BOOL  ,
BOOL   
)

Definition at line 138 of file main.c.

139 {
140  int iTextLength, iTargetLength;
141  size_t iAdjustment = 0;
142  LPTSTR pszText = NULL;
143  DWORD dwPosition, dwBegin, dwEnd;
144  BOOL bMatches = FALSE;
145  TCHAR szResource[128], szText[128];
146  BOOL bSuccess;
147 
148  iTargetLength = (int) _tcslen(pFindReplace->lpstrFindWhat);
149 
150  /* Retrieve the window text */
151  iTextLength = GetWindowTextLength(Globals.hEdit);
152  if (iTextLength > 0)
153  {
154  pszText = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (iTextLength + 1) * sizeof(TCHAR));
155  if (!pszText)
156  return FALSE;
157 
158  GetWindowText(Globals.hEdit, pszText, iTextLength + 1);
159  }
160 
161  SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM) &dwBegin, (LPARAM) &dwEnd);
162  if (bReplace && ((dwEnd - dwBegin) == (DWORD) iTargetLength))
163  {
164  if (NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwBegin))
165  {
166  SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM) pFindReplace->lpstrReplaceWith);
167  iAdjustment = _tcslen(pFindReplace->lpstrReplaceWith) - (dwEnd - dwBegin);
168  }
169  }
170 
171  if (pFindReplace->Flags & FR_DOWN)
172  {
173  /* Find Down */
174  dwPosition = dwEnd;
175  while(dwPosition < (DWORD) iTextLength)
176  {
177  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
178  if (bMatches)
179  break;
180  dwPosition++;
181  }
182  }
183  else
184  {
185  /* Find Up */
186  dwPosition = dwBegin;
187  while(dwPosition > 0)
188  {
189  dwPosition--;
190  bMatches = NOTEPAD_FindTextAt(pFindReplace, pszText, iTextLength, dwPosition);
191  if (bMatches)
192  break;
193  }
194  }
195 
196  if (bMatches)
197  {
198  /* Found target */
199  if (dwPosition > dwBegin)
200  dwPosition += (DWORD) iAdjustment;
201  SendMessage(Globals.hEdit, EM_SETSEL, dwPosition, dwPosition + iTargetLength);
203  bSuccess = TRUE;
204  }
205  else
206  {
207  /* Can't find target */
208  if (bShowAlert)
209  {
210  LoadString(Globals.hInstance, STRING_CANNOTFIND, szResource, ARRAY_SIZE(szResource));
211  _sntprintf(szText, ARRAY_SIZE(szText), szResource, pFindReplace->lpstrFindWhat);
212  LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, ARRAY_SIZE(szResource));
214  }
215  bSuccess = FALSE;
216  }
217 
218  if (pszText)
220  return bSuccess;
221 }
HWND hFindReplaceDlg
Definition: main.h:57
#define TRUE
Definition: types.h:120
NOTEPAD_GLOBALS Globals
Definition: main.c:29
#define DWORD
Definition: msvc.h:34
LPCWSTR pszText
Definition: msvc.h:103
static BOOLEAN bSuccess
Definition: drive.cpp:417
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5664
UINT_PTR WPARAM
Definition: windef.h:207
HINSTANCE hInstance
Definition: main.h:55
#define EM_GETSEL
Definition: winuser.h:1958
#define STRING_NOTEPAD
Definition: notepad_res.h:74
static const WCHAR szText[]
Definition: dialog.c:139
static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition)
Definition: main.c:104
LONG_PTR LPARAM
Definition: windef.h:208
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define EM_SETSEL
Definition: winuser.h:1979
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _sntprintf
Definition: xmlstorage.h:201
#define MessageBox
Definition: winuser.h:5688
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MB_OK
Definition: winuser.h:784
#define FR_DOWN
Definition: commdlg.h:127
#define STRING_CANNOTFIND
Definition: notepad_res.h:88
#define SendMessage
Definition: winuser.h:5709
#define GetWindowTextLength
Definition: winuser.h:5665
HWND hEdit
Definition: main.h:58
#define HeapFree(x, y, z)
Definition: compat.h:394
#define LoadString
Definition: winuser.h:5685
#define EM_REPLACESEL
Definition: winuser.h:1967
#define EM_SCROLLCARET
Definition: richedit.h:81
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:29

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;
119  INT base_length, dx, dy;
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 
168  RegCloseKey(hKey);
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 = ANSI_CHARSET;
187  Globals.lfFont.lfClipPrecision = CLIP_STROKE_PRECIS;
188  Globals.lfFont.lfEscapement = 0;
189  _tcscpy(Globals.lfFont.lfFaceName, _T("Lucida Console"));
190  Globals.lfFont.lfItalic = FALSE;
191  Globals.lfFont.lfOrientation = 0;
192  Globals.lfFont.lfOutPrecision = OUT_STRING_PRECIS;
193  Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
194  Globals.lfFont.lfQuality = PROOF_QUALITY;
195  Globals.lfFont.lfStrikeOut = FALSE;
196  Globals.lfFont.lfUnderline = FALSE;
197  Globals.lfFont.lfWeight = FW_NORMAL;
198  Globals.lfFont.lfHeight = HeightFromPointSize(100);
199  }
200 
201  hFont = CreateFontIndirect(&Globals.lfFont);
203  if (hFont)
204  {
205  if (Globals.hFont)
206  DeleteObject(Globals.hFont);
207  Globals.hFont = hFont;
208  }
209 }
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
Definition: settings.c:83
#define TRUE
Definition: types.h:120
int base_length[LENGTH_CODES]
Definition: trees.c:107
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
INT dx
Definition: msvc.h:65
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define PROOF_QUALITY
Definition: wingdi.h:437
int32_t INT
Definition: typedefs.h:56
HFONT hFont
Definition: main.c:53
#define STRING_PAGESETUP_HEADERVALUE
Definition: notepad_res.h:67
UINT_PTR WPARAM
Definition: windef.h:207
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define SM_CXSCREEN
Definition: winuser.h:949
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LONG_PTR LPARAM
Definition: windef.h:208
#define FIXED_PITCH
Definition: wingdi.h:443
#define OUT_STRING_PRECIS
Definition: wingdi.h:415
smooth NULL
Definition: ftsmooth.c:416
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
Definition: settings.c:94
#define SM_CYSCREEN
Definition: winuser.h:950
#define _T(x)
Definition: vfdio.h:22
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:78
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize)
Definition: settings.c:103
#define STRING_PAGESETUP_FOOTERVALUE
Definition: notepad_res.h:68
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
static LPCTSTR s_szRegistryKey
Definition: settings.c:27
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define ARRAY_SIZE(a)
Definition: main.h:24
#define INT
Definition: msvc.h:26
#define FF_MODERN
Definition: wingdi.h:448
#define CreateFontIndirect
Definition: wingdi.h:4422
INT INT dy
Definition: msvc.h:65
#define WM_SETFONT
Definition: winuser.h:1632
#define FW_NORMAL
Definition: wingdi.h:372
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define SendMessage
Definition: winuser.h:5709
static LONG HeightFromPointSize(DWORD dwPointSize)
Definition: settings.c:30
#define ANSI_CHARSET
Definition: wingdi.h:382
HINSTANCE hInstance
Definition: precomp.h:43
#define RegOpenKey
Definition: winreg.h:519
#define CLIP_STROKE_PRECIS
Definition: wingdi.h:427
#define LoadString
Definition: winuser.h:5685

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 
232  GetWindowRect(Globals.hMainWnd, &Globals.main_rect);
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 
264  RegCloseKey(hKey);
265  }
266 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define HKEY_CURRENT_USER
Definition: winreg.h:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:211
static LPCTSTR s_szRegistryKey
Definition: settings.c:27
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:42
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:216
#define RegCreateKeyEx
Definition: winreg.h:501

Referenced by NOTEPAD_WndProc().

◆ ReadText()

BOOL ReadText ( HANDLE  hFile,
LPWSTR ppszText,
DWORD pdwTextLen,
ENCODING pencFile,
int piEoln 
)

Definition at line 51 of file text.c.

52 {
53  DWORD dwSize;
54  LPBYTE pBytes = NULL;
56  LPWSTR pszAllocText = NULL;
57  DWORD dwPos, i;
58  DWORD dwCharCount;
60  BYTE b = 0;
61  ENCODING encFile = ENCODING_ANSI;
62  int iCodePage = 0;
63  WCHAR szCrlf[2] = {'\r', '\n'};
64  DWORD adwEolnCount[3] = {0, 0, 0};
65 
66  *ppszText = NULL;
67  *pdwTextLen = 0;
68 
71  goto done;
72 
73  pBytes = HeapAlloc(GetProcessHeap(), 0, dwSize + 2);
74  if (!pBytes)
75  goto done;
76 
77  if (!ReadFile(hFile, pBytes, dwSize, &dwSize, NULL))
78  goto done;
79  dwPos = 0;
80 
81  /* Make sure that there is a NUL character at the end, in any encoding */
82  pBytes[dwSize + 0] = '\0';
83  pBytes[dwSize + 1] = '\0';
84 
85  /* Look for Byte Order Marks */
86  if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE))
87  {
88  encFile = ENCODING_UTF16LE;
89  dwPos += 2;
90  }
91  else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF))
92  {
93  encFile = ENCODING_UTF16BE;
94  dwPos += 2;
95  }
96  else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF))
97  {
98  encFile = ENCODING_UTF8;
99  dwPos += 3;
100  }
101 
102  switch(encFile)
103  {
104  case ENCODING_UTF16BE:
105  for (i = dwPos; i < dwSize-1; i += 2)
106  {
107  b = pBytes[i+0];
108  pBytes[i+0] = pBytes[i+1];
109  pBytes[i+1] = b;
110  }
111  /* fall through */
112 
113  case ENCODING_UTF16LE:
114  pszText = (LPWSTR) &pBytes[dwPos];
115  dwCharCount = (dwSize - dwPos) / sizeof(WCHAR);
116  break;
117 
118  case ENCODING_ANSI:
119  case ENCODING_UTF8:
120  if (encFile == ENCODING_ANSI)
121  iCodePage = CP_ACP;
122  else if (encFile == ENCODING_UTF8)
123  iCodePage = CP_UTF8;
124 
125  if ((dwSize - dwPos) > 0)
126  {
127  dwCharCount = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, NULL, 0);
128  if (dwCharCount == 0)
129  goto done;
130  }
131  else
132  {
133  /* special case for files with no characters (other than BOMs) */
134  dwCharCount = 0;
135  }
136 
137  pszAllocText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (dwCharCount + 1) * sizeof(WCHAR));
138  if (!pszAllocText)
139  goto done;
140 
141  if ((dwSize - dwPos) > 0)
142  {
143  if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, pszAllocText, dwCharCount))
144  goto done;
145  }
146 
147  pszAllocText[dwCharCount] = '\0';
148  pszText = pszAllocText;
149  break;
151  }
152 
153  dwPos = 0;
154  for (i = 0; i < dwCharCount; i++)
155  {
156  switch(pszText[i])
157  {
158  case '\r':
159  if ((i < dwCharCount-1) && (pszText[i+1] == '\n'))
160  {
161  i++;
162  adwEolnCount[EOLN_CRLF]++;
163  break;
164  }
165  /* fall through */
166 
167  case '\n':
168  if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos))
169  return FALSE;
170  if (!Append(ppszText, pdwTextLen, szCrlf, ARRAY_SIZE(szCrlf)))
171  return FALSE;
172  dwPos = i + 1;
173 
174  if (pszText[i] == '\r')
175  adwEolnCount[EOLN_CR]++;
176  else
177  adwEolnCount[EOLN_LF]++;
178  break;
179 
180  case '\0':
181  pszText[i] = ' ';
182  break;
183  }
184  }
185 
186  if (!*ppszText && (pszText == pszAllocText))
187  {
188  /* special case; don't need to reallocate */
189  *ppszText = pszAllocText;
190  *pdwTextLen = dwCharCount;
191  pszAllocText = NULL;
192  }
193  else
194  {
195  /* append last remaining text */
196  if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos + 1))
197  return FALSE;
198  }
199 
200  /* chose which eoln to use */
201  *piEoln = EOLN_CRLF;
202  if (adwEolnCount[EOLN_LF] > adwEolnCount[*piEoln])
203  *piEoln = EOLN_LF;
204  if (adwEolnCount[EOLN_CR] > adwEolnCount[*piEoln])
205  *piEoln = EOLN_CR;
206  *pencFile = encFile;
207 
208  bSuccess = TRUE;
209 
210 done:
211  if (pBytes)
212  HeapFree(GetProcessHeap(), 0, pBytes);
213  if (pszAllocText)
214  HeapFree(GetProcessHeap(), 0, pszAllocText);
215 
216  if (!bSuccess && *ppszText)
217  {
218  HeapFree(GetProcessHeap(), 0, *ppszText);
219  *ppszText = NULL;
220  *pdwTextLen = 0;
221  }
222  return bSuccess;
223 }
#define DEFAULT_UNREACHABLE
#define TRUE
Definition: types.h:120
#define EOLN_CR
Definition: main.h:51
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
LPCWSTR pszText
Definition: msvc.h:103
static BOOL Append(LPWSTR *ppszText, DWORD *pdwTextLen, LPCWSTR pszAppendText, DWORD dwAppendLen)
Definition: text.c:25
#define INVALID_FILE_SIZE
Definition: winbase.h:529
static BOOLEAN bSuccess
Definition: drive.cpp:417
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
unsigned char * LPBYTE
Definition: typedefs.h:52
#define CP_UTF8
Definition: nls.h:20
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EOLN_CRLF
Definition: main.h:49
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define EOLN_LF
Definition: main.h:50
unsigned char BYTE
Definition: mem.h:68
_In_ HANDLE hFile
Definition: mswsock.h:90
ENCODING
Definition: more.c:155
#define ARRAY_SIZE(a)
Definition: main.h:24
#define MultiByteToWideChar
Definition: compat.h:100
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by DoOpenFile().

◆ SetFileName()

VOID SetFileName ( LPCTSTR  szFileName)

Definition at line 46 of file main.c.

47 {
49  Globals.szFileTitle[0] = 0;
51 }
NOTEPAD_GLOBALS Globals
Definition: main.c:29
TCHAR szFileName[MAX_PATH]
Definition: main.h:69
#define GetFileTitle
Definition: commdlg.h:664
#define StringCchCopy
Definition: strsafe.h:139
#define ARRAY_SIZE(a)
Definition: main.h:24
TCHAR szFileTitle[MAX_PATH]
Definition: main.h:70

◆ WriteText()

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

Definition at line 319 of file text.c.

320 {
321  WCHAR wcBom;
322  LPCWSTR pszLF = L"\n";
323  DWORD dwPos, dwNext;
324 
325  /* Write the proper byte order marks if not ANSI */
326  if (encFile != ENCODING_ANSI)
327  {
328  wcBom = 0xFEFF;
329  if (!WriteEncodedText(hFile, &wcBom, 1, encFile))
330  return FALSE;
331  }
332 
333  dwPos = 0;
334 
335  /* pszText eoln are always \r\n */
336 
337  do
338  {
339  /* Find the next eoln */
340  dwNext = dwPos;
341  while(dwNext < dwTextLen)
342  {
343  if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n')
344  break;
345  dwNext++;
346  }
347 
348  if (dwNext != dwTextLen)
349  {
350  switch (iEoln)
351  {
352  case EOLN_LF:
353  /* Write text (without eoln) */
354  if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
355  return FALSE;
356  /* Write eoln */
357  if (!WriteEncodedText(hFile, pszLF, 1, encFile))
358  return FALSE;
359  break;
360  case EOLN_CR:
361  /* Write text (including \r as eoln) */
362  if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1, encFile))
363  return FALSE;
364  break;
365  case EOLN_CRLF:
366  /* Write text (including \r\n as eoln) */
367  if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2, encFile))
368  return FALSE;
369  break;
370  default:
371  return FALSE;
372  }
373  }
374  else
375  {
376  /* Write text (without eoln, since this is the end of the file) */
377  if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, encFile))
378  return FALSE;
379  }
380 
381  /* Skip \r\n */
382  dwPos = dwNext + 2;
383  }
384  while (dwPos < dwTextLen);
385 
386  return TRUE;
387 }
#define TRUE
Definition: types.h:120
#define EOLN_CR
Definition: main.h:51
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPCWSTR pszText
Definition: msvc.h:103
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
static BOOL WriteEncodedText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, ENCODING encFile)
Definition: text.c:225
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EOLN_CRLF
Definition: main.h:49
#define EOLN_LF
Definition: main.h:50
static const WCHAR L[]
Definition: oid.c:1250
_In_ HANDLE hFile
Definition: mswsock.h:90

Referenced by DoSaveFile().

Variable Documentation

◆ Globals

NOTEPAD_GLOBALS Globals

Definition at line 13 of file clipbrd.c.