Commit 398af166 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

Convert Notepad to unicode.

parent 7924111b
...@@ -95,16 +95,6 @@ PUSHBUTTON "Cancel", 0x152, 180, 21, 40, 15, WS_TABSTOP ...@@ -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 */
......
#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[] = ...@@ -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[] = ...@@ -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};
...@@ -4,7 +4,7 @@ SRCDIR = @srcdir@ ...@@ -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
......
...@@ -34,11 +34,11 @@ VOID DIALOG_EditPaste(VOID); ...@@ -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); ...@@ -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);
...@@ -22,8 +22,9 @@ ...@@ -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 @@ ...@@ -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; ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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;
} }
...@@ -19,26 +19,11 @@ ...@@ -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 ...@@ -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
...@@ -24,6 +24,20 @@ ...@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment