4 * Copyright 2000 Mike McCormack <Mike_McCormack@looksmart.com.au>
5 * Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
6 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
7 * Copyright 2002 Andriy Palamarchuk
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "notepad_res.h"
33 NOTEPAD_GLOBALS Globals;
35 /***********************************************************************
39 * Sets Global File Name.
41 VOID SetFileName(LPSTR szFileName)
43 lstrcpy(Globals.szFileName, szFileName);
44 Globals.szFileTitle[0] = 0;
45 GetFileTitle(szFileName, Globals.szFileTitle, sizeof(Globals.szFileTitle));
48 /***********************************************************************
52 * All handling of main menu events
55 int NOTEPAD_MenuCommand(WPARAM wParam)
59 case CMD_NEW: DIALOG_FileNew(); break;
60 case CMD_OPEN: DIALOG_FileOpen(); break;
61 case CMD_SAVE: DIALOG_FileSave(); break;
62 case CMD_SAVE_AS: DIALOG_FileSaveAs(); break;
63 case CMD_PRINT: DIALOG_FilePrint(); break;
64 case CMD_PAGE_SETUP: DIALOG_FilePageSetup(); break;
65 case CMD_PRINTER_SETUP: DIALOG_FilePrinterSetup();break;
66 case CMD_EXIT: DIALOG_FileExit(); break;
68 case CMD_UNDO: DIALOG_EditUndo(); break;
69 case CMD_CUT: DIALOG_EditCut(); break;
70 case CMD_COPY: DIALOG_EditCopy(); break;
71 case CMD_PASTE: DIALOG_EditPaste(); break;
72 case CMD_DELETE: DIALOG_EditDelete(); break;
73 case CMD_SELECT_ALL: DIALOG_EditSelectAll(); break;
74 case CMD_TIME_DATE: DIALOG_EditTimeDate();break;
75 case CMD_WRAP: DIALOG_EditWrap(); break;
77 case CMD_SEARCH: DIALOG_Search(); break;
78 case CMD_SEARCH_NEXT: DIALOG_SearchNext(); break;
80 case CMD_HELP_CONTENTS: DIALOG_HelpContents(); break;
81 case CMD_HELP_SEARCH: DIALOG_HelpSearch(); break;
82 case CMD_HELP_ON_HELP: DIALOG_HelpHelp(); break;
83 case CMD_LICENSE: DIALOG_HelpLicense(); break;
84 case CMD_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
85 case CMD_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
90 /***********************************************************************
93 VOID NOTEPAD_InitData(VOID)
95 LPSTR p = Globals.szFilter;
97 LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
101 LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
108 /***********************************************************************
112 LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam,
120 GetClientRect(hWnd, &rc);
121 if (LoadLibrary("RichEd32.dll"))
124 CreateWindow("RICHEDIT", "",
125 WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
126 ES_AUTOVSCROLL | ES_MULTILINE,
127 0, 0, rc.right, rc.bottom, hWnd,
128 NULL, Globals.hInstance, NULL);
137 NOTEPAD_MenuCommand(wParam);
140 case WM_DESTROYCLIPBOARD:
141 MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);
155 SetWindowPos(Globals.hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
156 SWP_NOOWNERZORDER | SWP_NOZORDER);
161 CHAR szFileName[MAX_PATH];
162 HANDLE hDrop = (HANDLE) wParam;
164 DragQueryFile(hDrop, 0, (CHAR *) &szFileName, sizeof(szFileName));
166 DoOpenFile(szFileName);
171 return DefWindowProc(hWnd, msg, wParam, lParam);
176 int AlertFileDoesNotExist(LPSTR szFileName) {
179 CHAR szMessage[MAX_STRING_LEN];
180 CHAR szRessource[MAX_STRING_LEN];
182 LoadString(Globals.hInstance, STRING_DOESNOTEXIST, szRessource,
183 sizeof(szRessource));
184 wsprintf(szMessage, szRessource, szFileName);
186 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
188 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource,
189 MB_ICONEXCLAMATION | MB_YESNO);
194 void HandleCommandLine(LPSTR cmdline)
197 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
201 if (*cmdline++ == ' ') continue;
204 if (option) cmdline++;
205 while (*cmdline && *cmdline == ' ') cmdline++;
210 case 'P': printf("Print file: ");
211 /* TODO - not yet able to print a file */
218 /* file name is passed in the command line */
223 if (cmdline[0] == '"')
226 cmdline[strlen(cmdline) - 1] = 0;
228 if (FileExists(cmdline))
235 /* try to find file with ".txt" extention */
236 if (!strcmp(".txt", cmdline + strlen(cmdline) - strlen(".txt")))
243 strncpy(buf, cmdline, MAX_PATH - strlen(".txt") - 1);
246 file_exists = FileExists(buf);
252 DoOpenFile(file_name);
253 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
257 switch (AlertFileDoesNotExist(file_name)) {
259 DoOpenFile(file_name);
269 /***********************************************************************
273 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
277 char className[] = "NPClass";
278 char winName[] = "Notepad";
280 ZeroMemory(&Globals, sizeof(Globals));
281 Globals.hInstance = hInstance;
283 ZeroMemory(&class, sizeof(class));
284 class.cbSize = sizeof(class);
285 class.lpfnWndProc = NOTEPAD_WndProc;
286 class.hInstance = Globals.hInstance;
287 class.hIcon = LoadIcon(0, IDI_APPLICATION);
288 class.hCursor = LoadCursor(0, IDC_ARROW);
289 class.hbrBackground = (HBRUSH)(COLOR_WINDOW);
290 class.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU);
291 class.lpszClassName = className;
293 if (!RegisterClassEx(&class)) return FALSE;
298 CreateWindow(className, winName, WS_OVERLAPPEDWINDOW,
299 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
300 NULL, NULL, Globals.hInstance, NULL);
301 if (!Globals.hMainWnd)
310 ShowWindow(Globals.hMainWnd, show);
311 UpdateWindow(Globals.hMainWnd);
312 DragAcceptFiles(Globals.hMainWnd, TRUE);
314 HandleCommandLine(cmdline);
316 while (GetMessage(&msg, 0, 0, 0)) {
317 TranslateMessage(&msg);
318 DispatchMessage(&msg);