Convert Notepad to unicode.

This commit is contained in:
Dmitry Timoshkov 2003-07-21 20:05:33 +00:00 committed by Alexandre Julliard
parent 7924111bc6
commit 398af1666d
8 changed files with 335 additions and 428 deletions

View file

@ -95,16 +95,6 @@ PUSHBUTTON "Cancel", 0x152, 180, 21, 40, 15, WS_TABSTOP
PUSHBUTTON "&Help", 0x153, 180, 39, 40, 15, WS_TABSTOP PUSHBUTTON "&Help", 0x153, 180, 39, 40, 15, WS_TABSTOP
} }
ID_ACCEL ACCELERATORS
{
"^A", CMD_SELECT_ALL
"^F", CMD_SEARCH
"^O", CMD_OPEN
"^S", CMD_SAVE
VK_F3, CMD_SEARCH_NEXT, VIRTKEY
VK_F5, CMD_TIME_DATE, VIRTKEY
}
STRINGTABLE DISCARDABLE STRINGTABLE DISCARDABLE
{ {
STRING_PAGESETUP_HEADERVALUE, "&n" /* FIXME */ STRING_PAGESETUP_HEADERVALUE, "&n" /* FIXME */

View file

@ -1,8 +1,8 @@
#include <windows.h> #include <windows.h>
#include "license.h" #include "license.h"
static CHAR LicenseCaption_En[] = "LICENSE"; static const CHAR LicenseCaption_En[] = "LICENSE";
static CHAR License_En[] = static const CHAR License_En[] =
"This library is free software; you can redistribute it and/or " "This library is free software; you can redistribute it and/or "
"modify it under the terms of the GNU Lesser General Public " "modify it under the terms of the GNU Lesser General Public "
"License as published by the Free Software Foundation; either " "License as published by the Free Software Foundation; either "
@ -17,8 +17,8 @@ static CHAR License_En[] =
"License along with this library; if not, write to the Free Software " "License along with this library; if not, write to the Free Software "
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"; "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA";
static CHAR NoWarrantyCaption_En[] = "NO WARRANTY"; static const CHAR NoWarrantyCaption_En[] = "NO WARRANTY";
static CHAR NoWarranty_En[] = static const CHAR NoWarranty_En[] =
"This library is distributed in the hope that it will be useful, " "This library is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of " "but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU " "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU "
@ -26,4 +26,3 @@ static CHAR NoWarranty_En[] =
LICENSE WineLicense_En = {License_En, LicenseCaption_En, LICENSE WineLicense_En = {License_En, LicenseCaption_En,
NoWarranty_En, NoWarrantyCaption_En}; NoWarranty_En, NoWarrantyCaption_En};

View file

@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
MODULE = notepad.exe MODULE = notepad.exe
APPMODE = gui APPMODE = gui
IMPORTS = comdlg32 shell32 msvcrt user32 gdi32 kernel32 IMPORTS = comdlg32 shell32 user32 gdi32 msvcrt advapi32 kernel32
EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt
EXTRADEFS = -DNO_LIBWINE_PORT EXTRADEFS = -DNO_LIBWINE_PORT

View file

@ -20,34 +20,35 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define UNICODE
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <windows.h> #include <windows.h>
#include <commdlg.h> #include <commdlg.h>
#include <winerror.h>
#include "main.h" #include "main.h"
#include "license.h" #include "license.h"
#include "dialog.h" #include "dialog.h"
static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
VOID ShowLastError(void)
VOID ShowLastError()
{ {
DWORD error = GetLastError(); DWORD error = GetLastError();
if (error != NO_ERROR) if (error != NO_ERROR)
{ {
LPVOID lpMsgBuf; LPWSTR lpMsgBuf;
CHAR szTitle[MAX_STRING_LEN]; WCHAR szTitle[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_ERROR, szTitle, sizeof(szTitle)); LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
FormatMessage( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, 0, NULL, error, 0,
(LPTSTR) &lpMsgBuf, 0, NULL); (LPTSTR) &lpMsgBuf, 0, NULL);
MessageBox(NULL, (char*)lpMsgBuf, szTitle, MB_OK | MB_ICONERROR); MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
} }
} }
@ -57,95 +58,73 @@ VOID ShowLastError()
* Notepad - (untitled) if no file is open * Notepad - (untitled) if no file is open
* Notepad - [filename] if a file is given * Notepad - [filename] if a file is given
*/ */
void UpdateWindowCaption(void) { static void UpdateWindowCaption(void)
CHAR szCaption[MAX_STRING_LEN]; {
CHAR szUntitled[MAX_STRING_LEN]; WCHAR szCaption[MAX_STRING_LEN];
WCHAR szUntitled[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, sizeof(szCaption)); LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, SIZEOF(szCaption));
if (Globals.szFileTitle[0] != '\0') { if (Globals.szFileTitle[0] != '\0') {
lstrcat(szCaption, " - ["); static const WCHAR bracket_lW[] = { ' ','-',' ','[',0 };
static const WCHAR bracket_rW[] = { ']',0 };
lstrcat(szCaption, bracket_lW);
lstrcat(szCaption, Globals.szFileTitle); lstrcat(szCaption, Globals.szFileTitle);
lstrcat(szCaption, "]"); lstrcat(szCaption, bracket_rW);
} }
else else
{ {
LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, sizeof(szUntitled)); static const WCHAR hyphenW[] = { ' ','-',' ',0 };
lstrcat(szCaption, " - "); LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
lstrcat(szCaption, hyphenW);
lstrcat(szCaption, szUntitled); lstrcat(szCaption, szUntitled);
} }
SetWindowText(Globals.hMainWnd, szCaption); SetWindowText(Globals.hMainWnd, szCaption);
} }
static void AlertFileNotFound(LPCWSTR szFileName)
int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) { {
/* WCHAR szMessage[MAX_STRING_LEN];
* Given some ids strings, this acts as a language-aware wrapper for WCHAR szResource[MAX_STRING_LEN];
* "MessageBox"
*/
CHAR szMessage[MAX_STRING_LEN];
CHAR szCaption[MAX_STRING_LEN];
LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
}
void AlertFileNotFound(LPSTR szFileName) {
int nResult;
CHAR szMessage[MAX_STRING_LEN];
CHAR szRessource[MAX_STRING_LEN];
/* Load and format szMessage */ /* Load and format szMessage */
LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource)); LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource));
wsprintf(szMessage, szRessource, szFileName); wsprintf(szMessage, szResource, szFileName);
/* Load szCaption */ /* Load szCaption */
LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource)); LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
/* Display Modal Dialog */ /* Display Modal Dialog */
nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION); MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION);
} }
int AlertFileNotSaved(LPSTR szFileName) { static int AlertFileNotSaved(LPCWSTR szFileName)
{
WCHAR szMessage[MAX_STRING_LEN];
WCHAR szResource[MAX_STRING_LEN];
WCHAR szUntitled[MAX_STRING_LEN];
int nResult; LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
CHAR szMessage[MAX_STRING_LEN];
CHAR szRessource[MAX_STRING_LEN];
/* Load and format Message */ /* Load and format Message */
LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource));
LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource)); wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled);
wsprintf(szMessage, szRessource, szFileName);
/* Load Caption */ /* Load Caption */
LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
/* Display modal */ /* Display modal */
nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL); return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
return(nResult);
} }
VOID AlertOutOfMemory(void) {
int nResult;
nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
PostQuitMessage(1);
}
/** /**
* Returns: * Returns:
* TRUE - if file exists * TRUE - if file exists
* FALSE - if file does not exist * FALSE - if file does not exist
*/ */
BOOL FileExists(LPSTR szFilename) { BOOL FileExists(LPCWSTR szFilename)
{
WIN32_FIND_DATA entry; WIN32_FIND_DATA entry;
HANDLE hFile; HANDLE hFile;
@ -156,12 +135,12 @@ BOOL FileExists(LPSTR szFilename) {
} }
VOID DoSaveFile(VOID) { static VOID DoSaveFile(VOID)
{
HANDLE hFile; HANDLE hFile;
DWORD dwNumWrite; DWORD dwNumWrite;
BOOL bTest; LPSTR pTemp;
CHAR *pTemp; DWORD size;
int size;
hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@ -171,22 +150,21 @@ VOID DoSaveFile(VOID) {
return; return;
} }
size = GetWindowTextLength(Globals.hEdit); size = GetWindowTextLengthA(Globals.hEdit) + 1;
pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size); pTemp = HeapAlloc(GetProcessHeap(), 0, size);
if (!pTemp) if (!pTemp)
{ {
CloseHandle(hFile);
ShowLastError(); ShowLastError();
return; return;
} }
GetWindowText(Globals.hEdit, pTemp, size); size = GetWindowTextA(Globals.hEdit, pTemp, size);
bTest = WriteFile(hFile, pTemp, size, &dwNumWrite, NULL); if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
if(bTest == FALSE)
{
ShowLastError(); ShowLastError();
}
CloseHandle(hFile); CloseHandle(hFile);
GlobalFree(pTemp); HeapFree(GetProcessHeap(), 0, pTemp);
} }
/** /**
@ -194,10 +172,13 @@ VOID DoSaveFile(VOID) {
* TRUE - User agreed to close (both save/don't save) * TRUE - User agreed to close (both save/don't save)
* FALSE - User cancelled close by selecting "Cancel" * FALSE - User cancelled close by selecting "Cancel"
*/ */
BOOL DoCloseFile(void) { BOOL DoCloseFile(void)
{
int nResult; int nResult;
static const WCHAR empty_strW[] = { 0 };
if (Globals.szFileName[0] != 0) { if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
{
/* prompt user to save changes */ /* prompt user to save changes */
nResult = AlertFileNotSaved(Globals.szFileName); nResult = AlertFileNotSaved(Globals.szFileName);
switch (nResult) { switch (nResult) {
@ -214,70 +195,87 @@ BOOL DoCloseFile(void) {
} /* switch */ } /* switch */
} /* if */ } /* if */
SetFileName(""); SetFileName(empty_strW);
UpdateWindowCaption(); UpdateWindowCaption();
return(TRUE); return(TRUE);
} }
void DoOpenFile(LPSTR szFileName) { void DoOpenFile(LPCWSTR szFileName)
{
HANDLE hFile;
LPSTR pTemp;
DWORD size;
DWORD dwNumRead;
/* Close any files and prompt to save changes */ /* Close any files and prompt to save changes */
if (DoCloseFile()) if (!DoCloseFile())
return;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{ {
HANDLE hFile; ShowLastError();
CHAR *pTemp; return;
DWORD size;
DWORD dwNumRead;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
ShowLastError();
return;
}
size = GetFileSize(hFile, NULL);
if (size == 0xFFFFFFFF)
{
ShowLastError();
return;
}
size++;
pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
if (!pTemp)
{
ShowLastError();
return;
}
if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
{
ShowLastError();
return;
}
CloseHandle(hFile);
pTemp[dwNumRead] = '\0';
if (!SetWindowText(Globals.hEdit, pTemp))
{
GlobalFree(pTemp);
ShowLastError();
return;
}
SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
GlobalFree(pTemp);
SetFocus(Globals.hEdit);
SetFileName(szFileName);
UpdateWindowCaption();
} }
size = GetFileSize(hFile, NULL);
if (size == 0xFFFFFFFF)
{
CloseHandle(hFile);
ShowLastError();
return;
}
size++;
pTemp = HeapAlloc(GetProcessHeap(), 0, size);
if (!pTemp)
{
CloseHandle(hFile);
ShowLastError();
return;
}
if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
{
CloseHandle(hFile);
HeapFree(GetProcessHeap(), 0, pTemp);
ShowLastError();
return;
}
CloseHandle(hFile);
pTemp[dwNumRead] = 0;
if (IsTextUnicode(pTemp, dwNumRead, NULL))
{
LPWSTR p = (LPWSTR)pTemp;
/* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */
if (*p == 0xFEFF || *p == 0xFFFE) p++;
SetWindowTextW(Globals.hEdit, p);
}
else
SetWindowTextA(Globals.hEdit, pTemp);
HeapFree(GetProcessHeap(), 0, pTemp);
SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
SetFocus(Globals.hEdit);
SetFileName(szFileName);
UpdateWindowCaption();
} }
VOID DIALOG_FileNew(VOID) VOID DIALOG_FileNew(VOID)
{ {
static const WCHAR empty_strW[] = { 0 };
/* Close any files and promt to save changes */ /* Close any files and promt to save changes */
if (DoCloseFile()) { if (DoCloseFile()) {
SetWindowText(Globals.hEdit, ""); SetWindowText(Globals.hEdit, empty_strW);
SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
SetFocus(Globals.hEdit); SetFocus(Globals.hEdit);
} }
@ -286,22 +284,22 @@ VOID DIALOG_FileNew(VOID)
VOID DIALOG_FileOpen(VOID) VOID DIALOG_FileOpen(VOID)
{ {
OPENFILENAME openfilename; OPENFILENAME openfilename;
WCHAR szPath[MAX_PATH];
CHAR szPath[MAX_PATH]; WCHAR szDir[MAX_PATH];
CHAR szDir[MAX_PATH]; static const WCHAR szDefaultExt[] = { 't','x','t',0 };
CHAR szDefaultExt[] = "txt"; static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
ZeroMemory(&openfilename, sizeof(openfilename)); ZeroMemory(&openfilename, sizeof(openfilename));
GetCurrentDirectory(sizeof(szDir), szDir); GetCurrentDirectory(SIZEOF(szDir), szDir);
lstrcpy(szPath,"*.txt"); lstrcpy(szPath, txt_files);
openfilename.lStructSize = sizeof(openfilename); openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = Globals.hMainWnd; openfilename.hwndOwner = Globals.hMainWnd;
openfilename.hInstance = Globals.hInstance; openfilename.hInstance = Globals.hInstance;
openfilename.lpstrFilter = Globals.szFilter; openfilename.lpstrFilter = Globals.szFilter;
openfilename.lpstrFile = szPath; openfilename.lpstrFile = szPath;
openfilename.nMaxFile = sizeof(szPath); openfilename.nMaxFile = SIZEOF(szPath);
openfilename.lpstrInitialDir = szDir; openfilename.lpstrInitialDir = szDir;
openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
OFN_HIDEREADONLY; OFN_HIDEREADONLY;
@ -328,21 +326,22 @@ VOID DIALOG_FileSave(VOID)
VOID DIALOG_FileSaveAs(VOID) VOID DIALOG_FileSaveAs(VOID)
{ {
OPENFILENAME saveas; OPENFILENAME saveas;
CHAR szPath[MAX_PATH]; WCHAR szPath[MAX_PATH];
CHAR szDir[MAX_PATH]; WCHAR szDir[MAX_PATH];
CHAR szDefaultExt[] = "txt"; static const WCHAR szDefaultExt[] = { 't','x','t',0 };
static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
ZeroMemory(&saveas, sizeof(saveas)); ZeroMemory(&saveas, sizeof(saveas));
GetCurrentDirectory(sizeof(szDir), szDir); GetCurrentDirectory(SIZEOF(szDir), szDir);
lstrcpy(szPath,"*.*"); lstrcpy(szPath, txt_files);
saveas.lStructSize = sizeof(OPENFILENAME); saveas.lStructSize = sizeof(OPENFILENAME);
saveas.hwndOwner = Globals.hMainWnd; saveas.hwndOwner = Globals.hMainWnd;
saveas.hInstance = Globals.hInstance; saveas.hInstance = Globals.hInstance;
saveas.lpstrFilter = Globals.szFilter; saveas.lpstrFilter = Globals.szFilter;
saveas.lpstrFile = szPath; saveas.lpstrFile = szPath;
saveas.nMaxFile = sizeof(szPath); saveas.nMaxFile = SIZEOF(szPath);
saveas.lpstrInitialDir = szDir; saveas.lpstrInitialDir = szDir;
saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
OFN_HIDEREADONLY; OFN_HIDEREADONLY;
@ -357,28 +356,16 @@ VOID DIALOG_FileSaveAs(VOID)
VOID DIALOG_FilePrint(VOID) VOID DIALOG_FilePrint(VOID)
{ {
LONG bFlags;
DOCINFO di; DOCINFO di;
int nResult;
HDC hContext;
PRINTDLG printer; PRINTDLG printer;
char *pDevNamesSpace;
LPDEVNAMES lpDevNames;
SIZE szMetric; SIZE szMetric;
int cWidthPels, cHeightPels, border; int cWidthPels, cHeightPels, border;
int xLeft, yTop, count, i, pagecount, dopage, copycount; int xLeft, yTop, i, pagecount, dopage, copycount;
LOGFONT hdrFont; LOGFONT hdrFont;
HFONT font, old_font=0; HFONT font, old_font=0;
CHAR *pTemp; DWORD size;
int size; LPWSTR pTemp;
static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */
CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */
CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */
strcpy(szDocumentName, Globals.szFileTitle);
count = strlen(szDocumentName);
/* Get a small font and print some header info on each page */ /* Get a small font and print some header info on each page */
hdrFont.lfHeight = 100; hdrFont.lfHeight = 100;
@ -394,7 +381,7 @@ VOID DIALOG_FilePrint(VOID)
hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
hdrFont.lfQuality = PROOF_QUALITY; hdrFont.lfQuality = PROOF_QUALITY;
hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
strcpy(hdrFont.lfFaceName, "Times New Roman"); lstrcpy(hdrFont.lfFaceName, times_new_romanW);
font = CreateFontIndirect(&hdrFont); font = CreateFontIndirect(&hdrFont);
@ -405,84 +392,50 @@ VOID DIALOG_FilePrint(VOID)
printer.hInstance = Globals.hInstance; printer.hInstance = Globals.hInstance;
/* Set some default flags */ /* Set some default flags */
bFlags = PD_RETURNDC + PD_SHOWHELP; printer.Flags = PD_RETURNDC;
if (TRUE) { printer.nFromPage = 0;
/* Remove "Print Selection" if there is no selection */
bFlags = bFlags + PD_NOSELECTION;
}
printer.Flags = bFlags;
printer.nFromPage = 1;
printer.nMinPage = 1; printer.nMinPage = 1;
/* we really need to calculate number of pages to set nMaxPage and nToPage */ /* we really need to calculate number of pages to set nMaxPage and nToPage */
printer.nToPage = 20; printer.nToPage = 0;
printer.nMaxPage = 20; printer.nMaxPage = -1;
/* Let commdlg manage copy settings */ /* Let commdlg manage copy settings */
printer.nCopies = (WORD)PD_USEDEVMODECOPIES; printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
nResult = PrintDlg(&printer); if (!PrintDlg(&printer)) return;
if (printer.hDevNames==0)
return; assert(printer.hDC != 0);
if (!nResult) {
MessageBox(Globals.hMainWnd, "PrintDlg failed", "Print Error", MB_ICONEXCLAMATION);
return;
}
hContext = printer.hDC;
pDevNamesSpace = GlobalLock(printer.hDevNames);
lpDevNames = (LPDEVNAMES) pDevNamesSpace;
lstrcpy(szPrinterName, pDevNamesSpace+lpDevNames->wDriverOffset);
lstrcpy(szDeviceName, pDevNamesSpace+lpDevNames->wDeviceOffset);
lstrcpy(szOutput, pDevNamesSpace+lpDevNames->wOutputOffset);
GlobalUnlock(printer.hDevNames);
/*
MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION);
MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION);
*/
/* initialize DOCINFO */ /* initialize DOCINFO */
di.cbSize = sizeof(DOCINFO); di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szDocumentName; di.lpszDocName = Globals.szFileTitle;
di.lpszOutput = szOutput; di.lpszOutput = NULL;
di.lpszDatatype = (LPTSTR) NULL; di.lpszDatatype = NULL;
di.fwType = 0; di.fwType = 0;
/* The default resolution is pixels, ie MM_TEXT */
/* SetMapMode(hContext, MM_TWIPS);*/
/* SetViewPortExExt(hContext, 10, 10, 0);*/
/* SetBkMode(hContext, OPAQUE);*/
if (StartDoc(printer.hDC, &di) <= 0) return;
/* Get the page dimensions in pixels. */ /* Get the page dimensions in pixels. */
cWidthPels = GetDeviceCaps(hContext, HORZRES); cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
cHeightPels = GetDeviceCaps(hContext, VERTRES); cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
/* Get the file text */ /* Get the file text */
size = GetWindowTextLength(Globals.hEdit); size = GetWindowTextLength(Globals.hEdit) + 1;
pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size); pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
if (!pTemp) if (!pTemp)
{ {
ShowLastError(); ShowLastError();
return; return;
} }
GetWindowText(Globals.hEdit, pTemp, size); size = GetWindowText(Globals.hEdit, pTemp, size);
if (!size)
{
ShowLastError();
return;
}
/* Okay, let's print */
nResult = StartDoc(hContext, &di);
if (nResult <= 0) {
MessageBox(Globals.hMainWnd, "StartDoc failed", "Print Error", MB_ICONEXCLAMATION);
return;
}
border = 150; border = 150;
for (copycount=1; copycount <= printer.nCopies; copycount++) { for (copycount=1; copycount <= printer.nCopies; copycount++) {
i = 0; i = 0;
pagecount = 1; pagecount = 1;
do { do {
static const WCHAR letterM[] = { 'M',0 };
if (pagecount >= printer.nFromPage && if (pagecount >= printer.nFromPage &&
/* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/ /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
pagecount <= printer.nToPage) pagecount <= printer.nToPage)
@ -490,29 +443,30 @@ VOID DIALOG_FilePrint(VOID)
else else
dopage = 0; dopage = 0;
old_font = SelectObject(hContext, font); old_font = SelectObject(printer.hDC, font);
GetTextExtentPoint32(hContext, "M", 1, &szMetric); GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
if (dopage) { if (dopage) {
nResult = StartPage(hContext); if (StartPage(printer.hDC) <= 0) {
if (nResult <= 0) { static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
MessageBox(Globals.hMainWnd, "StartPage failed", "Print Error", MB_ICONEXCLAMATION); static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
return; return;
} }
/* Write a rectangle and header at the top of each page */ /* Write a rectangle and header at the top of each page */
Rectangle(hContext, border, border, cWidthPels-border, border+szMetric.cy*2); Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
/* I don't know what's up with this TextOut command. This comes out /* I don't know what's up with this TextOut command. This comes out
kind of mangled. kind of mangled.
*/ */
TextOut(hContext, border*2, border+szMetric.cy/2, szDocumentName, count); TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
} }
/* The starting point for the main text */ /* The starting point for the main text */
xLeft = border*2; xLeft = border*2;
yTop = border+szMetric.cy*4; yTop = border+szMetric.cy*4;
SelectObject(hContext, old_font); SelectObject(printer.hDC, old_font);
GetTextExtentPoint32(hContext, "M", 1, &szMetric); GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
/* Since outputting strings is giving me problems, output the main /* Since outputting strings is giving me problems, output the main
text one character at a time. text one character at a time.
@ -524,45 +478,19 @@ VOID DIALOG_FilePrint(VOID)
} }
else if (pTemp[i] != '\r') { else if (pTemp[i] != '\r') {
if (dopage) if (dopage)
TextOut(hContext, xLeft, yTop, &pTemp[i], 1); TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
xLeft += szMetric.cx; xLeft += szMetric.cx;
} }
} while (i++<size && yTop<(cHeightPels-border*2)); } while (i++<size && yTop<(cHeightPels-border*2));
if (dopage) if (dopage)
EndPage(hContext); EndPage(printer.hDC);
pagecount++; pagecount++;
} while (i<size); } while (i<size);
} }
switch (nResult) { EndDoc(printer.hDC);
case SP_ERROR: DeleteDC(printer.hDC);
MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
break;
case SP_APPABORT:
MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
break;
case SP_USERABORT:
MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
break;
case SP_OUTOFDISK:
MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
break;
case SP_OUTOFMEMORY:
AlertOutOfMemory();
break;
default:
break;
} /* switch */
nResult = EndDoc(hContext);
assert(nResult>=0);
nResult = DeleteDC(hContext);
assert(nResult!=0);
}
VOID DIALOG_FilePageSetup(VOID)
{
DIALOG_PageSetup();
} }
VOID DIALOG_FilePrinterSetup(VOID) VOID DIALOG_FilePrinterSetup(VOID)
@ -576,9 +504,7 @@ VOID DIALOG_FilePrinterSetup(VOID)
printer.Flags = PD_PRINTSETUP; printer.Flags = PD_PRINTSETUP;
printer.nCopies = 1; printer.nCopies = 1;
if (PrintDlg(&printer)) { PrintDlg(&printer);
/* do nothing */
};
} }
VOID DIALOG_FileExit(VOID) VOID DIALOG_FileExit(VOID)
@ -593,73 +519,44 @@ VOID DIALOG_EditUndo(VOID)
VOID DIALOG_EditCut(VOID) VOID DIALOG_EditCut(VOID)
{ {
HANDLE hMem; SendMessage(Globals.hEdit, WM_CUT, 0, 0);
hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
OpenClipboard(Globals.hMainWnd);
EmptyClipboard();
/* FIXME: Get text */
lstrcpy((CHAR *)hMem, "Hello World");
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
GlobalFree(hMem);
} }
VOID DIALOG_EditCopy(VOID) VOID DIALOG_EditCopy(VOID)
{ {
HANDLE hMem; SendMessage(Globals.hEdit, WM_COPY, 0, 0);
hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
OpenClipboard(Globals.hMainWnd);
EmptyClipboard();
/* FIXME: Get text */
lstrcpy((CHAR *)hMem, "Hello World");
SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
GlobalFree(hMem);
} }
VOID DIALOG_EditPaste(VOID) VOID DIALOG_EditPaste(VOID)
{ {
HANDLE hClipText; SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
if (IsClipboardFormatAvailable(CF_TEXT)) {
OpenClipboard(Globals.hMainWnd);
hClipText = GetClipboardData(CF_TEXT);
CloseClipboard();
MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
}
} }
VOID DIALOG_EditDelete(VOID) VOID DIALOG_EditDelete(VOID)
{ {
/* Delete */ SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
} }
VOID DIALOG_EditSelectAll(VOID) VOID DIALOG_EditSelectAll(VOID)
{ {
/* Select all */ SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
} }
VOID DIALOG_EditTimeDate(VOID) VOID DIALOG_EditTimeDate(VOID)
{ {
SYSTEMTIME st; SYSTEMTIME st;
LPSYSTEMTIME lpst = &st; WCHAR szDate[MAX_STRING_LEN];
CHAR szDate[MAX_STRING_LEN]; static const WCHAR spaceW[] = { ' ',0 };
LPSTR date = szDate;
GetLocalTime(&st); GetLocalTime(&st);
GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN); 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);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
} }
VOID DIALOG_EditWrap(VOID) VOID DIALOG_EditWrap(VOID)
@ -698,8 +595,8 @@ VOID DIALOG_Search(VOID)
Globals.find.lStructSize = sizeof(Globals.find); Globals.find.lStructSize = sizeof(Globals.find);
Globals.find.hwndOwner = Globals.hMainWnd; Globals.find.hwndOwner = Globals.hMainWnd;
Globals.find.hInstance = Globals.hInstance; Globals.find.hInstance = Globals.hInstance;
Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText; Globals.find.lpstrFindWhat = Globals.szFindText;
Globals.find.wFindWhatLen = sizeof(Globals.szFindText); Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
Globals.find.Flags = FR_DOWN; Globals.find.Flags = FR_DOWN;
/* We only need to create the modal FindReplace dialog which will */ /* We only need to create the modal FindReplace dialog which will */
@ -711,12 +608,13 @@ VOID DIALOG_Search(VOID)
VOID DIALOG_SearchNext(VOID) VOID DIALOG_SearchNext(VOID)
{ {
/* Search Next */ /* FIXME: Search Next */
DIALOG_Search();
} }
VOID DIALOG_HelpContents(VOID) VOID DIALOG_HelpContents(VOID)
{ {
WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0); WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
} }
VOID DIALOG_HelpSearch(VOID) VOID DIALOG_HelpSearch(VOID)
@ -726,7 +624,7 @@ VOID DIALOG_HelpSearch(VOID)
VOID DIALOG_HelpHelp(VOID) VOID DIALOG_HelpHelp(VOID)
{ {
WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0); WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
} }
VOID DIALOG_HelpLicense(VOID) VOID DIALOG_HelpLicense(VOID)
@ -741,26 +639,22 @@ VOID DIALOG_HelpNoWarranty(VOID)
VOID DIALOG_HelpAboutWine(VOID) VOID DIALOG_HelpAboutWine(VOID)
{ {
CHAR szNotepad[MAX_STRING_LEN]; static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
WCHAR szNotepad[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad)); LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0); ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0);
} }
/*********************************************************************** /***********************************************************************
* *
* DIALOG_PageSetup * DIALOG_FilePageSetup
*/ */
VOID DIALOG_FilePageSetup(void)
VOID DIALOG_PageSetup(VOID)
{ {
WNDPROC lpfnDlg;
lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP), DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
Globals.hMainWnd, (DLGPROC)lpfnDlg); Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
FreeProcInstance(lpfnDlg);
} }
@ -769,7 +663,7 @@ VOID DIALOG_PageSetup(VOID)
* DIALOG_PAGESETUP_DlgProc * DIALOG_PAGESETUP_DlgProc
*/ */
static LRESULT 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) switch (msg)
@ -779,12 +673,12 @@ static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wPara
{ {
case IDOK: case IDOK:
/* save user input and close dialog */ /* save user input and close dialog */
GetDlgItemText(hDlg, 0x141, Globals.szHeader, sizeof(Globals.szHeader)); GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
GetDlgItemText(hDlg, 0x143, Globals.szFooter, sizeof(Globals.szFooter)); GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, sizeof(Globals.szMarginTop)); GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, sizeof(Globals.szMarginBottom)); GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, sizeof(Globals.szMarginLeft)); GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, sizeof(Globals.szMarginRight)); GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
EndDialog(hDlg, IDOK); EndDialog(hDlg, IDOK);
return TRUE; return TRUE;
@ -794,20 +688,27 @@ static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wPara
return TRUE; return TRUE;
case IDHELP: case IDHELP:
{
/* FIXME: Bring this to work */ /* FIXME: Bring this to work */
MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION); 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);
return TRUE; return TRUE;
} }
default:
break;
}
break; break;
case WM_INITDIALOG: case WM_INITDIALOG:
/* fetch last user input prior to display dialog */ /* fetch last user input prior to display dialog */
SetDlgItemText(hDlg, 0x141, Globals.szHeader); SetDlgItemText(hDlg, 0x141, Globals.szHeader);
SetDlgItemText(hDlg, 0x143, Globals.szFooter); SetDlgItemText(hDlg, 0x143, Globals.szFooter);
SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop); SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom); SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft); SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight); SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
break; break;
} }

