mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 21:56:06 +00:00
Moved the WINE notepad.
svn path=/trunk/; revision=8773
This commit is contained in:
parent
b17d04d3a2
commit
e816725be5
35 changed files with 3530 additions and 1024 deletions
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
* ReactOS notepad
|
||||
* Notepad
|
||||
*
|
||||
* main.c
|
||||
*
|
||||
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
|
||||
* Copyright 2000 Mike McCormack <Mike_McCormack@looksmart.com.au>
|
||||
* Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
|
||||
* Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
|
||||
* Copyright 2002 Andriy Palamarchuk
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -18,141 +19,336 @@
|
|||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#define UNICODE
|
||||
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "framewnd.h"
|
||||
#include "dialog.h"
|
||||
#include "notepad_res.h"
|
||||
|
||||
NOTEPAD_GLOBALS Globals;
|
||||
static ATOM aFINDMSGSTRING;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global Variables:
|
||||
//
|
||||
|
||||
HINSTANCE hInst;
|
||||
HWND hFrameWnd;
|
||||
HWND hStatusBar;
|
||||
HMENU hMenuFrame;
|
||||
UINT nClipboardFormat;
|
||||
LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
|
||||
|
||||
|
||||
TCHAR szTitle[MAX_LOADSTRING];
|
||||
TCHAR szFrameClass[MAX_LOADSTRING];
|
||||
TCHAR szChildClass[MAX_LOADSTRING];
|
||||
|
||||
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
/***********************************************************************
|
||||
*
|
||||
* SetFileName
|
||||
*
|
||||
* Sets Global File Name.
|
||||
*/
|
||||
VOID SetFileName(LPCWSTR szFileName)
|
||||
{
|
||||
WNDCLASSEX wcFrame = {
|
||||
sizeof(WNDCLASSEX),
|
||||
CS_HREDRAW | CS_VREDRAW/*style*/,
|
||||
FrameWndProc,
|
||||
0/*cbClsExtra*/,
|
||||
0/*cbWndExtra*/,
|
||||
hInstance,
|
||||
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NOTEPAD)),
|
||||
LoadCursor(0, IDC_ARROW),
|
||||
0/*hbrBackground*/,
|
||||
0/*lpszMenuName*/,
|
||||
szFrameClass,
|
||||
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_NOTEPAD), IMAGE_ICON,
|
||||
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
|
||||
};
|
||||
ATOM hFrameWndClass = RegisterClassEx(&wcFrame); // register frame window class
|
||||
#if 0
|
||||
WNDCLASSEX wcChild = {
|
||||
sizeof(WNDCLASSEX),
|
||||
CS_HREDRAW | CS_VREDRAW/*style*/,
|
||||
ChildWndProc,
|
||||
0/*cbClsExtra*/,
|
||||
sizeof(HANDLE)/*cbWndExtra*/,
|
||||
hInstance,
|
||||
LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NOTEPAD)),
|
||||
LoadCursor(0, IDC_ARROW),
|
||||
0/*hbrBackground*/,
|
||||
0/*lpszMenuName*/,
|
||||
szChildClass,
|
||||
(HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_NOTEPAD), IMAGE_ICON,
|
||||
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
|
||||
|
||||
};
|
||||
ATOM hChildWndClass = RegisterClassEx(&wcChild); // register child windows class
|
||||
hChildWndClass = hChildWndClass; // warning eater
|
||||
#endif
|
||||
hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_NOTEPAD_MENU));
|
||||
|
||||
// Initialize the Windows Common Controls DLL
|
||||
InitCommonControls();
|
||||
|
||||
nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
|
||||
if (nClipboardFormat == 0) {
|
||||
DWORD dwError = GetLastError();
|
||||
}
|
||||
|
||||
hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
|
||||
WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
|
||||
|
||||
if (!hFrameWnd) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Create the status bar
|
||||
hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
|
||||
_T(""), hFrameWnd, STATUS_WINDOW);
|
||||
if (hStatusBar) {
|
||||
// Create the status bar panes
|
||||
SetupStatusBar(hFrameWnd, FALSE);
|
||||
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
|
||||
}
|
||||
ShowWindow(hFrameWnd, nCmdShow);
|
||||
UpdateWindow(hFrameWnd);
|
||||
return TRUE;
|
||||
lstrcpy(Globals.szFileName, szFileName);
|
||||
Globals.szFileTitle[0] = 0;
|
||||
GetFileTitle(szFileName, Globals.szFileTitle, sizeof(Globals.szFileTitle));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void ExitInstance(void)
|
||||
/***********************************************************************
|
||||
*
|
||||
* NOTEPAD_MenuCommand
|
||||
*
|
||||
* All handling of main menu events
|
||||
*/
|
||||
static int NOTEPAD_MenuCommand(WPARAM wParam)
|
||||
{
|
||||
DestroyMenu(hMenuFrame);
|
||||
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_WRAP: DIALOG_EditWrap(); break;
|
||||
case CMD_FONT: DIALOG_SelectFont(); 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_LICENSE: DIALOG_HelpLicense(); break;
|
||||
case CMD_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
|
||||
case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
/***********************************************************************
|
||||
* Data Initialization
|
||||
*/
|
||||
static VOID NOTEPAD_InitData(VOID)
|
||||
{
|
||||
MSG msg;
|
||||
HACCEL hAccel;
|
||||
LPWSTR p = Globals.szFilter;
|
||||
static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
|
||||
static const WCHAR all_files[] = { '*','.','*',0 };
|
||||
|
||||
// Initialize global strings
|
||||
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadString(hInstance, IDC_NOTEPAD_FRAME, szFrameClass, MAX_LOADSTRING);
|
||||
LoadString(hInstance, IDC_NOTEPAD, szChildClass, MAX_LOADSTRING);
|
||||
LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
|
||||
p += lstrlen(p) + 1;
|
||||
lstrcpy(p, txt_files);
|
||||
p += lstrlen(p) + 1;
|
||||
LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
|
||||
p += lstrlen(p) + 1;
|
||||
lstrcpy(p, all_files);
|
||||
p += lstrlen(p) + 1;
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* NOTEPAD_WndProc
|
||||
*/
|
||||
static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
switch (msg) {
|
||||
|
||||
case WM_CREATE:
|
||||
{
|
||||
static const WCHAR editW[] = { 'e','d','i','t',0 };
|
||||
RECT rc;
|
||||
GetClientRect(hWnd, &rc);
|
||||
Globals.hEdit = CreateWindow(editW, NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
|
||||
ES_AUTOVSCROLL | ES_MULTILINE,
|
||||
0, 0, rc.right, rc.bottom, hWnd,
|
||||
NULL, Globals.hInstance, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_COMMAND:
|
||||
NOTEPAD_MenuCommand(LOWORD(wParam));
|
||||
break;
|
||||
|
||||
case WM_DESTROYCLIPBOARD:
|
||||
/*MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);*/
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
if (DoCloseFile()) {
|
||||
DestroyWindow(hWnd);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
SetWindowPos(Globals.hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
|
||||
SWP_NOOWNERZORDER | SWP_NOZORDER);
|
||||
break;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
SetFocus(Globals.hEdit);
|
||||
break;
|
||||
|
||||
case WM_DROPFILES:
|
||||
{
|
||||
WCHAR szFileName[MAX_PATH];
|
||||
HANDLE hDrop = (HANDLE) wParam;
|
||||
|
||||
DragQueryFile(hDrop, 0, szFileName, SIZEOF(szFileName));
|
||||
DragFinish(hDrop);
|
||||
DoOpenFile(szFileName);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int AlertFileDoesNotExist(LPCWSTR szFileName)
|
||||
{
|
||||
int nResult;
|
||||
WCHAR szMessage[MAX_STRING_LEN];
|
||||
WCHAR szResource[MAX_STRING_LEN];
|
||||
|
||||
LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szResource, SIZEOF(szResource));
|
||||
wsprintf(szMessage, szResource, szFileName);
|
||||
|
||||
LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
|
||||
|
||||
nResult = MessageBox(Globals.hMainWnd, szMessage, szResource,
|
||||
MB_ICONEXCLAMATION | MB_YESNO);
|
||||
|
||||
return(nResult);
|
||||
}
|
||||
|
||||
static void HandleCommandLine(LPWSTR cmdline)
|
||||
{
|
||||
WCHAR delimiter;
|
||||
|
||||
// Store instance handle in our global variable
|
||||
hInst = hInstance;
|
||||
/* skip white space */
|
||||
while (*cmdline && *cmdline == ' ') cmdline++;
|
||||
|
||||
// Perform application initialization:
|
||||
if (!InitInstance(hInstance, nCmdShow)) {
|
||||
return FALSE;
|
||||
/* skip executable name */
|
||||
delimiter = ' ';
|
||||
if (*cmdline == '"')
|
||||
delimiter = '"';
|
||||
|
||||
do
|
||||
{
|
||||
cmdline++;
|
||||
}
|
||||
hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_NOTEPAD);
|
||||
while (*cmdline && *cmdline != delimiter);
|
||||
if (*cmdline == delimiter) cmdline++;
|
||||
|
||||
// Main message loop:
|
||||
while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
|
||||
{
|
||||
WCHAR option;
|
||||
|
||||
if (*cmdline++ == ' ') continue;
|
||||
|
||||
option = *cmdline;
|
||||
if (option) cmdline++;
|
||||
while (*cmdline && *cmdline == ' ') cmdline++;
|
||||
|
||||
switch(option)
|
||||
{
|
||||
case 'p':
|
||||
case 'P': printf("Print file: ");
|
||||
/* TODO - not yet able to print a file */
|
||||
break;
|
||||
}
|
||||
}
|
||||
ExitInstance();
|
||||
|
||||
if (*cmdline)
|
||||
{
|
||||
/* file name is passed in the command line */
|
||||
LPCWSTR file_name;
|
||||
BOOL file_exists;
|
||||
WCHAR buf[MAX_PATH];
|
||||
|
||||
if (cmdline[0] == '"')
|
||||
{
|
||||
cmdline++;
|
||||
cmdline[lstrlen(cmdline) - 1] = 0;
|
||||
}
|
||||
|
||||
if (FileExists(cmdline))
|
||||
{
|
||||
file_exists = TRUE;
|
||||
file_name = cmdline;
|
||||
}
|
||||
else
|
||||
{
|
||||
static const WCHAR txtW[] = { '.','t','x','t',0 };
|
||||
|
||||
/* try to find file with ".txt" extension */
|
||||
if (!lstrcmp(txtW, cmdline + lstrlen(cmdline) - lstrlen(txtW)))
|
||||
{
|
||||
file_exists = FALSE;
|
||||
file_name = cmdline;
|
||||
}
|
||||
else
|
||||
{
|
||||
lstrcpyn(buf, cmdline, MAX_PATH - lstrlen(txtW) - 1);
|
||||
lstrcat(buf, txtW);
|
||||
file_name = buf;
|
||||
file_exists = FileExists(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists)
|
||||
{
|
||||
DoOpenFile(file_name);
|
||||
InvalidateRect(Globals.hMainWnd, NULL, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (AlertFileDoesNotExist(file_name)) {
|
||||
case IDYES:
|
||||
DoOpenFile(file_name);
|
||||
break;
|
||||
|
||||
case IDNO:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* WinMain
|
||||
*/
|
||||
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
{
|
||||
MSG msg;
|
||||
HACCEL hAccel;
|
||||
WNDCLASSEX class;
|
||||
static const WCHAR className[] = {'N','P','C','l','a','s','s',0};
|
||||
static const WCHAR winName[] = {'N','o','t','e','p','a','d',0};
|
||||
|
||||
aFINDMSGSTRING = RegisterWindowMessage(FINDMSGSTRING);
|
||||
|
||||
ZeroMemory(&Globals, sizeof(Globals));
|
||||
Globals.hInstance = hInstance;
|
||||
|
||||
ZeroMemory(&class, sizeof(class));
|
||||
class.cbSize = sizeof(class);
|
||||
class.lpfnWndProc = NOTEPAD_WndProc;
|
||||
class.hInstance = Globals.hInstance;
|
||||
class.hIcon = LoadIcon(0, IDI_APPLICATION);
|
||||
class.hCursor = LoadCursor(0, IDC_ARROW);
|
||||
class.hbrBackground = (HBRUSH)(COLOR_WINDOW);
|
||||
class.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);
|
||||
class.lpszClassName = className;
|
||||
|
||||
if (!RegisterClassEx(&class)) return FALSE;
|
||||
|
||||
/* Setup windows */
|
||||
|
||||
Globals.hMainWnd =
|
||||
CreateWindow(className, winName, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
|
||||
NULL, NULL, Globals.hInstance, NULL);
|
||||
if (!Globals.hMainWnd)
|
||||
{
|
||||
ShowLastError();
|
||||
ExitProcess(1);
|
||||
}
|
||||
|
||||
NOTEPAD_InitData();
|
||||
DIALOG_FileNew();
|
||||
|
||||
ShowWindow(Globals.hMainWnd, show);
|
||||
UpdateWindow(Globals.hMainWnd);
|
||||
DragAcceptFiles(Globals.hMainWnd, TRUE);
|
||||
|
||||
HandleCommandLine(GetCommandLine());
|
||||
|
||||
hAccel = LoadAccelerators( hInstance, MAKEINTRESOURCE(ID_ACCEL) );
|
||||
|
||||
while (GetMessage(&msg, 0, 0, 0))
|
||||
{
|
||||
if (!TranslateAccelerator(Globals.hMainWnd, hAccel, &msg) && !IsDialogMessage(Globals.hFindReplaceDlg, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
return msg.wParam;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue