Author: hpoussin Date: Tue Oct 9 12:53:25 2007 New Revision: 29466
URL: http://svn.reactos.org/svn/reactos?rev=29466&view=rev Log: Patch by Carlo Bramini, carlo dot bramix at libero dot it Fixes for non unicode build See issue #2711 for more details.
Modified: trunk/reactos/base/applications/notepad/ChangeLog (props changed) trunk/reactos/base/applications/notepad/dialog.c (contents, props changed) trunk/reactos/base/applications/notepad/dialog.h (contents, props changed) trunk/reactos/base/applications/notepad/license.c (props changed) trunk/reactos/base/applications/notepad/main.c (contents, props changed) trunk/reactos/base/applications/notepad/main.h (contents, props changed) trunk/reactos/base/applications/notepad/notepad.h trunk/reactos/base/applications/notepad/notepad.rbuild trunk/reactos/base/applications/notepad/notepad_res.h (props changed) trunk/reactos/base/applications/notepad/rsrc.rc (props changed) trunk/reactos/base/applications/notepad/settings.c (contents, props changed)
Propchange: trunk/reactos/base/applications/notepad/ChangeLog ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/dialog.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/d... ============================================================================== --- trunk/reactos/base/applications/notepad/dialog.c (original) +++ trunk/reactos/base/applications/notepad/dialog.c Tue Oct 9 12:53:25 2007 @@ -22,17 +22,81 @@
#include <notepad.h>
-static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 }; +static const TCHAR helpfile[] = _T("notepad.hlp"); +static const TCHAR empty_str[] = _T(""); +static const TCHAR szDefaultExt[] = _T("txt"); +static const TCHAR txt_files[] = _T("*.txt");
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); + +#ifndef UNICODE +static LPSTR ConvertToASCII(LPSTR pszText) +{ + int sz; + LPWSTR pszTextW = (LPWSTR)pszText; + + /* default return value */ + pszText = NULL; + do { + /* query about requested size for conversion */ + sz = WideCharToMultiByte(CP_ACP, 0, pszTextW, -1, NULL, 0, NULL, NULL); + if (!sz) + break; + + /* get space for ASCII buffer */ + pszText = (LPSTR)HeapAlloc(GetProcessHeap(), 0, sz); + if (pszText == NULL) + break; + + /* if previous diagnostic call worked fine, + * then this one will work too, + * so no need to test return value here + */ + WideCharToMultiByte(CP_ACP, 0, pszTextW, -1, pszText, sz, NULL, NULL); + } while (0); + + HeapFree(GetProcessHeap(), 0, pszTextW); + return pszText; +} + +static LPWSTR ConvertToUNICODE(LPSTR pszText, DWORD *pdwSize) +{ + int sz; + LPWSTR pszTextW = NULL; + + do { + /* query about requested size for conversion */ + sz = MultiByteToWideChar(CP_ACP, 0, pszText, -1, NULL, 0); + if (!sz) + break; + + /* get space for UNICODE buffer */ + pszTextW = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR)); + if (pszText == NULL) + break; + + /* if previous diagnostic call worked fine, + * then this one will work too, + * so no need to test return value here + */ + MultiByteToWideChar(CP_ACP, 0, pszText, -1, pszTextW, sz); + + /* report the new size of the text to the caller */ + *pdwSize = sz; + } while (0); + + HeapFree(GetProcessHeap(), 0, pszText); + return pszTextW; +} +#endif
VOID ShowLastError(void) { DWORD error = GetLastError(); if (error != NO_ERROR) { - LPWSTR lpMsgBuf; - WCHAR szTitle[MAX_STRING_LEN]; + LPTSTR lpMsgBuf = NULL; + TCHAR szTitle[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle)); FormatMessage( @@ -51,33 +115,33 @@ */ static void UpdateWindowCaption(void) { - WCHAR szCaption[MAX_STRING_LEN]; - WCHAR szUntitled[MAX_STRING_LEN]; + TCHAR szCaption[MAX_STRING_LEN]; + TCHAR szUntitled[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, SIZEOF(szCaption));
if (Globals.szFileTitle[0] != '\0') { - static const WCHAR bracket_lW[] = { ' ','-',' ','[',0 }; - static const WCHAR bracket_rW[] = { ']',0 }; - lstrcat(szCaption, bracket_lW); - lstrcat(szCaption, Globals.szFileTitle); - lstrcat(szCaption, bracket_rW); + static const TCHAR bracket_l[] = _T(" - ["); + static const TCHAR bracket_r[] = _T("]"); + _tcscat(szCaption, bracket_l); + _tcscat(szCaption, Globals.szFileTitle); + _tcscat(szCaption, bracket_r); } else { - static const WCHAR hyphenW[] = { ' ','-',' ',0 }; + static const TCHAR hyphen[] = _T(" - "); LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled)); - lstrcat(szCaption, hyphenW); - lstrcat(szCaption, szUntitled); + _tcscat(szCaption, hyphen); + _tcscat(szCaption, szUntitled); }
SetWindowText(Globals.hMainWnd, szCaption); }
-static void AlertFileNotFound(LPCWSTR szFileName) -{ - WCHAR szMessage[MAX_STRING_LEN]; - WCHAR szResource[MAX_STRING_LEN]; +static void AlertFileNotFound(LPCTSTR szFileName) +{ + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN];
/* Load and format szMessage */ LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource)); @@ -90,11 +154,11 @@ MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION); }
-static int AlertFileNotSaved(LPCWSTR szFileName) -{ - WCHAR szMessage[MAX_STRING_LEN]; - WCHAR szResource[MAX_STRING_LEN]; - WCHAR szUntitled[MAX_STRING_LEN]; +static int AlertFileNotSaved(LPCTSTR szFileName) +{ + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN]; + TCHAR szUntitled[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
@@ -114,7 +178,7 @@ * TRUE - if file exists * FALSE - if file does not exist */ -BOOL FileExists(LPCWSTR szFilename) +BOOL FileExists(LPCTSTR szFilename) { WIN32_FIND_DATA entry; HANDLE hFile; @@ -126,21 +190,21 @@ }
-BOOL HasFileExtension(LPCWSTR szFilename) -{ - LPCWSTR s; - - s = wcsrchr(szFilename, '\'); +BOOL HasFileExtension(LPCTSTR szFilename) +{ + LPCTSTR s; + + s = _tcsrchr(szFilename, _T('\')); if (s) szFilename = s; - return wcsrchr(szFilename, '.') != NULL; + return _tcsrchr(szFilename, _T('.')) != NULL; }
static VOID DoSaveFile(VOID) { HANDLE hFile; - LPWSTR pTemp; + LPTSTR pTemp; DWORD size;
hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, @@ -151,7 +215,7 @@ return; }
- size = GetWindowTextLengthW(Globals.hEdit) + 1; + size = GetWindowTextLength(Globals.hEdit) + 1; pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(*pTemp)); if (!pTemp) { @@ -159,9 +223,19 @@ ShowLastError(); return; } - size = GetWindowTextW(Globals.hEdit, pTemp, size); - - if (!WriteText(hFile, pTemp, size, Globals.iEncoding, Globals.iEoln)) + size = GetWindowText(Globals.hEdit, pTemp, size); + +#ifndef UNICODE + pTemp = (LPTSTR)ConvertToUNICODE(pTemp, &size); + if (!pTemp) { + /* original "pTemp" already freed */ + CloseHandle(hFile); + ShowLastError(); + return; + } +#endif + + if (!WriteText(hFile, (LPWSTR)pTemp, size, Globals.iEncoding, Globals.iEoln)) ShowLastError(); else SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0); @@ -178,7 +252,6 @@ BOOL DoCloseFile(void) { int nResult; - static const WCHAR empty_strW[] = { 0 };
if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0)) { @@ -198,20 +271,19 @@ } /* switch */ } /* if */
- SetFileName(empty_strW); + SetFileName(empty_str);
UpdateWindowCaption(); return(TRUE); }
- -void DoOpenFile(LPCWSTR szFileName) -{ - static const WCHAR dotlog[] = { '.','L','O','G',0 }; +void DoOpenFile(LPCTSTR szFileName) +{ + static const TCHAR dotlog[] = _T(".LOG"); HANDLE hFile; - LPWSTR pszText; + LPTSTR pszText; DWORD dwTextLen; - WCHAR log[5]; + TCHAR log[5];
/* Close any files and prompt to save changes */ if (!DoCloseFile()) @@ -225,13 +297,19 @@ goto done; }
- if (!ReadText(hFile, &pszText, &dwTextLen, &Globals.iEncoding, &Globals.iEoln)) + if (!ReadText(hFile, (LPWSTR *)&pszText, &dwTextLen, &Globals.iEncoding, &Globals.iEoln)) { ShowLastError(); goto done; } - - SetWindowTextW(Globals.hEdit, pszText); +#ifndef UNICODE + pszText = ConvertToASCII(pszText); + if (pszText == NULL) { + ShowLastError(); + goto done; + } +#endif + SetWindowText(Globals.hEdit, pszText);
SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0); SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); @@ -240,13 +318,13 @@ /* If the file starts with .LOG, add a time/date at the end and set cursor after * See http://support.microsoft.com/?kbid=260563 */ - if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog)) - { - static const WCHAR lfW[] = { '\r','\n',0 }; + if (GetWindowText(Globals.hEdit, log, SIZEOF(log)) && !_tcscmp(log, dotlog)) + { + static const TCHAR lf[] = _T("\r\n"); SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1); - SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW); + SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lf); DIALOG_EditTimeDate(); - SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW); + SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lf); }
SetFileName(szFileName); @@ -261,11 +339,9 @@
VOID DIALOG_FileNew(VOID) { - static const WCHAR empty_strW[] = { 0 }; - /* Close any files and prompt to save changes */ if (DoCloseFile()) { - SetWindowText(Globals.hEdit, empty_strW); + SetWindowText(Globals.hEdit, empty_str); SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); SetFocus(Globals.hEdit); } @@ -274,18 +350,16 @@ VOID DIALOG_FileOpen(VOID) { OPENFILENAME openfilename; - WCHAR szDir[MAX_PATH]; - WCHAR szPath[MAX_PATH]; - static const WCHAR szDefaultExt[] = { 't','x','t',0 }; - static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; + TCHAR szDir[MAX_PATH]; + TCHAR szPath[MAX_PATH];
ZeroMemory(&openfilename, sizeof(openfilename));
GetCurrentDirectory(SIZEOF(szDir), szDir); if (Globals.szFileName[0] == 0) - lstrcpy(szPath, txt_files); + _tcscpy(szPath, txt_files); else - lstrcpy(szPath, Globals.szFileName); + _tcscpy(szPath, Globals.szFileName);
openfilename.lStructSize = sizeof(openfilename); openfilename.hwndOwner = Globals.hMainWnd; @@ -318,7 +392,7 @@
static UINT_PTR CALLBACK DIALOG_FileSaveAs_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - WCHAR szText[128]; + TCHAR szText[128]; HWND hCombo; OFNOTIFY *pNotify;
@@ -378,18 +452,16 @@ VOID DIALOG_FileSaveAs(VOID) { OPENFILENAME saveas; - WCHAR szDir[MAX_PATH]; - WCHAR szPath[MAX_PATH]; - static const WCHAR szDefaultExt[] = { 't','x','t',0 }; - static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; + TCHAR szDir[MAX_PATH]; + TCHAR szPath[MAX_PATH];
ZeroMemory(&saveas, sizeof(saveas));
GetCurrentDirectory(SIZEOF(szDir), szDir); if (Globals.szFileName[0] == 0) - lstrcpy(szPath, txt_files); + _tcscpy(szPath, txt_files); else - lstrcpy(szPath, Globals.szFileName); + _tcscpy(szPath, Globals.szFileName);
saveas.lStructSize = sizeof(OPENFILENAME); saveas.hwndOwner = Globals.hMainWnd; @@ -422,24 +494,19 @@ LOGFONT hdrFont; HFONT font, old_font=0; DWORD size; - LPWSTR pTemp; - static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 }; + LPTSTR pTemp; + static const TCHAR times_new_roman[] = _T("Times New Roman");
/* Get a small font and print some header info on each page */ + ZeroMemory(&hdrFont, sizeof(hdrFont)); hdrFont.lfHeight = 100; - hdrFont.lfWidth = 0; - hdrFont.lfEscapement = 0; - hdrFont.lfOrientation = 0; hdrFont.lfWeight = FW_BOLD; - hdrFont.lfItalic = 0; - hdrFont.lfUnderline = 0; - hdrFont.lfStrikeOut = 0; hdrFont.lfCharSet = ANSI_CHARSET; hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS; hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; hdrFont.lfQuality = PROOF_QUALITY; hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; - lstrcpy(hdrFont.lfFaceName, times_new_romanW); + _tcscpy(hdrFont.lfFaceName, times_new_roman);
font = CreateFontIndirect(&hdrFont);
@@ -478,21 +545,21 @@ cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
/* Get the file text */ - size = GetWindowTextLengthW(Globals.hEdit) + 1; - pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); + size = GetWindowTextLength(Globals.hEdit) + 1; + pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(TCHAR)); if (!pTemp) { ShowLastError(); return; } - size = GetWindowTextW(Globals.hEdit, pTemp, size); + size = GetWindowText(Globals.hEdit, pTemp, size);
border = 150; for (copycount=1; copycount <= printer.nCopies; copycount++) { i = 0; pagecount = 1; do { - static const WCHAR letterM[] = { 'M',0 }; + static const TCHAR letterM[] = _T("M");
if (pagecount >= printer.nFromPage && /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/ @@ -506,9 +573,9 @@
if (dopage) { if (StartPage(printer.hDC) <= 0) { - static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 }; - static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 }; - MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION); + static const TCHAR failed[] = _T("StartPage failed"); + static const TCHAR error[] = _T("Print Error"); + MessageBox(Globals.hMainWnd, failed, error, MB_ICONEXCLAMATION); return; } /* Write a rectangle and header at the top of each page */ @@ -604,15 +671,15 @@ VOID DIALOG_EditTimeDate(VOID) { SYSTEMTIME st; - WCHAR szDate[MAX_STRING_LEN]; - static const WCHAR spaceW[] = { ' ',0 }; + TCHAR szDate[MAX_STRING_LEN]; + static const TCHAR space[] = _T(" ");
GetLocalTime(&st);
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN); SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
- SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW); + SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)space);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN); SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate); @@ -620,11 +687,11 @@
VOID DIALOG_EditWrap(VOID) { - static const WCHAR editW[] = { 'e','d','i','t',0 }; + static const TCHAR edit[] = _T("edit"); DWORD dwStyle; RECT rc, rcstatus; DWORD size; - LPWSTR pTemp; + LPTSTR pTemp;
Globals.bWrapLongLines = !Globals.bWrapLongLines;
@@ -652,12 +719,12 @@ ShowWindow(Globals.hStatusBar, SW_SHOW); } } - Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle, + Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, edit, NULL, dwStyle, 0, 0, rc.right, rc.bottom, Globals.hMainWnd, NULL, Globals.hInstance, NULL); SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE); SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0); - SetWindowTextW(Globals.hEdit, pTemp); + SetWindowText(Globals.hEdit, pTemp); SetFocus(Globals.hEdit); HeapFree(GetProcessHeap(), 0, pTemp); DrawMenuBar(Globals.hMainWnd); @@ -732,7 +799,7 @@ switch(uMsg) { case WM_INITDIALOG: hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER); - _sntprintf(szText, sizeof(szText) / sizeof(szText[0]), _T("%d"), lParam); + _sntprintf(szText, SIZEOF(szText), _T("%d"), lParam); SetWindowText(hTextBox, szText); break; case WM_COMMAND: @@ -741,7 +808,7 @@ if (LOWORD(wParam) == IDOK) { hTextBox = GetDlgItem(hwndDialog, ID_LINENUMBER); - GetWindowText(hTextBox, szText, sizeof(szText) / sizeof(szText[0])); + GetWindowText(hTextBox, szText, SIZEOF(szText)); EndDialog(hwndDialog, _ttoi(szText)); bResult = TRUE; } @@ -842,7 +909,7 @@
VOID DIALOG_HelpContents(VOID) { - WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0); + WinHelp(Globals.hMainWnd, helpfile, HELP_INDEX, 0); }
VOID DIALOG_HelpSearch(VOID) @@ -852,7 +919,7 @@
VOID DIALOG_HelpHelp(VOID) { - WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0); + WinHelp(Globals.hMainWnd, helpfile, HELP_HELPONHELP, 0); }
#ifdef _MSC_VER @@ -862,7 +929,7 @@ AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hLicenseEditWnd; - TCHAR strLicense[0x1000]; + TCHAR *strLicense;
switch (message) { @@ -870,6 +937,8 @@
hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE);
+ /* 0x1000 should be enought */ + strLicense = (TCHAR *)_alloca(0x1000); LoadString(GetModuleHandle(NULL), STRING_LICENSE, strLicense, 0x1000);
SetWindowText(hLicenseEditWnd, strLicense); @@ -894,11 +963,11 @@
VOID DIALOG_HelpAboutWine(VOID) { - static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 }; - WCHAR szNotepad[MAX_STRING_LEN]; + static const TCHAR notepad[] = _T("Notepad\n"); + TCHAR szNotepad[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad)); - ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0); + ShellAbout(Globals.hMainWnd, szNotepad, notepad, 0); }
@@ -947,9 +1016,9 @@ case IDHELP: { /* FIXME: Bring this to work */ - static const WCHAR sorryW[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 }; - static const WCHAR helpW[] = { 'H','e','l','p',0 }; - MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION); + static const TCHAR sorry[] = _T("Sorry, no help available"); + static const TCHAR help[] = _T("Help"); + MessageBox(Globals.hMainWnd, sorry, help, MB_ICONEXCLAMATION); return TRUE; }
Propchange: trunk/reactos/base/applications/notepad/dialog.c ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/dialog.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/d... ============================================================================== --- trunk/reactos/base/applications/notepad/dialog.h (original) +++ trunk/reactos/base/applications/notepad/dialog.h Tue Oct 9 12:53:25 2007 @@ -59,7 +59,7 @@
/* utility functions */ VOID ShowLastError(void); -BOOL FileExists(LPCWSTR szFilename); -BOOL HasFileExtension(LPCWSTR szFilename); +BOOL FileExists(LPCTSTR szFilename); +BOOL HasFileExtension(LPCTSTR szFilename); BOOL DoCloseFile(void); -void DoOpenFile(LPCWSTR szFileName); +void DoOpenFile(LPCTSTR szFileName);
Propchange: trunk/reactos/base/applications/notepad/dialog.h ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Propchange: trunk/reactos/base/applications/notepad/license.c ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/m... ============================================================================== --- trunk/reactos/base/applications/notepad/main.c (original) +++ trunk/reactos/base/applications/notepad/main.c Tue Oct 9 12:53:25 2007 @@ -33,11 +33,11 @@ * * Sets Global File Name. */ -VOID SetFileName(LPCWSTR szFileName) -{ - lstrcpy(Globals.szFileName, szFileName); +VOID SetFileName(LPCTSTR szFileName) +{ + _tcscpy(Globals.szFileName, szFileName); Globals.szFileTitle[0] = 0; - GetFileTitle(szFileName, Globals.szFileTitle, sizeof(Globals.szFileTitle) / sizeof(Globals.szFileTitle[0])); + GetFileTitle(szFileName, Globals.szFileTitle, SIZEOF(Globals.szFileTitle)); }
/*********************************************************************** @@ -244,18 +244,17 @@ */ static VOID NOTEPAD_InitData(VOID) { - LPWSTR p = Globals.szFilter; - static const WCHAR txt_files[] = { '*','.','t','x','t',0 }; - static const WCHAR all_files[] = { '*','.','*',0 }; - - LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN); - p += lstrlen(p) + 1; - lstrcpy(p, txt_files); - p += lstrlen(p) + 1; - LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN); - p += lstrlen(p) + 1; - lstrcpy(p, all_files); - p += lstrlen(p) + 1; + LPTSTR p = Globals.szFilter; + static const TCHAR txt_files[] = _T("*.txt"); + static const TCHAR all_files[] = _T("*.*"); + + p += LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN)+1; + _tcscpy(p, txt_files); + p += SIZEOF(txt_files); + + p += LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN)+1; + _tcscpy(p, all_files); + p += SIZEOF(all_files); *p = '\0'; Globals.find.lpstrFindWhat = NULL; } @@ -302,10 +301,10 @@
case WM_CREATE: { - static const WCHAR editW[] = { 'e','d','i','t',0 }; + static const TCHAR edit[] = _T("edit"); RECT rc; GetClientRect(hWnd, &rc); - Globals.hEdit = CreateWindowEx(EDIT_EXSTYLE, editW, NULL, Globals.bWrapLongLines ? EDIT_STYLE_WRAP : EDIT_STYLE, + Globals.hEdit = CreateWindowEx(EDIT_EXSTYLE, edit, NULL, Globals.bWrapLongLines ? EDIT_STYLE_WRAP : EDIT_STYLE, 0, 0, rc.right, rc.bottom, hWnd, NULL, Globals.hInstance, NULL); if (!Globals.hEdit) @@ -379,7 +378,7 @@
case WM_DROPFILES: { - WCHAR szFileName[MAX_PATH]; + TCHAR szFileName[MAX_PATH]; HDROP hDrop = (HDROP) wParam;
DragQueryFile(hDrop, 0, szFileName, SIZEOF(szFileName)); @@ -413,11 +412,11 @@ return 0; }
-static int AlertFileDoesNotExist(LPCWSTR szFileName) +static int AlertFileDoesNotExist(LPCTSTR szFileName) { int nResult; - WCHAR szMessage[MAX_STRING_LEN]; - WCHAR szResource[MAX_STRING_LEN]; + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szResource, SIZEOF(szResource)); wsprintf(szMessage, szResource, szFileName); @@ -430,16 +429,16 @@ return(nResult); }
-static void HandleCommandLine(LPWSTR cmdline) -{ - WCHAR delimiter; +static void HandleCommandLine(LPTSTR cmdline) +{ + TCHAR delimiter; int opt_print=0;
/* skip white space */ while (*cmdline == ' ') cmdline++;
/* skip executable name */ - delimiter = (*cmdline == '"' ? '"' : ' '); + delimiter = (*cmdline == _T('"') ? _T('"') : _T(' '));
do { @@ -448,15 +447,15 @@ while (*cmdline && *cmdline != delimiter); if (*cmdline == delimiter) cmdline++;
- while (*cmdline == ' ' || *cmdline == '-' || *cmdline == '/') - { - WCHAR option; - - if (*cmdline++ == ' ') continue; + while (*cmdline == _T(' ') || *cmdline == _T('-') || *cmdline == _T('/')) + { + TCHAR option; + + if (*cmdline++ == _T(' ')) continue;
option = *cmdline; if (option) cmdline++; - while (*cmdline == ' ') cmdline++; + while (*cmdline == _T(' ')) cmdline++;
switch(option) { @@ -470,11 +469,11 @@ if (*cmdline) { /* file name is passed in the command line */ - LPCWSTR file_name = NULL; + LPCTSTR file_name = NULL; BOOL file_exists = FALSE; - WCHAR buf[MAX_PATH]; - - if (cmdline[0] == '"') + TCHAR buf[MAX_PATH]; + + if (cmdline[0] == _T('"')) { cmdline++; cmdline[lstrlen(cmdline) - 1] = 0; @@ -487,17 +486,17 @@ } else if (!HasFileExtension(cmdline)) { - static const WCHAR txtW[] = { '.','t','x','t',0 }; + static const TCHAR txt[] = _T(".txt");
/* try to find file with ".txt" extension */ - if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW))) + if (!_tcscmp(txt, cmdline + _tcslen(cmdline) - _tcslen(txt))) { file_exists = FALSE; } else { - lstrcpyn(buf, cmdline, MAX_PATH - lstrlen(txtW) - 1); - lstrcat(buf, txtW); + _tcsncpy(buf, cmdline, MAX_PATH - _tcslen(txt) - 1); + _tcscat(buf, txt); file_name = buf; file_exists = FileExists(file_name); } @@ -528,16 +527,15 @@ * * WinMain */ -int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show) { MSG msg; HACCEL hAccel; WNDCLASSEX wndclass; - static const WCHAR className[] = {'N','P','C','l','a','s','s',0}; - static const WCHAR winName[] = {'N','o','t','e','p','a','d',0}; + static const TCHAR className[] = _T("NPClass"); + static const TCHAR winName[] = _T("Notepad");
UNREFERENCED_PARAMETER(prev); - UNREFERENCED_PARAMETER(cmdline);
aFINDMSGSTRING = (ATOM) RegisterWindowMessage(FINDMSGSTRING);
@@ -578,7 +576,7 @@ UpdateWindow(Globals.hMainWnd); DragAcceptFiles(Globals.hMainWnd, TRUE);
- HandleCommandLine(GetCommandLine()); + HandleCommandLine(cmdline);
hAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE(ID_ACCEL) );
Propchange: trunk/reactos/base/applications/notepad/main.c ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/main.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/m... ============================================================================== --- trunk/reactos/base/applications/notepad/main.h (original) +++ trunk/reactos/base/applications/notepad/main.h Tue Oct 9 12:53:25 2007 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#define SIZEOF(a) sizeof(a)/sizeof((a)[0]) +#define SIZEOF(a) (sizeof(a)/sizeof((a)[0]))
#include "notepad_res.h"
@@ -50,19 +50,19 @@ LOGFONT lfFont; BOOL bWrapLongLines; BOOL bShowStatusBar; - WCHAR szFindText[MAX_PATH]; - WCHAR szReplaceText[MAX_PATH]; - WCHAR szFileName[MAX_PATH]; - WCHAR szFileTitle[MAX_PATH]; - WCHAR szFilter[2 * MAX_STRING_LEN + 100]; - WCHAR szMarginTop[MAX_PATH]; - WCHAR szMarginBottom[MAX_PATH]; - WCHAR szMarginLeft[MAX_PATH]; - WCHAR szMarginRight[MAX_PATH]; - WCHAR szHeader[MAX_PATH]; - WCHAR szFooter[MAX_PATH]; - WCHAR szStatusBarLine[MAX_PATH]; - WCHAR szStatusBarCol[MAX_PATH]; + TCHAR szFindText[MAX_PATH]; + TCHAR szReplaceText[MAX_PATH]; + TCHAR szFileName[MAX_PATH]; + TCHAR szFileTitle[MAX_PATH]; + TCHAR szFilter[2 * MAX_STRING_LEN + 100]; + TCHAR szMarginTop[MAX_PATH]; + TCHAR szMarginBottom[MAX_PATH]; + TCHAR szMarginLeft[MAX_PATH]; + TCHAR szMarginRight[MAX_PATH]; + TCHAR szHeader[MAX_PATH]; + TCHAR szFooter[MAX_PATH]; + TCHAR szStatusBarLine[MAX_PATH]; + TCHAR szStatusBarCol[MAX_PATH]; int iEncoding; int iEoln;
@@ -71,7 +71,7 @@
extern NOTEPAD_GLOBALS Globals;
-VOID SetFileName(LPCWSTR szFileName); +VOID SetFileName(LPCTSTR szFileName);
/* from text.c */ BOOL ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, int *piEncoding, int *piEoln);
Propchange: trunk/reactos/base/applications/notepad/main.h ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/notepad.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/n... ============================================================================== --- trunk/reactos/base/applications/notepad/notepad.h (original) +++ trunk/reactos/base/applications/notepad/notepad.h Tue Oct 9 12:53:25 2007 @@ -1,6 +1,3 @@ -#define UNICODE -#define _UNICODE - #include <assert.h> #include <stdio.h> #include <windows.h> @@ -8,6 +5,7 @@ #include <commctrl.h> #include <tchar.h> #include <richedit.h> +#include <malloc.h>
#include "main.h" #include "dialog.h"
Modified: trunk/reactos/base/applications/notepad/notepad.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/n... ============================================================================== --- trunk/reactos/base/applications/notepad/notepad.rbuild (original) +++ trunk/reactos/base/applications/notepad/notepad.rbuild Tue Oct 9 12:53:25 2007 @@ -1,6 +1,6 @@ <?xml version="1.0"?> <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> -<module name="notepad" type="win32gui" installbase="system32" installname="notepad.exe"> +<module name="notepad" type="win32gui" installbase="system32" installname="notepad.exe" unicode="yes"> <include base="notepad">.</include> <define name="__USE_W32API" /> <define name="_WIN32_IE">0x0501</define>
Propchange: trunk/reactos/base/applications/notepad/notepad_res.h ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Propchange: trunk/reactos/base/applications/notepad/rsrc.rc ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision
Modified: trunk/reactos/base/applications/notepad/settings.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/s... ============================================================================== --- trunk/reactos/base/applications/notepad/settings.c (original) +++ trunk/reactos/base/applications/notepad/settings.c Tue Oct 9 12:53:25 2007 @@ -22,9 +22,7 @@
#include <notepad.h>
-static const TCHAR s_szRegistryKey[] = { 'S','o','f','t','w','a','r','e', - '\','M','i','c','r','o','s','o','f','t', - '\','N','o','t','e','p','a','d',0 }; +static LPCTSTR s_szRegistryKey = _T("Software\Microsoft\Notepad");
static LONG HeightFromPointSize(DWORD dwPointSize) @@ -55,49 +53,31 @@ return dwPointSize; }
-static BOOL QueryGeneric(HKEY hKey, LPCSTR pszValueName, DWORD dwExpectedType, +static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize) { - WCHAR szValueW[32]; - LPCTSTR pszValueNameT; DWORD dwType, cbData; - LPVOID *pTemp; - BOOL bSuccess = FALSE; + LPVOID *pTemp = _alloca(dwResultSize);
-#ifdef UNICODE - MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0])); - pszValueNameT = szValueW; -#else - pszValueNameT = pszValueName; -#endif - - pTemp = HeapAlloc(GetProcessHeap(), 0, dwResultSize); - if (!pTemp) - goto done; - memset(pTemp, 0, dwResultSize); + ZeroMemory(pTemp, dwResultSize);
cbData = dwResultSize; if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS) - goto done; + return FALSE;
if (dwType != dwExpectedType) - goto done; + return FALSE;
memcpy(pvResult, pTemp, cbData); - bSuccess = TRUE; - -done: - if (pTemp) - HeapFree(GetProcessHeap(), 0, pTemp); - return bSuccess; + return TRUE; }
-static BOOL QueryDword(HKEY hKey, LPCSTR pszValueName, DWORD *pdwResult) +static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult) { return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult)); }
-static BOOL QueryByte(HKEY hKey, LPCSTR pszValueName, BYTE *pbResult) +static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult) { DWORD dwResult; if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult))) @@ -108,7 +88,7 @@ return TRUE; }
-static BOOL QueryBool(HKEY hKey, LPCSTR pszValueName, BOOL *pbResult) +static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult) { DWORD dwResult; if (!QueryDword(hKey, pszValueName, &dwResult)) @@ -117,9 +97,9 @@ return TRUE; }
-static BOOL QueryString(HKEY hKey, LPCSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize) +static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize) { - return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(*pszResult)); + return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(TCHAR)); }
void LoadSettings(void) @@ -130,20 +110,20 @@
if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) { - QueryByte(hKey, "lfCharSet", &Globals.lfFont.lfCharSet); - QueryByte(hKey, "lfClipPrecision", &Globals.lfFont.lfClipPrecision); - QueryDword(hKey, "lfEscapement", (DWORD*)&Globals.lfFont.lfEscapement); - QueryString(hKey, "lfFaceName", Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0])); - QueryByte(hKey, "lfItalic", &Globals.lfFont.lfItalic); - QueryDword(hKey, "lfOrientation", (DWORD*)&Globals.lfFont.lfOrientation); - QueryByte(hKey, "lfOutPrecision", &Globals.lfFont.lfOutPrecision); - QueryByte(hKey, "lfPitchAndFamily", &Globals.lfFont.lfPitchAndFamily); - QueryByte(hKey, "lfQuality", &Globals.lfFont.lfQuality); - QueryByte(hKey, "lfStrikeOut", &Globals.lfFont.lfStrikeOut); - QueryByte(hKey, "lfUnderline", &Globals.lfFont.lfUnderline); - QueryDword(hKey, "lfWeight", (DWORD*)&Globals.lfFont.lfWeight); - QueryDword(hKey, "iPointSize", &dwPointSize); - QueryBool(hKey, "fWrap", &Globals.bWrapLongLines); + QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet); + QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision); + QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement); + QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0])); + QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic); + QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation); + QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision); + QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily); + QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality); + QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut); + QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline); + QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight); + QueryDword(hKey, _T("iPointSize"), &dwPointSize); + QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
if (dwPointSize != 0) Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); @@ -160,33 +140,13 @@ } }
-static BOOL SaveDword(HKEY hKey, LPCSTR pszValueName, DWORD dwValue) +static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue) { - WCHAR szValueW[32]; - LPCTSTR pszValueNameT; - -#ifdef UNICODE - MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0])); - pszValueNameT = szValueW; -#else - pszValueNameT = pszValueName; -#endif - return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS; }
-static BOOL SaveString(HKEY hKey, LPCSTR pszValueName, LPCTSTR pszValue) +static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue) { - WCHAR szValueW[32]; - LPCTSTR pszValueNameT; - -#ifdef UNICODE - MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0])); - pszValueNameT = szValueW; -#else - pszValueNameT = pszValueName; -#endif - return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS; }
@@ -198,20 +158,20 @@ if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS) { - SaveDword(hKey, "lfCharSet", Globals.lfFont.lfCharSet); - SaveDword(hKey, "lfClipPrecision", Globals.lfFont.lfClipPrecision); - SaveDword(hKey, "lfEscapement", Globals.lfFont.lfEscapement); - SaveString(hKey, "lfFaceName", Globals.lfFont.lfFaceName); - SaveDword(hKey, "lfItalic", Globals.lfFont.lfItalic); - SaveDword(hKey, "lfOrientation", Globals.lfFont.lfOrientation); - SaveDword(hKey, "lfOutPrecision", Globals.lfFont.lfOutPrecision); - SaveDword(hKey, "lfPitchAndFamily", Globals.lfFont.lfPitchAndFamily); - SaveDword(hKey, "lfQuality", Globals.lfFont.lfQuality); - SaveDword(hKey, "lfStrikeOut", Globals.lfFont.lfStrikeOut); - SaveDword(hKey, "lfUnderline", Globals.lfFont.lfUnderline); - SaveDword(hKey, "lfWeight", Globals.lfFont.lfWeight); - SaveDword(hKey, "iPointSize", PointSizeFromHeight(Globals.lfFont.lfHeight)); - SaveDword(hKey, "fWrap", Globals.bWrapLongLines ? 1 : 0); + SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet); + SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision); + SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement); + SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName); + SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic); + SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation); + SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision); + SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily); + SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality); + SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut); + SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline); + SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight); + SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight)); + SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
RegCloseKey(hKey); }
Propchange: trunk/reactos/base/applications/notepad/settings.c ------------------------------------------------------------------------------ --- svn:keywords (original) +++ svn:keywords (removed) @@ -1,1 +1,0 @@ -author date id revision