View file

@ -34,11 +34,11 @@ VOID DIALOG_EditPaste(VOID);
VOID DIALOG_EditDelete(VOID); VOID DIALOG_EditDelete(VOID);
VOID DIALOG_EditSelectAll(VOID); VOID DIALOG_EditSelectAll(VOID);
VOID DIALOG_EditTimeDate(VOID); VOID DIALOG_EditTimeDate(VOID);
VOID DIALOG_EditWrap(VOID);
VOID DIALOG_Search(VOID); VOID DIALOG_Search(VOID);
VOID DIALOG_SearchNext(VOID); VOID DIALOG_SearchNext(VOID);
VOID DIALOG_EditWrap(VOID);
VOID DIALOG_SelectFont(VOID); VOID DIALOG_SelectFont(VOID);
VOID DIALOG_HelpContents(VOID); VOID DIALOG_HelpContents(VOID);
@ -48,11 +48,10 @@ VOID DIALOG_HelpLicense(VOID);
VOID DIALOG_HelpNoWarranty(VOID); VOID DIALOG_HelpNoWarranty(VOID);
VOID DIALOG_HelpAboutWine(VOID); VOID DIALOG_HelpAboutWine(VOID);
VOID DIALOG_PageSetup(VOID);
VOID DIALOG_TimeDate(VOID); VOID DIALOG_TimeDate(VOID);
/* utility functions */ /* utility functions */
VOID ShowLastError(); VOID ShowLastError();
BOOL FileExists(LPSTR szFilename); BOOL FileExists(LPCWSTR szFilename);
BOOL DoCloseFile(void); BOOL DoCloseFile(void);
void DoOpenFile(LPSTR szFileName); void DoOpenFile(LPCWSTR szFileName);

