Author: akhaldi Date: Thu Jan 8 13:20:02 2015 New Revision: 66005
URL: http://svn.reactos.org/svn/reactos?rev=66005&view=rev Log: [NOTEPAD] Fix some comment typos. Tabs => Spaces. Apply consistent formatting. No code changes.
Modified: trunk/reactos/base/applications/notepad/dialog.c trunk/reactos/base/applications/notepad/license.c trunk/reactos/base/applications/notepad/main.c trunk/reactos/base/applications/notepad/main.h trunk/reactos/base/applications/notepad/settings.c trunk/reactos/base/applications/notepad/text.c
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 [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/dialog.c [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -28,17 +28,17 @@
LRESULT CALLBACK EDIT_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-static const TCHAR helpfile[] = _T("notepad.hlp"); -static const TCHAR empty_str[] = _T(""); +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 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; + int sz; LPWSTR pszTextW = (LPWSTR)pszText;
/* default return value */ @@ -67,7 +67,7 @@
static LPWSTR ConvertToUNICODE(LPSTR pszText, DWORD *pdwSize) { - int sz; + int sz; LPWSTR pszTextW = NULL;
do { @@ -77,7 +77,7 @@ break;
/* get space for UNICODE buffer */ - pszTextW = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR)); + pszTextW = HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR)); if (pszText == NULL) break;
@@ -105,10 +105,15 @@ TCHAR szTitle[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle)); - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error, 0, - (LPTSTR) &lpMsgBuf, 0, NULL); + + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + error, + 0, + (LPTSTR) &lpMsgBuf, + 0, + NULL); + MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR); LocalFree(lpMsgBuf); } @@ -121,58 +126,58 @@ */ static void UpdateWindowCaption(void) { - TCHAR szCaption[MAX_STRING_LEN]; - TCHAR szNotepad[MAX_STRING_LEN]; - - LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad)); - - if (Globals.szFileTitle[0] != 0) - { - StringCchCopy(szCaption, SIZEOF(szCaption), Globals.szFileTitle); - } - else - { - LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption)); - } - - StringCchCat(szCaption, SIZEOF(szCaption), _T(" - ")); - StringCchCat(szCaption, SIZEOF(szCaption), szNotepad); - SetWindowText(Globals.hMainWnd, szCaption); + TCHAR szCaption[MAX_STRING_LEN]; + TCHAR szNotepad[MAX_STRING_LEN]; + + LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad)); + + if (Globals.szFileTitle[0] != 0) + { + StringCchCopy(szCaption, SIZEOF(szCaption), Globals.szFileTitle); + } + else + { + LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption)); + } + + StringCchCat(szCaption, SIZEOF(szCaption), _T(" - ")); + StringCchCat(szCaption, SIZEOF(szCaption), szNotepad); + SetWindowText(Globals.hMainWnd, szCaption); }
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)); - wsprintf(szMessage, szResource, szFileName); - - /* Load szCaption */ - LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); - - /* Display Modal Dialog */ - MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION); + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN]; + + /* Load and format szMessage */ + LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource)); + wsprintf(szMessage, szResource, szFileName); + + /* Load szCaption */ + LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); + + /* Display Modal Dialog */ + MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION); }
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)); - - /* Load and format Message */ - LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource)); - wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled); - - /* Load Caption */ - LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); - - /* Display modal */ - return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL); + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN]; + TCHAR szUntitled[MAX_STRING_LEN]; + + LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled)); + + /* Load and format Message */ + LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource)); + wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled); + + /* Load Caption */ + LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); + + /* Display modal */ + return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL); }
/** @@ -182,13 +187,13 @@ */ BOOL FileExists(LPCTSTR szFilename) { - WIN32_FIND_DATA entry; - HANDLE hFile; - - hFile = FindFirstFile(szFilename, &entry); - FindClose(hFile); - - return (hFile != INVALID_HANDLE_VALUE); + WIN32_FIND_DATA entry; + HANDLE hFile; + + hFile = FindFirstFile(szFilename, &entry); + FindClose(hFile); + + return (hFile != INVALID_HANDLE_VALUE); }
BOOL HasFileExtension(LPCTSTR szFilename) @@ -378,17 +383,15 @@ else _tcscpy(szPath, Globals.szFileName);
- openfilename.lStructSize = sizeof(openfilename); - openfilename.hwndOwner = Globals.hMainWnd; - openfilename.hInstance = Globals.hInstance; - openfilename.lpstrFilter = Globals.szFilter; - openfilename.lpstrFile = szPath; - openfilename.nMaxFile = SIZEOF(szPath); - openfilename.lpstrInitialDir = szDir; - openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | - OFN_HIDEREADONLY; - openfilename.lpstrDefExt = szDefaultExt; - + openfilename.lStructSize = sizeof(openfilename); + openfilename.hwndOwner = Globals.hMainWnd; + openfilename.hInstance = Globals.hInstance; + openfilename.lpstrFilter = Globals.szFilter; + openfilename.lpstrFile = szPath; + openfilename.nMaxFile = SIZEOF(szPath); + openfilename.lpstrInitialDir = szDir; + openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; + openfilename.lpstrDefExt = szDefaultExt;
if (GetOpenFileName(&openfilename)) { if (FileExists(openfilename.lpstrFile)) @@ -398,7 +401,6 @@ } }
- BOOL DIALOG_FileSave(VOID) { if (Globals.szFileName[0] == 0) @@ -407,7 +409,9 @@ return DoSaveFile(); }
-static UINT_PTR CALLBACK DIALOG_FileSaveAs_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static UINT_PTR +CALLBACK +DIALOG_FileSaveAs_Hook(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { TCHAR szText[128]; HWND hCombo; @@ -477,24 +481,24 @@ else _tcscpy(szPath, Globals.szFileName);
- saveas.lStructSize = sizeof(OPENFILENAME); - saveas.hwndOwner = Globals.hMainWnd; - saveas.hInstance = Globals.hInstance; - saveas.lpstrFilter = Globals.szFilter; - saveas.lpstrFile = szPath; - saveas.nMaxFile = SIZEOF(szPath); - saveas.lpstrInitialDir = szDir; - saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | - OFN_HIDEREADONLY | OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_ENABLEHOOK; - saveas.lpstrDefExt = szDefaultExt; - saveas.lpTemplateName = MAKEINTRESOURCE(DIALOG_ENCODING); - saveas.lpfnHook = DIALOG_FileSaveAs_Hook; + saveas.lStructSize = sizeof(OPENFILENAME); + saveas.hwndOwner = Globals.hMainWnd; + saveas.hInstance = Globals.hInstance; + saveas.lpstrFilter = Globals.szFilter; + saveas.lpstrFile = szPath; + saveas.nMaxFile = SIZEOF(szPath); + saveas.lpstrInitialDir = szDir; + saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | + OFN_EXPLORER | OFN_ENABLETEMPLATE | OFN_ENABLEHOOK; + saveas.lpstrDefExt = szDefaultExt; + saveas.lpTemplateName = MAKEINTRESOURCE(DIALOG_ENCODING); + saveas.lpfnHook = DIALOG_FileSaveAs_Hook;
if (GetSaveFileName(&saveas)) { - // HACK: Because in ROS, Save-As boxes don't check the validity - // of file names and thus, here, szPath can be invalid !! We only - // see its validity when we call DoSaveFile()... + /* HACK: Because in ROS, Save-As boxes don't check the validity + * of file names and thus, here, szPath can be invalid !! We only + * see its validity when we call DoSaveFile()... */ SetFileName(szPath); if (DoSaveFile()) { @@ -542,20 +546,20 @@
/* Get Current Settings */ ZeroMemory(&printer, sizeof(printer)); - printer.lStructSize = sizeof(printer); - printer.hwndOwner = Globals.hMainWnd; - printer.hInstance = Globals.hInstance; + printer.lStructSize = sizeof(printer); + printer.hwndOwner = Globals.hMainWnd; + printer.hInstance = Globals.hInstance;
/* Set some default flags */ - printer.Flags = PD_RETURNDC; - printer.nFromPage = 0; - printer.nMinPage = 1; + printer.Flags = PD_RETURNDC; + printer.nFromPage = 0; + printer.nMinPage = 1; /* we really need to calculate number of pages to set nMaxPage and nToPage */ - printer.nToPage = 0; - printer.nMaxPage = (WORD) -1; + printer.nToPage = 0; + printer.nMaxPage = (WORD)-1;
/* Let commdlg manage copy settings */ - printer.nCopies = (WORD)PD_USEDEVMODECOPIES; + printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
if (!PrintDlg(&printer)) { @@ -628,22 +632,25 @@ /* I don't know what's up with this TextOut command. This comes out kind of mangled. */ - TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle)); + TextOut(printer.hDC, + border * 2, + border + szMetric.cy / 2, + Globals.szFileTitle, + lstrlen(Globals.szFileTitle)); }
/* The starting point for the main text */ - xLeft = border*2; - yTop = border+szMetric.cy*4; + xLeft = border * 2; + yTop = border + szMetric.cy * 4;
SelectObject(printer.hDC, old_font); GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
/* Since outputting strings is giving me problems, output the main - text one character at a time. - */ + * text one character at a time. */ do { if (pTemp[i] == '\n') { - xLeft = border*2; + xLeft = border * 2; yTop += szMetric.cy; } else if (pTemp[i] != '\r') { @@ -651,12 +658,12 @@ TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1); xLeft += szMetric.cx; } - } while (i++<size && yTop<(cHeightPels-border*2)); + } while (i++ < size && yTop < (cHeightPels - border * 2));
if (dopage) EndPage(printer.hDC); pagecount++; - } while (i<size); + } while (i < size); }
if (old_font != 0) @@ -672,11 +679,11 @@ PRINTDLG printer;
ZeroMemory(&printer, sizeof(printer)); - printer.lStructSize = sizeof(printer); - printer.hwndOwner = Globals.hMainWnd; - printer.hInstance = Globals.hInstance; - printer.Flags = PD_PRINTSETUP; - printer.nCopies = 1; + printer.lStructSize = sizeof(printer); + printer.hwndOwner = Globals.hMainWnd; + printer.hInstance = Globals.hInstance; + printer.Flags = PD_PRINTSETUP; + printer.nCopies = 1;
PrintDlg(&printer); } @@ -718,9 +725,9 @@
VOID DIALOG_EditTimeDate(VOID) { - SYSTEMTIME st; - TCHAR szDate[MAX_STRING_LEN]; - TCHAR szText[MAX_STRING_LEN * 2 + 2]; + SYSTEMTIME st; + TCHAR szDate[MAX_STRING_LEN]; + TCHAR szText[MAX_STRING_LEN * 2 + 2];
GetLocalTime(&st);
@@ -738,15 +745,14 @@ RECT rcstatus; BOOL bStatusBarVisible;
- // Check if status bar object already exists. + /* Check if status bar object already exists. */ if (Globals.hStatusBar == NULL) { - // Try to create the status bar - Globals.hStatusBar = CreateStatusWindow( - WS_CHILD | WS_VISIBLE | WS_EX_STATICEDGE, - NULL, - Globals.hMainWnd, - CMD_STATUSBAR_WND_ID); + /* Try to create the status bar */ + Globals.hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE | WS_EX_STATICEDGE, + NULL, + Globals.hMainWnd, + CMD_STATUSBAR_WND_ID);
if (Globals.hStatusBar == NULL) { @@ -754,16 +760,15 @@ return; }
- // Load the string for formatting column/row text output - LoadString(Globals.hInstance, STRING_LINE_COLUMN, Globals.szStatusBarLineCol, MAX_PATH-1); - - // Set the status bar for single-text output + /* Load the string for formatting column/row text output */ + LoadString(Globals.hInstance, STRING_LINE_COLUMN, Globals.szStatusBarLineCol, MAX_PATH - 1); + + /* Set the status bar for single-text output */ SendMessage(Globals.hStatusBar, SB_SIMPLE, (WPARAM)TRUE, (LPARAM)0); }
- // Set status bar visiblity according to the settings. - if (Globals.bWrapLongLines == TRUE || - Globals.bShowStatusBar == FALSE) + /* Set status bar visiblity according to the settings. */ + if (Globals.bWrapLongLines == TRUE || Globals.bShowStatusBar == FALSE) { bStatusBarVisible = FALSE; ShowWindow(Globals.hStatusBar, SW_HIDE); @@ -775,7 +780,7 @@ SendMessage(Globals.hStatusBar, WM_SIZE, 0, 0); }
- // Set check state in show status bar item. + /* Set check state in show status bar item. */ if (bStatusBarVisible) { CheckMenuItem(Globals.hMenu, CMD_STATUSBAR, MF_BYCOMMAND | MF_CHECKED); @@ -785,69 +790,72 @@ CheckMenuItem(Globals.hMenu, CMD_STATUSBAR, MF_BYCOMMAND | MF_UNCHECKED); }
- // Update menu mar with the previous changes + /* Update menu mar with the previous changes */ DrawMenuBar(Globals.hMainWnd);
- // Sefety test is edit control exists + /* Sefety test is edit control exists */ if (Globals.hEdit != NULL) { - // Retrieve the sizes of the controls + /* Retrieve the sizes of the controls */ GetClientRect(Globals.hMainWnd, &rc); GetClientRect(Globals.hStatusBar, &rcstatus);
- // If status bar is currently visible, update dimensions of edir control + /* If status bar is currently visible, update dimensions of edit control */ if (bStatusBarVisible) rc.bottom -= (rcstatus.bottom - rcstatus.top);
- // Resize edit control to right size. - MoveWindow(Globals.hEdit, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); - } - - // Update content with current row/column text + /* Resize edit control to right size. */ + MoveWindow(Globals.hEdit, + rc.left, + rc.top, + rc.right - rc.left, + rc.bottom - rc.top, + TRUE); + } + + /* Update content with current row/column text */ DIALOG_StatusBarUpdateCaretPos(); }
VOID DoCreateEditWindow(VOID) { - DWORD dwStyle; - int iSize; + DWORD dwStyle; + int iSize; LPTSTR pTemp = NULL; - BOOL bModified = FALSE; + BOOL bModified = FALSE;
iSize = 0;
- // If the edit control already exists, try to save its content + /* If the edit control already exists, try to save its content */ if (Globals.hEdit != NULL) { - // number of chars currently written into the editor. + /* number of chars currently written into the editor. */ iSize = GetWindowTextLength(Globals.hEdit); - if (iSize) { - // Allocates temporary buffer. + /* Allocates temporary buffer. */ pTemp = HeapAlloc(GetProcessHeap(), 0, (iSize + 1) * sizeof(TCHAR)); - if (!pTemp) { ShowLastError(); return; }
- // Recover the text into the control. + /* Recover the text into the control. */ GetWindowText(Globals.hEdit, pTemp, iSize + 1);
if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0)) bModified = TRUE; }
- // Restore original window procedure + /* Restore original window procedure */ SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)Globals.EditProc);
- // Destroy the edit control + /* Destroy the edit control */ DestroyWindow(Globals.hEdit); }
- // Update wrap status into the main menu and recover style flags + /* Update wrap status into the main menu and recover style flags */ if (Globals.bWrapLongLines) { dwStyle = EDIT_STYLE_WRAP; @@ -857,23 +865,22 @@ EnableMenuItem(Globals.hMenu, CMD_STATUSBAR, MF_BYCOMMAND | MF_ENABLED); }
- // Update previous changes + /* Update previous changes */ DrawMenuBar(Globals.hMainWnd);
- // Create the new edit control - Globals.hEdit = CreateWindowEx( - WS_EX_CLIENTEDGE, - EDIT_CLASS, - NULL, - dwStyle, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, - Globals.hMainWnd, - NULL, - Globals.hInstance, - NULL); + /* Create the new edit control */ + Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, + EDIT_CLASS, + NULL, + dwStyle, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + Globals.hMainWnd, + NULL, + Globals.hInstance, + NULL);
if (Globals.hEdit == NULL) { @@ -884,7 +891,7 @@ SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, FALSE); SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0);
- // If some text was previously saved, restore it. + /* If some text was previously saved, restore it. */ if (iSize != 0) { SetWindowText(Globals.hEdit, pTemp); @@ -894,13 +901,15 @@ SendMessage(Globals.hEdit, EM_SETMODIFY, TRUE, 0); }
- // Sub-class a new window callback for row/column detection. - Globals.EditProc = (WNDPROC) SetWindowLongPtr(Globals.hEdit, GWLP_WNDPROC, (LONG_PTR)EDIT_WndProc); - - // Create/update status bar + /* Sub-class a new window callback for row/column detection. */ + Globals.EditProc = (WNDPROC)SetWindowLongPtr(Globals.hEdit, + GWLP_WNDPROC, + (LONG_PTR)EDIT_WndProc); + + /* Create/update status bar */ DoCreateStatusBar();
- // Finally shows new edit control and set focus into it. + /* Finally shows new edit control and set focus into it. */ ShowWindow(Globals.hEdit, SW_SHOW); SetFocus(Globals.hEdit); } @@ -908,30 +917,29 @@ VOID DIALOG_EditWrap(VOID) { Globals.bWrapLongLines = !Globals.bWrapLongLines; - DoCreateEditWindow(); }
VOID DIALOG_SelectFont(VOID) { CHOOSEFONT cf; - LOGFONT lf=Globals.lfFont; + LOGFONT lf = Globals.lfFont;
ZeroMemory( &cf, sizeof(cf) ); - cf.lStructSize=sizeof(cf); - cf.hwndOwner=Globals.hMainWnd; - cf.lpLogFont=&lf; - cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; - - if( ChooseFont(&cf) ) - { - HFONT currfont=Globals.hFont; - - Globals.hFont=CreateFontIndirect( &lf ); - Globals.lfFont=lf; - SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE ); - if( currfont!=NULL ) - DeleteObject( currfont ); + cf.lStructSize = sizeof(cf); + cf.hwndOwner = Globals.hMainWnd; + cf.lpLogFont = &lf; + cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; + + if (ChooseFont(&cf)) + { + HFONT currfont = Globals.hFont; + + Globals.hFont = CreateFontIndirect(&lf); + Globals.lfFont = lf; + SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE); + if (currfont != NULL) + DeleteObject(currfont); } }
@@ -940,20 +948,20 @@ static VOID DIALOG_SearchDialog(FINDPROC pfnProc) { ZeroMemory(&Globals.find, sizeof(Globals.find)); - Globals.find.lStructSize = sizeof(Globals.find); - Globals.find.hwndOwner = Globals.hMainWnd; - Globals.find.hInstance = Globals.hInstance; - Globals.find.lpstrFindWhat = Globals.szFindText; - Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText); + Globals.find.lStructSize = sizeof(Globals.find); + Globals.find.hwndOwner = Globals.hMainWnd; + Globals.find.hInstance = Globals.hInstance; + Globals.find.lpstrFindWhat = Globals.szFindText; + Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText); Globals.find.lpstrReplaceWith = Globals.szReplaceText; - Globals.find.wReplaceWithLen = SIZEOF(Globals.szReplaceText); - Globals.find.Flags = FR_DOWN; + Globals.find.wReplaceWithLen = SIZEOF(Globals.szReplaceText); + Globals.find.Flags = FR_DOWN;
/* We only need to create the modal FindReplace dialog which will */ /* notify us of incoming events using hMainWnd Window Messages */
Globals.hFindReplaceDlg = pfnProc(&Globals.find); - assert(Globals.hFindReplaceDlg !=0); + assert(Globals.hFindReplaceDlg != 0); }
VOID DIALOG_Search(VOID) @@ -964,9 +972,9 @@ VOID DIALOG_SearchNext(VOID) { if (Globals.find.lpstrFindWhat != NULL) - NOTEPAD_FindNext(&Globals.find, FALSE, TRUE); + NOTEPAD_FindNext(&Globals.find, FALSE, TRUE); else - DIALOG_Search(); + DIALOG_Search(); }
VOID DIALOG_Replace(VOID) @@ -974,7 +982,9 @@ DIALOG_SearchDialog(ReplaceText); }
-static INT_PTR CALLBACK DIALOG_GoTo_DialogProc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam) +static INT_PTR +CALLBACK +DIALOG_GoTo_DialogProc(HWND hwndDialog, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL bResult = FALSE; HWND hTextBox; @@ -1031,8 +1041,11 @@ nLine++; }
- nLine = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(DIALOG_GOTO), - Globals.hMainWnd, DIALOG_GoTo_DialogProc, nLine); + nLine = DialogBoxParam(Globals.hInstance, + MAKEINTRESOURCE(DIALOG_GOTO), + Globals.hMainWnd, + DIALOG_GoTo_DialogProc, + nLine);
if (nLine >= 1) { @@ -1055,9 +1068,9 @@
SendMessage(Globals.hEdit, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwSize); line = SendMessage(Globals.hEdit, EM_LINEFROMCHAR, (WPARAM)dwStart, 0); - col = dwStart - SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0); - - _stprintf(buff, Globals.szStatusBarLineCol, line+1, col+1); + col = dwStart - SendMessage(Globals.hEdit, EM_LINEINDEX, (WPARAM)line, 0); + + _stprintf(buff, Globals.szStatusBarLineCol, line + 1, col + 1); SendMessage(Globals.hStatusBar, SB_SETTEXT, SB_SIMPLEID, (LPARAM)buff); }
@@ -1075,7 +1088,7 @@
VOID DIALOG_HelpSearch(VOID) { - /* Search Help */ + /* Search Help */ }
VOID DIALOG_HelpHelp(VOID) @@ -1086,11 +1099,12 @@ #ifdef _MSC_VER #pragma warning(disable : 4100) #endif -INT_PTR CALLBACK +INT_PTR +CALLBACK AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - HWND hLicenseEditWnd; - TCHAR *strLicense; + HWND hLicenseEditWnd; + TCHAR *strLicense;
switch (message) { @@ -1098,7 +1112,7 @@
hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE);
- /* 0x1000 should be enought */ + /* 0x1000 should be enough */ strLicense = (TCHAR *)_alloca(0x1000); LoadString(GetModuleHandle(NULL), STRING_LICENSE, strLicense, 0x1000);
@@ -1120,8 +1134,6 @@ return 0; }
- - VOID DIALOG_HelpAboutWine(VOID) { TCHAR szNotepad[MAX_STRING_LEN]; @@ -1131,7 +1143,6 @@ ShellAbout(Globals.hMainWnd, szNotepad, 0, notepadIcon); DeleteObject(notepadIcon); } -
/*********************************************************************** * @@ -1139,19 +1150,21 @@ */ VOID DIALOG_FilePageSetup(void) { - DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP), - Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc); -} - + DialogBox(Globals.hInstance, + MAKEINTRESOURCE(DIALOG_PAGESETUP), + Globals.hMainWnd, + DIALOG_PAGESETUP_DlgProc); +}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DIALOG_PAGESETUP_DlgProc */
-static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - +static INT_PTR +WINAPI +DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ switch (msg) { case WM_COMMAND:
Modified: trunk/reactos/base/applications/notepad/license.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/l... ============================================================================== --- trunk/reactos/base/applications/notepad/license.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/license.c [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -22,17 +22,21 @@
VOID WineLicense(HWND Wnd) { - /* FIXME: should load strings from resources */ - LICENSE *License = &WineLicense_En; - MessageBoxA(Wnd, License->License, License->LicenseCaption, - MB_ICONINFORMATION | MB_OK); + /* FIXME: should load strings from resources */ + LICENSE *License = &WineLicense_En; + MessageBoxA(Wnd, + License->License, + License->LicenseCaption, + MB_ICONINFORMATION | MB_OK); }
VOID WineWarranty(HWND Wnd) { - /* FIXME: should load strings from resources */ - LICENSE *License = &WineLicense_En; - MessageBoxA(Wnd, License->Warranty, License->WarrantyCaption, - MB_ICONEXCLAMATION | MB_OK); + /* FIXME: should load strings from resources */ + LICENSE *License = &WineLicense_En; + MessageBoxA(Wnd, + License->Warranty, + License->WarrantyCaption, + MB_ICONEXCLAMATION | MB_OK); }
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 [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/main.c [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -58,47 +58,50 @@ { switch (wParam) { - case CMD_NEW: DIALOG_FileNew(); break; - case CMD_OPEN: DIALOG_FileOpen(); break; - case CMD_SAVE: DIALOG_FileSave(); break; - case CMD_SAVE_AS: DIALOG_FileSaveAs(); break; - case CMD_PRINT: DIALOG_FilePrint(); break; - case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break; - case CMD_PRINTER_SETUP: DIALOG_FilePrinterSetup();break; - case CMD_EXIT: DIALOG_FileExit(); break; - - case CMD_UNDO: DIALOG_EditUndo(); break; - case CMD_CUT: DIALOG_EditCut(); break; - case CMD_COPY: DIALOG_EditCopy(); break; - case CMD_PASTE: DIALOG_EditPaste(); break; - case CMD_DELETE: DIALOG_EditDelete(); break; - case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break; - case CMD_TIME_DATE: DIALOG_EditTimeDate();break; - - case CMD_SEARCH: DIALOG_Search(); break; - case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break; - case CMD_REPLACE: DIALOG_Replace(); break; - case CMD_GOTO: DIALOG_GoTo(); break; - - case CMD_WRAP: DIALOG_EditWrap(); break; - case CMD_FONT: DIALOG_SelectFont(); break; - - case CMD_STATUSBAR: DIALOG_ViewStatusBar(); break; - - case CMD_HELP_CONTENTS: DIALOG_HelpContents(); break; - case CMD_HELP_SEARCH: DIALOG_HelpSearch(); break; - case CMD_HELP_ON_HELP: DIALOG_HelpHelp(); break; - case CMD_ABOUT: DialogBox(GetModuleHandle(NULL), - MAKEINTRESOURCE(IDD_ABOUTBOX), - Globals.hMainWnd, - AboutDialogProc); - break; - case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break; + case CMD_NEW: DIALOG_FileNew(); break; + case CMD_OPEN: DIALOG_FileOpen(); break; + case CMD_SAVE: DIALOG_FileSave(); break; + case CMD_SAVE_AS: DIALOG_FileSaveAs(); break; + case CMD_PRINT: DIALOG_FilePrint(); break; + case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break; + case CMD_PRINTER_SETUP: DIALOG_FilePrinterSetup(); break; + case CMD_EXIT: DIALOG_FileExit(); break; + + case CMD_UNDO: DIALOG_EditUndo(); break; + case CMD_CUT: DIALOG_EditCut(); break; + case CMD_COPY: DIALOG_EditCopy(); break; + case CMD_PASTE: DIALOG_EditPaste(); break; + case CMD_DELETE: DIALOG_EditDelete(); break; + case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break; + case CMD_TIME_DATE: DIALOG_EditTimeDate(); break; + + case CMD_SEARCH: DIALOG_Search(); break; + case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break; + case CMD_REPLACE: DIALOG_Replace(); break; + case CMD_GOTO: DIALOG_GoTo(); break; + + case CMD_WRAP: DIALOG_EditWrap(); break; + case CMD_FONT: DIALOG_SelectFont(); break; + + case CMD_STATUSBAR: DIALOG_ViewStatusBar(); break; + + case CMD_HELP_CONTENTS: DIALOG_HelpContents(); break; + case CMD_HELP_SEARCH: DIALOG_HelpSearch(); break; + case CMD_HELP_ON_HELP: DIALOG_HelpHelp(); break; + + case CMD_ABOUT: + DialogBox(GetModuleHandle(NULL), + MAKEINTRESOURCE(IDD_ABOUTBOX), + Globals.hMainWnd, + AboutDialogProc); + break; + + case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
default: - break; - } - return 0; + break; + } + return 0; }
/*********************************************************************** @@ -106,7 +109,8 @@ * NOTEPAD_FindTextAt */
-static BOOL NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition) +static BOOL +NOTEPAD_FindTextAt(FINDREPLACE *pFindReplace, LPCTSTR pszText, int iTextLength, DWORD dwPosition) { BOOL bMatches; size_t iTargetLength; @@ -256,11 +260,11 @@ 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; + 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; + p += LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN) + 1; _tcscpy(p, all_files); p += SIZEOF(all_files); *p = '\0'; @@ -328,10 +332,12 @@ * * NOTEPAD_WndProc */ -static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, - LPARAM lParam) -{ - switch (msg) { +static LRESULT +WINAPI +NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + {
case WM_CREATE: Globals.hMenu = GetMenu(hWnd); @@ -371,8 +377,7 @@
case WM_SIZE: { - if (Globals.bShowStatusBar == TRUE && - Globals.bWrapLongLines == FALSE) + if (Globals.bShowStatusBar == TRUE && Globals.bWrapLongLines == FALSE) { RECT rcStatusBar; HDWP hdwp; @@ -384,24 +389,45 @@ if (hdwp == NULL) break;
- hdwp = DeferWindowPos(hdwp, Globals.hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam) - (rcStatusBar.bottom - rcStatusBar.top), SWP_NOZORDER | SWP_NOMOVE); + hdwp = DeferWindowPos(hdwp, + Globals.hEdit, + NULL, + 0, + 0, + LOWORD(lParam), + HIWORD(lParam) - (rcStatusBar.bottom - rcStatusBar.top), + SWP_NOZORDER | SWP_NOMOVE); + if (hdwp == NULL) break;
- hdwp = DeferWindowPos(hdwp, Globals.hStatusBar, NULL, 0, 0, LOWORD(lParam), LOWORD(wParam), SWP_NOZORDER); + hdwp = DeferWindowPos(hdwp, + Globals.hStatusBar, + NULL, + 0, + 0, + LOWORD(lParam), + LOWORD(wParam), + SWP_NOZORDER);
if (hdwp != NULL) EndDeferWindowPos(hdwp); } else - SetWindowPos(Globals.hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOZORDER | SWP_NOMOVE); - - break; - } - - // The entire client area is covered by edit control and by - // the status bar. So there is no need to erase main background. - // This resolves the horrible fliker effect during windows resizes. + SetWindowPos(Globals.hEdit, + NULL, + 0, + 0, + LOWORD(lParam), + HIWORD(lParam), + SWP_NOZORDER | SWP_NOMOVE); + + break; + } + + /* The entire client area is covered by edit control and by + * the status bar. So there is no need to erase main background. + * This resolves the horrible flicker effect during windows resizes. */ case WM_ERASEBKGND: return 1;
@@ -447,19 +473,21 @@
static int AlertFileDoesNotExist(LPCTSTR szFileName) { - int nResult; - TCHAR szMessage[MAX_STRING_LEN]; - TCHAR szResource[MAX_STRING_LEN]; - - LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szResource, SIZEOF(szResource)); - wsprintf(szMessage, szResource, szFileName); - - LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); - - nResult = MessageBox(Globals.hMainWnd, szMessage, szResource, - MB_ICONEXCLAMATION | MB_YESNO); - - return(nResult); + int nResult; + TCHAR szMessage[MAX_STRING_LEN]; + TCHAR szResource[MAX_STRING_LEN]; + + LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szResource, SIZEOF(szResource)); + wsprintf(szMessage, szResource, szFileName); + + LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource)); + + nResult = MessageBox(Globals.hMainWnd, + szMessage, + szResource, + MB_ICONEXCLAMATION | MB_YESNO); + + return(nResult); }
static BOOL HandleCommandLine(LPTSTR cmdline) @@ -553,53 +581,57 @@ */ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int show) { - MSG msg; - HACCEL hAccel; - WNDCLASSEX wndclass; - HMONITOR monitor; + MSG msg; + HACCEL hAccel; + WNDCLASSEX wndclass; + HMONITOR monitor; MONITORINFO info; - INT x, y; + INT x, y;
static const TCHAR className[] = _T("NPClass"); - static const TCHAR winName[] = _T("Notepad"); + static const TCHAR winName[] = _T("Notepad");
switch (GetUserDefaultUILanguage()) - { + { case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT): - SetProcessDefaultLayout(LAYOUT_RTL); - break; + SetProcessDefaultLayout(LAYOUT_RTL); + break;
default: - break; - } + break; + }
UNREFERENCED_PARAMETER(prev);
- aFINDMSGSTRING = (ATOM) RegisterWindowMessage(FINDMSGSTRING); + aFINDMSGSTRING = (ATOM)RegisterWindowMessage(FINDMSGSTRING);
ZeroMemory(&Globals, sizeof(Globals)); - Globals.hInstance = hInstance; + Globals.hInstance = hInstance; LoadSettings();
ZeroMemory(&wndclass, sizeof(wndclass)); - wndclass.cbSize = sizeof(wndclass); - wndclass.lpfnWndProc = NOTEPAD_WndProc; - wndclass.hInstance = Globals.hInstance; - wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NPICON)); - wndclass.hCursor = LoadCursor(0, IDC_ARROW); + wndclass.cbSize = sizeof(wndclass); + wndclass.lpfnWndProc = NOTEPAD_WndProc; + wndclass.hInstance = Globals.hInstance; + wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NPICON)); + wndclass.hCursor = LoadCursor(0, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); + wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); wndclass.lpszClassName = className; - wndclass.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_NPICON), - IMAGE_ICON, 16, 16, 0); + wndclass.hIconSm = (HICON)LoadImage(hInstance, + MAKEINTRESOURCE(IDI_NPICON), + IMAGE_ICON, + 16, + 16, + 0);
if (!RegisterClassEx(&wndclass)) return FALSE;
/* Setup windows */
- monitor = MonitorFromRect( &Globals.main_rect, MONITOR_DEFAULTTOPRIMARY ); + monitor = MonitorFromRect(&Globals.main_rect, MONITOR_DEFAULTTOPRIMARY); info.cbSize = sizeof(info); - GetMonitorInfoW( monitor, &info ); + GetMonitorInfoW(monitor, &info);
x = Globals.main_rect.left; y = Globals.main_rect.top; @@ -609,11 +641,17 @@ Globals.main_rect.bottom < info.rcWork.top) x = y = CW_USEDEFAULT;
- Globals.hMainWnd = - CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, - x, y, Globals.main_rect.right - Globals.main_rect.left, - Globals.main_rect.bottom - Globals.main_rect.top, - NULL, NULL, Globals.hInstance, NULL); + Globals.hMainWnd = CreateWindow(className, + winName, + WS_OVERLAPPEDWINDOW, + x, + y, + Globals.main_rect.right - Globals.main_rect.left, + Globals.main_rect.bottom - Globals.main_rect.top, + NULL, + NULL, + Globals.hInstance, + NULL); if (!Globals.hMainWnd) { ShowLastError(); @@ -636,7 +674,7 @@ return 0; }
- hAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE(ID_ACCEL) ); + hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
while (GetMessage(&msg, 0, 0, 0)) {
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 [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/main.h [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -33,10 +33,10 @@
#define MAX_STRING_LEN 255
-#define ENCODING_ANSI 0 -#define ENCODING_UNICODE 1 -#define ENCODING_UNICODE_BE 2 -#define ENCODING_UTF8 3 +#define ENCODING_ANSI 0 +#define ENCODING_UNICODE 1 +#define ENCODING_UNICODE_BE 2 +#define ENCODING_UTF8 3
#define EOLN_CRLF 0 #define EOLN_LF 1 @@ -44,34 +44,34 @@
typedef struct { - HINSTANCE hInstance; - HWND hMainWnd; - HWND hFindReplaceDlg; - HWND hEdit; - HWND hStatusBar; - HFONT hFont; /* Font used by the edit control */ - HMENU hMenu; - LOGFONT lfFont; - BOOL bWrapLongLines; - BOOL bShowStatusBar; - 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 szStatusBarLineCol[MAX_PATH]; - int iEncoding; - int iEoln; + HINSTANCE hInstance; + HWND hMainWnd; + HWND hFindReplaceDlg; + HWND hEdit; + HWND hStatusBar; + HFONT hFont; /* Font used by the edit control */ + HMENU hMenu; + LOGFONT lfFont; + BOOL bWrapLongLines; + BOOL bShowStatusBar; + 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 szStatusBarLineCol[MAX_PATH]; + int iEncoding; + int iEoln;
- FINDREPLACE find; - WNDPROC EditProc; - RECT main_rect; + FINDREPLACE find; + WNDPROC EditProc; + RECT main_rect; } NOTEPAD_GLOBALS;
extern NOTEPAD_GLOBALS Globals;
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 [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/settings.c [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -29,178 +29,179 @@
static LONG HeightFromPointSize(DWORD dwPointSize) { - LONG lHeight; - HDC hDC; - - hDC = GetDC(NULL); - lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720); - ReleaseDC(NULL, hDC); - - return lHeight; + LONG lHeight; + HDC hDC; + + hDC = GetDC(NULL); + lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720); + ReleaseDC(NULL, hDC); + + return lHeight; }
static DWORD PointSizeFromHeight(LONG lHeight) { - DWORD dwPointSize; - HDC hDC; - - hDC = GetDC(NULL); - dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY)); - ReleaseDC(NULL, hDC); - - /* round to nearest multiple of 10 */ - dwPointSize += 5; - dwPointSize -= dwPointSize % 10; - - return dwPointSize; -} - -static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, - LPVOID pvResult, DWORD dwResultSize) -{ - DWORD dwType, cbData; - LPVOID *pTemp = _alloca(dwResultSize); - - ZeroMemory(pTemp, dwResultSize); - - cbData = dwResultSize; - if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS) - return FALSE; - - if (dwType != dwExpectedType) - return FALSE; - - memcpy(pvResult, pTemp, cbData); - return TRUE; + DWORD dwPointSize; + HDC hDC; + + hDC = GetDC(NULL); + dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY)); + ReleaseDC(NULL, hDC); + + /* round to nearest multiple of 10 */ + dwPointSize += 5; + dwPointSize -= dwPointSize % 10; + + return dwPointSize; +} + +static BOOL +QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, + LPVOID pvResult, DWORD dwResultSize) +{ + DWORD dwType, cbData; + LPVOID *pTemp = _alloca(dwResultSize); + + ZeroMemory(pTemp, dwResultSize); + + cbData = dwResultSize; + if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS) + return FALSE; + + if (dwType != dwExpectedType) + return FALSE; + + memcpy(pvResult, pTemp, cbData); + return TRUE; }
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult) { - return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult)); + return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult)); }
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult) { - DWORD dwResult; - if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult))) - return FALSE; - if (dwResult >= 0x100) - return FALSE; - *pbResult = (BYTE) dwResult; - return TRUE; + DWORD dwResult; + if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult))) + return FALSE; + if (dwResult >= 0x100) + return FALSE; + *pbResult = (BYTE) dwResult; + return TRUE; }
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult) { - DWORD dwResult; - if (!QueryDword(hKey, pszValueName, &dwResult)) - return FALSE; - *pbResult = dwResult ? TRUE : FALSE; - return TRUE; + DWORD dwResult; + if (!QueryDword(hKey, pszValueName, &dwResult)) + return FALSE; + *pbResult = dwResult ? TRUE : FALSE; + return TRUE; }
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize) { - return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(TCHAR)); + return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(TCHAR)); }
void LoadSettings(void) { - HKEY hKey = NULL; - HFONT hFont; - DWORD dwPointSize = 0; - INT base_length, dx, dy; - - base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))? - GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); - - dx = (INT)(base_length * .95); - dy = dx * 3 / 4; - SetRect( &Globals.main_rect, 0, 0, dx, dy ); - - if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) - { - 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); - QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); - - QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); - QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); - QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx); - QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy); + HKEY hKey = NULL; + HFONT hFont; + DWORD dwPointSize = 0; + INT base_length, dx, dy; + + base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN)) ? + GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); + + dx = (INT)(base_length * .95); + dy = dx * 3 / 4; + SetRect(&Globals.main_rect, 0, 0, dx, dy); + + if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS) + { + 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); + QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); + + QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); + QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); + QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx); + QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy);
Globals.main_rect.right = Globals.main_rect.left + dx; Globals.main_rect.bottom = Globals.main_rect.top + dy;
- Globals.bShowStatusBar = !Globals.bShowStatusBar; /* invert value becuase DIALOG_ViewStatusBar will be called to show it*/ - - if (dwPointSize != 0) - Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); - - RegCloseKey(hKey); - } - - hFont = CreateFontIndirect(&Globals.lfFont); - if (hFont) - { - if (Globals.hFont) - DeleteObject(Globals.hFont); - Globals.hFont = hFont; - } + /* invert value because DIALOG_ViewStatusBar will be called to show it */ + Globals.bShowStatusBar = !Globals.bShowStatusBar; + + if (dwPointSize != 0) + Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); + + RegCloseKey(hKey); + } + + hFont = CreateFontIndirect(&Globals.lfFont); + if (hFont) + { + if (Globals.hFont) + DeleteObject(Globals.hFont); + Globals.hFont = hFont; + } }
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue) { - return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS; + return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS; }
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue) { - return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS; + return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS; }
void SaveSettings(void) { - HKEY hKey; - DWORD dwDisposition; + HKEY hKey; + DWORD dwDisposition;
GetWindowRect(Globals.hMainWnd, &Globals.main_rect);
- if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) - == ERROR_SUCCESS) - { - 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); - SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0); - SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left); - SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top); - SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left); - SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top); - RegCloseKey(hKey); - } - -} + if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) + == ERROR_SUCCESS) + { + 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); + SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0); + SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left); + SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top); + SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left); + SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top); + RegCloseKey(hKey); + } +}
Modified: trunk/reactos/base/applications/notepad/text.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/t... ============================================================================== --- trunk/reactos/base/applications/notepad/text.c [iso-8859-1] (original) +++ trunk/reactos/base/applications/notepad/text.c [iso-8859-1] Thu Jan 8 13:20:02 2015 @@ -24,362 +24,363 @@
static BOOL Append(LPWSTR *ppszText, DWORD *pdwTextLen, LPCWSTR pszAppendText, DWORD dwAppendLen) { - LPWSTR pszNewText; - - if (dwAppendLen > 0) - { - if (*ppszText) - { - pszNewText = (LPWSTR) HeapReAlloc(GetProcessHeap(), 0, *ppszText, (*pdwTextLen + dwAppendLen) * sizeof(WCHAR)); - } - else - { - pszNewText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwAppendLen * sizeof(WCHAR)); - } - - if (!pszNewText) - return FALSE; - - memcpy(pszNewText + *pdwTextLen, pszAppendText, dwAppendLen * sizeof(WCHAR)); - *ppszText = pszNewText; - *pdwTextLen += dwAppendLen; - } - return TRUE; + LPWSTR pszNewText; + + if (dwAppendLen > 0) + { + if (*ppszText) + { + pszNewText = (LPWSTR) HeapReAlloc(GetProcessHeap(), 0, *ppszText, (*pdwTextLen + dwAppendLen) * sizeof(WCHAR)); + } + else + { + pszNewText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, dwAppendLen * sizeof(WCHAR)); + } + + if (!pszNewText) + return FALSE; + + memcpy(pszNewText + *pdwTextLen, pszAppendText, dwAppendLen * sizeof(WCHAR)); + *ppszText = pszNewText; + *pdwTextLen += dwAppendLen; + } + return TRUE; }
-BOOL ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, int *piEncoding, int *piEoln) +BOOL +ReadText(HANDLE hFile, LPWSTR *ppszText, DWORD *pdwTextLen, int *piEncoding, int *piEoln) { - DWORD dwSize; - LPBYTE pBytes = NULL; - LPWSTR pszText; - LPWSTR pszAllocText = NULL; - DWORD dwPos, i; - DWORD dwCharCount; - BOOL bSuccess = FALSE; - BYTE b = 0; - int iEncoding = ENCODING_ANSI; - int iCodePage = 0; - WCHAR szCrlf[2] = { '\r', '\n' }; - DWORD adwEolnCount[3] = { 0, 0, 0 }; - - *ppszText = NULL; - *pdwTextLen = 0; - - dwSize = GetFileSize(hFile, NULL); - if (dwSize == INVALID_FILE_SIZE) - goto done; - - pBytes = HeapAlloc(GetProcessHeap(), 0, dwSize + 2); - if (!pBytes) - goto done; - - if (!ReadFile(hFile, pBytes, dwSize, &dwSize, NULL)) - goto done; - dwPos = 0; - - /* Make sure that there is a NUL character at the end, in any encoding */ - pBytes[dwSize + 0] = '\0'; - pBytes[dwSize + 1] = '\0'; - - /* Look for Byte Order Marks */ - if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE)) - { - iEncoding = ENCODING_UNICODE; - dwPos += 2; - } - else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF)) - { - iEncoding = ENCODING_UNICODE_BE; - dwPos += 2; - } - else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF)) - { - iEncoding = ENCODING_UTF8; - dwPos += 3; - } - - switch(iEncoding) - { - case ENCODING_UNICODE_BE: - for (i = dwPos; i < dwSize-1; i += 2) - { - b = pBytes[i+0]; - pBytes[i+0] = pBytes[i+1]; - pBytes[i+1] = b; - } - /* fall through */ - - case ENCODING_UNICODE: - pszText = (LPWSTR) &pBytes[dwPos]; - dwCharCount = (dwSize - dwPos) / sizeof(WCHAR); - break; - - case ENCODING_ANSI: - case ENCODING_UTF8: - if (iEncoding == ENCODING_ANSI) - iCodePage = CP_ACP; - else if (iEncoding == ENCODING_UTF8) - iCodePage = CP_UTF8; - - if ((dwSize - dwPos) > 0) - { - dwCharCount = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, NULL, 0); - if (dwCharCount == 0) - goto done; - } - else - { - /* special case for files with no characters (other than BOMs) */ - dwCharCount = 0; - } - - pszAllocText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (dwCharCount + 1) * sizeof(WCHAR)); - if (!pszAllocText) - goto done; - - if ((dwSize - dwPos) > 0) - { - if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, pszAllocText, dwCharCount)) - goto done; - } - - pszAllocText[dwCharCount] = '\0'; - pszText = pszAllocText; - break; - } - - dwPos = 0; - for (i = 0; i < dwCharCount; i++) - { - switch(pszText[i]) - { - case '\r': - if ((i < dwCharCount-1) && (pszText[i+1] == '\n')) - { - i++; - adwEolnCount[EOLN_CRLF]++; - break; - } - /* fall through */ - - case '\n': - if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos)) - return FALSE; - if (!Append(ppszText, pdwTextLen, szCrlf, sizeof(szCrlf) / sizeof(szCrlf[0]))) - return FALSE; - dwPos = i + 1; - - if (pszText[i] == '\r') - adwEolnCount[EOLN_CR]++; - else - adwEolnCount[EOLN_LF]++; - break; - - case '\0': - pszText[i] = ' '; - break; - } - } - - if (!*ppszText && (pszText == pszAllocText)) - { - /* special case; don't need to reallocate */ - *ppszText = pszAllocText; - *pdwTextLen = dwCharCount; - pszAllocText = NULL; - } - else - { - /* append last remaining text */ - if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos + 1)) - return FALSE; - } - - /* chose which eoln to use */ - *piEoln = EOLN_CRLF; - if (adwEolnCount[EOLN_LF] > adwEolnCount[*piEoln]) - *piEoln = EOLN_LF; - if (adwEolnCount[EOLN_CR] > adwEolnCount[*piEoln]) - *piEoln = EOLN_CR; - *piEncoding = iEncoding; - - bSuccess = TRUE; + DWORD dwSize; + LPBYTE pBytes = NULL; + LPWSTR pszText; + LPWSTR pszAllocText = NULL; + DWORD dwPos, i; + DWORD dwCharCount; + BOOL bSuccess = FALSE; + BYTE b = 0; + int iEncoding = ENCODING_ANSI; + int iCodePage = 0; + WCHAR szCrlf[2] = {'\r', '\n'}; + DWORD adwEolnCount[3] = {0, 0, 0}; + + *ppszText = NULL; + *pdwTextLen = 0; + + dwSize = GetFileSize(hFile, NULL); + if (dwSize == INVALID_FILE_SIZE) + goto done; + + pBytes = HeapAlloc(GetProcessHeap(), 0, dwSize + 2); + if (!pBytes) + goto done; + + if (!ReadFile(hFile, pBytes, dwSize, &dwSize, NULL)) + goto done; + dwPos = 0; + + /* Make sure that there is a NUL character at the end, in any encoding */ + pBytes[dwSize + 0] = '\0'; + pBytes[dwSize + 1] = '\0'; + + /* Look for Byte Order Marks */ + if ((dwSize >= 2) && (pBytes[0] == 0xFF) && (pBytes[1] == 0xFE)) + { + iEncoding = ENCODING_UNICODE; + dwPos += 2; + } + else if ((dwSize >= 2) && (pBytes[0] == 0xFE) && (pBytes[1] == 0xFF)) + { + iEncoding = ENCODING_UNICODE_BE; + dwPos += 2; + } + else if ((dwSize >= 3) && (pBytes[0] == 0xEF) && (pBytes[1] == 0xBB) && (pBytes[2] == 0xBF)) + { + iEncoding = ENCODING_UTF8; + dwPos += 3; + } + + switch(iEncoding) + { + case ENCODING_UNICODE_BE: + for (i = dwPos; i < dwSize-1; i += 2) + { + b = pBytes[i+0]; + pBytes[i+0] = pBytes[i+1]; + pBytes[i+1] = b; + } + /* fall through */ + + case ENCODING_UNICODE: + pszText = (LPWSTR) &pBytes[dwPos]; + dwCharCount = (dwSize - dwPos) / sizeof(WCHAR); + break; + + case ENCODING_ANSI: + case ENCODING_UTF8: + if (iEncoding == ENCODING_ANSI) + iCodePage = CP_ACP; + else if (iEncoding == ENCODING_UTF8) + iCodePage = CP_UTF8; + + if ((dwSize - dwPos) > 0) + { + dwCharCount = MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, NULL, 0); + if (dwCharCount == 0) + goto done; + } + else + { + /* special case for files with no characters (other than BOMs) */ + dwCharCount = 0; + } + + pszAllocText = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, (dwCharCount + 1) * sizeof(WCHAR)); + if (!pszAllocText) + goto done; + + if ((dwSize - dwPos) > 0) + { + if (!MultiByteToWideChar(iCodePage, 0, (LPCSTR)&pBytes[dwPos], dwSize - dwPos, pszAllocText, dwCharCount)) + goto done; + } + + pszAllocText[dwCharCount] = '\0'; + pszText = pszAllocText; + break; + } + + dwPos = 0; + for (i = 0; i < dwCharCount; i++) + { + switch(pszText[i]) + { + case '\r': + if ((i < dwCharCount-1) && (pszText[i+1] == '\n')) + { + i++; + adwEolnCount[EOLN_CRLF]++; + break; + } + /* fall through */ + + case '\n': + if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos)) + return FALSE; + if (!Append(ppszText, pdwTextLen, szCrlf, sizeof(szCrlf) / sizeof(szCrlf[0]))) + return FALSE; + dwPos = i + 1; + + if (pszText[i] == '\r') + adwEolnCount[EOLN_CR]++; + else + adwEolnCount[EOLN_LF]++; + break; + + case '\0': + pszText[i] = ' '; + break; + } + } + + if (!*ppszText && (pszText == pszAllocText)) + { + /* special case; don't need to reallocate */ + *ppszText = pszAllocText; + *pdwTextLen = dwCharCount; + pszAllocText = NULL; + } + else + { + /* append last remaining text */ + if (!Append(ppszText, pdwTextLen, &pszText[dwPos], i - dwPos + 1)) + return FALSE; + } + + /* chose which eoln to use */ + *piEoln = EOLN_CRLF; + if (adwEolnCount[EOLN_LF] > adwEolnCount[*piEoln]) + *piEoln = EOLN_LF; + if (adwEolnCount[EOLN_CR] > adwEolnCount[*piEoln]) + *piEoln = EOLN_CR; + *piEncoding = iEncoding; + + bSuccess = TRUE;
done: - if (pBytes) - HeapFree(GetProcessHeap(), 0, pBytes); - if (pszAllocText) - HeapFree(GetProcessHeap(), 0, pszAllocText); - - if (!bSuccess && *ppszText) - { - HeapFree(GetProcessHeap(), 0, *ppszText); - *ppszText = NULL; - *pdwTextLen = 0; - } - return bSuccess; + if (pBytes) + HeapFree(GetProcessHeap(), 0, pBytes); + if (pszAllocText) + HeapFree(GetProcessHeap(), 0, pszAllocText); + + if (!bSuccess && *ppszText) + { + HeapFree(GetProcessHeap(), 0, *ppszText); + *ppszText = NULL; + *pdwTextLen = 0; + } + return bSuccess; }
static BOOL WriteEncodedText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding) { - LPBYTE pBytes = NULL; - LPBYTE pAllocBuffer = NULL; - DWORD dwPos = 0; - DWORD dwByteCount; - BYTE buffer[1024]; - UINT iCodePage = 0; - DWORD dwDummy, i; - BOOL bSuccess = FALSE; - int iBufferSize, iRequiredBytes; - BYTE b; - - while(dwPos < dwTextLen) - { - switch(iEncoding) - { - case ENCODING_UNICODE: - pBytes = (LPBYTE) &pszText[dwPos]; - dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); - dwPos = dwTextLen; - break; - - case ENCODING_UNICODE_BE: - dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); - if (dwByteCount > sizeof(buffer)) - dwByteCount = sizeof(buffer); - - memcpy(buffer, &pszText[dwPos], dwByteCount); - for (i = 0; i < dwByteCount; i += 2) - { - b = buffer[i+0]; - buffer[i+0] = buffer[i+1]; - buffer[i+1] = b; - } - pBytes = (LPBYTE) &buffer[dwPos]; - dwPos += dwByteCount / sizeof(WCHAR); - break; - - case ENCODING_ANSI: - case ENCODING_UTF8: - if (iEncoding == ENCODING_ANSI) - iCodePage = CP_ACP; - else if (iEncoding == ENCODING_UTF8) - iCodePage = CP_UTF8; - - iRequiredBytes = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, NULL, 0, NULL, NULL); - if (iRequiredBytes <= 0) - { - goto done; - } - else if (iRequiredBytes < sizeof(buffer)) - { - pBytes = buffer; - iBufferSize = sizeof(buffer); - } - else - { - pAllocBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), 0, iRequiredBytes); - if (!pAllocBuffer) - return FALSE; - pBytes = pAllocBuffer; - iBufferSize = iRequiredBytes; - } - - dwByteCount = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, (LPSTR) pBytes, iBufferSize, NULL, NULL); - if (!dwByteCount) - goto done; - - dwPos = dwTextLen; - break; - - default: - goto done; - } - - if (!WriteFile(hFile, pBytes, dwByteCount, &dwDummy, NULL)) - goto done; - - /* free the buffer, if we have allocated one */ - if (pAllocBuffer) - { - HeapFree(GetProcessHeap(), 0, pAllocBuffer); - pAllocBuffer = NULL; - } - } - bSuccess = TRUE; + LPBYTE pBytes = NULL; + LPBYTE pAllocBuffer = NULL; + DWORD dwPos = 0; + DWORD dwByteCount; + BYTE buffer[1024]; + UINT iCodePage = 0; + DWORD dwDummy, i; + BOOL bSuccess = FALSE; + int iBufferSize, iRequiredBytes; + BYTE b; + + while(dwPos < dwTextLen) + { + switch(iEncoding) + { + case ENCODING_UNICODE: + pBytes = (LPBYTE) &pszText[dwPos]; + dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); + dwPos = dwTextLen; + break; + + case ENCODING_UNICODE_BE: + dwByteCount = (dwTextLen - dwPos) * sizeof(WCHAR); + if (dwByteCount > sizeof(buffer)) + dwByteCount = sizeof(buffer); + + memcpy(buffer, &pszText[dwPos], dwByteCount); + for (i = 0; i < dwByteCount; i += 2) + { + b = buffer[i+0]; + buffer[i+0] = buffer[i+1]; + buffer[i+1] = b; + } + pBytes = (LPBYTE) &buffer[dwPos]; + dwPos += dwByteCount / sizeof(WCHAR); + break; + + case ENCODING_ANSI: + case ENCODING_UTF8: + if (iEncoding == ENCODING_ANSI) + iCodePage = CP_ACP; + else if (iEncoding == ENCODING_UTF8) + iCodePage = CP_UTF8; + + iRequiredBytes = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, NULL, 0, NULL, NULL); + if (iRequiredBytes <= 0) + { + goto done; + } + else if (iRequiredBytes < sizeof(buffer)) + { + pBytes = buffer; + iBufferSize = sizeof(buffer); + } + else + { + pAllocBuffer = (LPBYTE) HeapAlloc(GetProcessHeap(), 0, iRequiredBytes); + if (!pAllocBuffer) + return FALSE; + pBytes = pAllocBuffer; + iBufferSize = iRequiredBytes; + } + + dwByteCount = WideCharToMultiByte(iCodePage, 0, &pszText[dwPos], dwTextLen - dwPos, (LPSTR) pBytes, iBufferSize, NULL, NULL); + if (!dwByteCount) + goto done; + + dwPos = dwTextLen; + break; + + default: + goto done; + } + + if (!WriteFile(hFile, pBytes, dwByteCount, &dwDummy, NULL)) + goto done; + + /* free the buffer, if we have allocated one */ + if (pAllocBuffer) + { + HeapFree(GetProcessHeap(), 0, pAllocBuffer); + pAllocBuffer = NULL; + } + } + bSuccess = TRUE;
done: - if (pAllocBuffer) - HeapFree(GetProcessHeap(), 0, pAllocBuffer); - return bSuccess; + if (pAllocBuffer) + HeapFree(GetProcessHeap(), 0, pAllocBuffer); + return bSuccess; }
BOOL WriteText(HANDLE hFile, LPCWSTR pszText, DWORD dwTextLen, int iEncoding, int iEoln) { - WCHAR wcBom; - LPCWSTR pszLF = L"\n"; - DWORD dwPos, dwNext; - - /* Write the proper byte order marks if not ANSI */ - if (iEncoding != ENCODING_ANSI) - { - wcBom = 0xFEFF; - if (!WriteEncodedText(hFile, &wcBom, 1, iEncoding)) - return FALSE; - } - - dwPos = 0; - - /* pszText eoln are always \r\n */ - - do - { - /* Find the next eoln */ - dwNext = dwPos; - while(dwNext < dwTextLen) - { - if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n') - break; - dwNext++; - } - - if (dwNext != dwTextLen) - { - switch (iEoln) - { - case EOLN_LF: - /* Write text (without eoln) */ - if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding)) - return FALSE; - /* Write eoln */ - if (!WriteEncodedText(hFile, pszLF, 1, iEncoding)) - return FALSE; - break; - case EOLN_CR: - /* Write text (including \r as eoln) */ - if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1, iEncoding)) - return FALSE; - break; - case EOLN_CRLF: - /* Write text (including \r\n as eoln) */ - if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2, iEncoding)) - return FALSE; - break; - default: - return FALSE; - } - } - else - { - /* Write text (without eoln, since this is the end of the file) */ - if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding)) - return FALSE; - } - - /* Skip \r\n */ - dwPos = dwNext + 2; - } - while (dwPos < dwTextLen); - - return TRUE; + WCHAR wcBom; + LPCWSTR pszLF = L"\n"; + DWORD dwPos, dwNext; + + /* Write the proper byte order marks if not ANSI */ + if (iEncoding != ENCODING_ANSI) + { + wcBom = 0xFEFF; + if (!WriteEncodedText(hFile, &wcBom, 1, iEncoding)) + return FALSE; + } + + dwPos = 0; + + /* pszText eoln are always \r\n */ + + do + { + /* Find the next eoln */ + dwNext = dwPos; + while(dwNext < dwTextLen) + { + if (pszText[dwNext] == '\r' && pszText[dwNext + 1] == '\n') + break; + dwNext++; + } + + if (dwNext != dwTextLen) + { + switch (iEoln) + { + case EOLN_LF: + /* Write text (without eoln) */ + if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding)) + return FALSE; + /* Write eoln */ + if (!WriteEncodedText(hFile, pszLF, 1, iEncoding)) + return FALSE; + break; + case EOLN_CR: + /* Write text (including \r as eoln) */ + if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 1, iEncoding)) + return FALSE; + break; + case EOLN_CRLF: + /* Write text (including \r\n as eoln) */ + if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos + 2, iEncoding)) + return FALSE; + break; + default: + return FALSE; + } + } + else + { + /* Write text (without eoln, since this is the end of the file) */ + if (!WriteEncodedText(hFile, &pszText[dwPos], dwNext - dwPos, iEncoding)) + return FALSE; + } + + /* Skip \r\n */ + dwPos = dwNext + 2; + } + while (dwPos < dwTextLen); + + return TRUE; }