View file

@ -22,8 +22,9 @@
* *
*/ */
#define UNICODE
#include <windows.h> #include <windows.h>
#include <richedit.h>
#include <stdio.h> #include <stdio.h>
#include "main.h" #include "main.h"
@ -31,6 +32,7 @@
#include "notepad_res.h" #include "notepad_res.h"
NOTEPAD_GLOBALS Globals; NOTEPAD_GLOBALS Globals;
static ATOM aFINDMSGSTRING;
/*********************************************************************** /***********************************************************************
* *
@ -38,7 +40,7 @@ NOTEPAD_GLOBALS Globals;
* *
* Sets Global File Name. * Sets Global File Name.
*/ */
VOID SetFileName(LPSTR szFileName) VOID SetFileName(LPCWSTR szFileName)
{ {
lstrcpy(Globals.szFileName, szFileName); lstrcpy(Globals.szFileName, szFileName);
Globals.szFileTitle[0] = 0; Globals.szFileTitle[0] = 0;
@ -51,8 +53,7 @@ VOID SetFileName(LPSTR szFileName)
* *
* All handling of main menu events * All handling of main menu events
*/ */
static int NOTEPAD_MenuCommand(WPARAM wParam)
int NOTEPAD_MenuCommand(WPARAM wParam)
{ {
switch (wParam) switch (wParam)
{ {
@ -85,6 +86,9 @@ int NOTEPAD_MenuCommand(WPARAM wParam)
case CMD_LICENSE: DIALOG_HelpLicense(); break; case CMD_LICENSE: DIALOG_HelpLicense(); break;
case CMD_NO_WARRANTY: DIALOG_HelpNoWarranty(); break; case CMD_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break; case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
default:
break;
} }
return 0; return 0;
} }
@ -92,18 +96,20 @@ int NOTEPAD_MenuCommand(WPARAM wParam)
/*********************************************************************** /***********************************************************************
* Data Initialization * Data Initialization
*/ */
VOID NOTEPAD_InitData(VOID) static VOID NOTEPAD_InitData(VOID)
{ {
LPSTR p = Globals.szFilter; 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); LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
p += strlen(p) + 1; p += lstrlen(p) + 1;
lstrcpy(p, "*.txt"); lstrcpy(p, txt_files);
p += strlen(p) + 1; p += lstrlen(p) + 1;
LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN); LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
p += strlen(p) + 1; p += lstrlen(p) + 1;
lstrcpy(p, "*.*"); lstrcpy(p, all_files);
p += strlen(p) + 1; p += lstrlen(p) + 1;
*p = '\0'; *p = '\0';
} }
@ -111,16 +117,17 @@ VOID NOTEPAD_InitData(VOID)
* *
* NOTEPAD_WndProc * NOTEPAD_WndProc
*/ */
LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam) LPARAM lParam)
{ {
switch (msg) { switch (msg) {
case WM_CREATE: case WM_CREATE:
{ {
static const WCHAR editW[] = { 'e','d','i','t',0 };
RECT rc; RECT rc;
GetClientRect(hWnd, &rc); GetClientRect(hWnd, &rc);
Globals.hEdit = CreateWindow("EDIT", "", Globals.hEdit = CreateWindow(editW, NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
ES_AUTOVSCROLL | ES_MULTILINE, ES_AUTOVSCROLL | ES_MULTILINE,
0, 0, rc.right, rc.bottom, hWnd, 0, 0, rc.right, rc.bottom, hWnd,
@ -133,7 +140,7 @@ LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
break; break;
case WM_DESTROYCLIPBOARD: case WM_DESTROYCLIPBOARD:
MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION); /*MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);*/
break; break;
case WM_CLOSE: case WM_CLOSE:
@ -151,12 +158,16 @@ LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
SWP_NOOWNERZORDER | SWP_NOZORDER); SWP_NOOWNERZORDER | SWP_NOZORDER);
break; break;
case WM_SETFOCUS:
SetFocus(Globals.hEdit);
break;
case WM_DROPFILES: case WM_DROPFILES:
{ {
CHAR szFileName[MAX_PATH]; WCHAR szFileName[MAX_PATH];
HANDLE hDrop = (HANDLE) wParam; HANDLE hDrop = (HANDLE) wParam;
DragQueryFile(hDrop, 0, (CHAR *) &szFileName, sizeof(szFileName)); DragQueryFile(hDrop, 0, szFileName, SIZEOF(szFileName));
DragFinish(hDrop); DragFinish(hDrop);
DoOpenFile(szFileName); DoOpenFile(szFileName);
break; break;
@ -168,30 +179,45 @@ LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
return 0; return 0;
} }
int AlertFileDoesNotExist(LPSTR szFileName) { static int AlertFileDoesNotExist(LPCWSTR szFileName)
{
int nResult; int nResult;
CHAR szMessage[MAX_STRING_LEN]; WCHAR szMessage[MAX_STRING_LEN];
CHAR szRessource[MAX_STRING_LEN]; WCHAR szResource[MAX_STRING_LEN];
LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szRessource, LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szResource, SIZEOF(szResource));
sizeof(szRessource)); wsprintf(szMessage, szResource, szFileName);
wsprintf(szMessage, szRessource, szFileName);
LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource)); LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, nResult = MessageBox(Globals.hMainWnd, szMessage, szResource,
MB_ICONEXCLAMATION | MB_YESNO); MB_ICONEXCLAMATION | MB_YESNO);
return(nResult); return(nResult);
} }
void HandleCommandLine(LPSTR cmdline) static void HandleCommandLine(LPWSTR cmdline)
{ {
WCHAR delimiter;
/* skip white space */
while (*cmdline && *cmdline == ' ') cmdline++;
/* skip executable name */
delimiter = ' ';
if (*cmdline == '"')
delimiter = '"';
do
{
cmdline++;
}
while (*cmdline && *cmdline != delimiter);
if (*cmdline == delimiter) cmdline++;
while (*cmdline && (*cmdline == ' ' || *cmdline == '-')) while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
{ {
CHAR option; WCHAR option;
if (*cmdline++ == ' ') continue; if (*cmdline++ == ' ') continue;
@ -211,15 +237,16 @@ void HandleCommandLine(LPSTR cmdline)
if (*cmdline) if (*cmdline)
{ {
/* file name is passed in the command line */ /* file name is passed in the command line */
char *file_name; LPCWSTR file_name;
BOOL file_exists; BOOL file_exists;
char buf[MAX_PATH]; WCHAR buf[MAX_PATH];
if (cmdline[0] == '"') if (cmdline[0] == '"')
{ {
cmdline++; cmdline++;
cmdline[strlen(cmdline) - 1] = 0; cmdline[lstrlen(cmdline) - 1] = 0;
} }
if (FileExists(cmdline)) if (FileExists(cmdline))
{ {
file_exists = TRUE; file_exists = TRUE;
@ -227,16 +254,18 @@ void HandleCommandLine(LPSTR cmdline)
} }
else else
{ {
/* try to find file with ".txt" extension */ static const WCHAR txtW[] = { '.','t','x','t',0 };
if (!strcmp(".txt", cmdline + strlen(cmdline) - strlen(".txt")))
/* try to find file with ".txt" extention */
if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW)))
{ {
file_exists = FALSE; file_exists = FALSE;
file_name = cmdline; file_name = cmdline;
} }
else else
{ {
strncpy(buf, cmdline, MAX_PATH - strlen(".txt") - 1); lstrcpyn(buf, cmdline, MAX_PATH - lstrlen(txtW) - 1);
strcat(buf, ".txt"); lstrcat(buf, txtW);
file_name = buf; file_name = buf;
file_exists = FileExists(buf); file_exists = FileExists(buf);
} }
@ -270,8 +299,10 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
MSG msg; MSG msg;
HACCEL hAccel; HACCEL hAccel;
WNDCLASSEX class; WNDCLASSEX class;
char className[] = "NPClass"; static const WCHAR className[] = {'N','P','C','l','a','s','s',0};
char winName[] = "Notepad"; static const WCHAR winName[] = {'N','o','t','e','p','a','d',0};
aFINDMSGSTRING = RegisterWindowMessage(FINDMSGSTRING);
ZeroMemory(&Globals, sizeof(Globals)); ZeroMemory(&Globals, sizeof(Globals));
Globals.hInstance = hInstance; Globals.hInstance = hInstance;
@ -307,24 +338,17 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
UpdateWindow(Globals.hMainWnd); UpdateWindow(Globals.hMainWnd);
DragAcceptFiles(Globals.hMainWnd, TRUE); DragAcceptFiles(Globals.hMainWnd, TRUE);
HandleCommandLine(cmdline); HandleCommandLine(GetCommandLine());
hAccel=LoadAccelerators( hInstance, MAKEINTRESOURCE(ID_ACCEL) ); hAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE(ID_ACCEL) );
if( hAccel!=NULL ) while (GetMessage(&msg, 0, 0, 0))
{ {
while( GetMessage(&msg, 0, 0, 0)) { if (!TranslateAccelerator(Globals.hMainWnd, hAccel, &msg) && !IsDialogMessage(Globals.hFindReplaceDlg, &msg))
if( !TranslateAccelerator( Globals.hMainWnd, hAccel, &msg ) ) { {
TranslateMessage( &msg ); TranslateMessage(&msg);
DispatchMessage( &msg ); DispatchMessage(&msg);
} }
}
} else
{
while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} }
return msg.wParam; return msg.wParam;
} }

View file

@ -19,26 +19,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define SIZEOF(a) sizeof(a)/sizeof((a)[0])
#include "notepad_res.h" #include "notepad_res.h"
#define MAX_STRING_LEN 255 #define MAX_STRING_LEN 255
#define HELPFILE "notepad.hlp"
/* hide the following from winerc */
#ifndef RC_INVOKED
#define WINE_RELEASE_INFO "Wine (www.winehq.com)"
#include "commdlg.h"
VOID SetFileName(LPSTR szFileName);
/***** Compatibility *****/
#ifndef OIC_WINLOGO
#define OIC_WINLOGO 32517
#endif
#define DEFAULTICON OIC_WINLOGO
typedef struct typedef struct
{ {
@ -48,26 +33,21 @@ typedef struct
HWND hEdit; HWND hEdit;
HFONT hFont; /* Font used by the edit control */ HFONT hFont; /* Font used by the edit control */
LOGFONT lfFont; LOGFONT lfFont;
HICON hMainIcon;
HICON hDefaultIcon;
LPCSTR lpszIcoFile;
BOOL bWrapLongLines; BOOL bWrapLongLines;
CHAR szFindText[MAX_PATH]; WCHAR szFindText[MAX_PATH];
CHAR szFileName[MAX_PATH]; WCHAR szFileName[MAX_PATH];
CHAR szFileTitle[MAX_PATH]; WCHAR szFileTitle[MAX_PATH];
CHAR szFilter[2 * MAX_STRING_LEN + 100]; WCHAR szFilter[2 * MAX_STRING_LEN + 100];
CHAR szMarginTop[MAX_PATH]; WCHAR szMarginTop[MAX_PATH];
CHAR szMarginBottom[MAX_PATH]; WCHAR szMarginBottom[MAX_PATH];
CHAR szMarginLeft[MAX_PATH]; WCHAR szMarginLeft[MAX_PATH];
CHAR szMarginRight[MAX_PATH]; WCHAR szMarginRight[MAX_PATH];
CHAR szHeader[MAX_PATH]; WCHAR szHeader[MAX_PATH];
CHAR szFooter[MAX_PATH]; WCHAR szFooter[MAX_PATH];
FINDREPLACE find; FINDREPLACE find;
} NOTEPAD_GLOBALS; } NOTEPAD_GLOBALS;
extern NOTEPAD_GLOBALS Globals; extern NOTEPAD_GLOBALS Globals;
#else /* RC_INVOKED */ VOID SetFileName(LPCWSTR szFileName);
#endif

View file

@ -24,6 +24,20 @@
#include "commctrl.h" #include "commctrl.h"
#include "notepad_res.h" #include "notepad_res.h"
ID_ACCEL ACCELERATORS
{
"^A", CMD_SELECT_ALL
"^C", CMD_COPY
"^F", CMD_SEARCH
"^O", CMD_OPEN
"^S", CMD_SAVE
"^V", CMD_PASTE
"^X", CMD_CUT
"^Z", CMD_UNDO
VK_F3, CMD_SEARCH_NEXT, VIRTKEY
VK_F5, CMD_TIME_DATE, VIRTKEY
}
#include "Da.rc" #include "Da.rc"
#include "De.rc" #include "De.rc"
#include "En.rc" #include "En.rc"