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 GetFileTitle(szFileName
, Globals
.szFileTitle
, sizeof(Globals
.szFileTitle
));
47 /***********************************************************************
51 * All handling of main menu events
54 int NOTEPAD_MenuCommand(WPARAM wParam
)
58 case CMD_NEW
: DIALOG_FileNew(); break;
59 case CMD_OPEN
: DIALOG_FileOpen(); break;
60 case CMD_SAVE
: DIALOG_FileSave(); break;
61 case CMD_SAVE_AS
: DIALOG_FileSaveAs(); break;
62 case CMD_PRINT
: DIALOG_FilePrint(); break;
63 case CMD_PAGE_SETUP
: DIALOG_FilePageSetup(); break;
64 case CMD_PRINTER_SETUP
: DIALOG_FilePrinterSetup();break;
65 case CMD_EXIT
: DIALOG_FileExit(); break;
67 case CMD_UNDO
: DIALOG_EditUndo(); break;
68 case CMD_CUT
: DIALOG_EditCut(); break;
69 case CMD_COPY
: DIALOG_EditCopy(); break;
70 case CMD_PASTE
: DIALOG_EditPaste(); break;
71 case CMD_DELETE
: DIALOG_EditDelete(); break;
72 case CMD_SELECT_ALL
: DIALOG_EditSelectAll(); break;
73 case CMD_TIME_DATE
: DIALOG_EditTimeDate();break;
74 case CMD_WRAP
: DIALOG_EditWrap(); break;
76 case CMD_SEARCH
: DIALOG_Search(); break;
77 case CMD_SEARCH_NEXT
: DIALOG_SearchNext(); break;
79 case CMD_HELP_CONTENTS
: DIALOG_HelpContents(); break;
80 case CMD_HELP_SEARCH
: DIALOG_HelpSearch(); break;
81 case CMD_HELP_ON_HELP
: DIALOG_HelpHelp(); break;
82 case CMD_LICENSE
: DIALOG_HelpLicense(); break;
83 case CMD_NO_WARRANTY
: DIALOG_HelpNoWarranty(); break;
84 case CMD_ABOUT_WINE
: DIALOG_HelpAboutWine(); break;
89 /***********************************************************************
92 VOID
NOTEPAD_InitData(VOID
)
94 LPSTR p
= Globals
.szFilter
;
96 LoadString(Globals
.hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
100 LoadString(Globals
.hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
107 /***********************************************************************
111 LRESULT WINAPI
NOTEPAD_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
119 GetClientRect(hWnd
, &rc
);
120 if (LoadLibrary("RichEd32.dll"))
123 CreateWindow("RICHEDIT", "",
124 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| WS_VSCROLL
|
125 ES_AUTOVSCROLL
| ES_MULTILINE
,
126 0, 0, rc
.right
, rc
.bottom
, hWnd
,
127 NULL
, Globals
.hInstance
, NULL
);
138 NOTEPAD_MenuCommand(wParam
);
141 case WM_DESTROYCLIPBOARD
:
142 MessageBox(Globals
.hMainWnd
, "Empty clipboard", "Debug", MB_ICONEXCLAMATION
);
156 SetWindowPos(Globals
.hEdit
, NULL
, 0, 0, LOWORD(lParam
), HIWORD(lParam
),
157 SWP_NOOWNERZORDER
| SWP_NOZORDER
);
162 CHAR szFileName
[MAX_PATH
];
163 HANDLE hDrop
= (HANDLE
) wParam
;
165 DragQueryFile(hDrop
, 0, (CHAR
*) &szFileName
, sizeof(szFileName
));
167 DoOpenFile(szFileName
);
172 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
177 int AlertFileDoesNotExist(LPSTR szFileName
) {
180 CHAR szMessage
[MAX_STRING_LEN
];
181 CHAR szRessource
[MAX_STRING_LEN
];
183 LoadString(Globals
.hInstance
, STRING_DOESNOTEXIST
, szRessource
,
184 sizeof(szRessource
));
185 wsprintf(szMessage
, szRessource
, szFileName
);
187 LoadString(Globals
.hInstance
, STRING_ERROR
, szRessource
, sizeof(szRessource
));
189 nResult
= MessageBox(Globals
.hMainWnd
, szMessage
, szRessource
,
190 MB_ICONEXCLAMATION
| MB_YESNO
);
195 void HandleCommandLine(LPSTR cmdline
)
198 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
202 if (*cmdline
++ == ' ') continue;
205 if (option
) cmdline
++;
206 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
211 case 'P': printf("Print file: ");
212 /* TODO - not yet able to print a file */
219 /* file name is passed in the command line */
224 if (FileExists(cmdline
))
231 /* try to find file with ".txt" extention */
232 if (!strcmp(".txt", cmdline
+ strlen(cmdline
) - strlen(".txt")))
239 strncpy(buf
, cmdline
, MAX_PATH
- strlen(".txt") - 1);
242 file_exists
= FileExists(buf
);
248 DoOpenFile(file_name
);
249 InvalidateRect(Globals
.hMainWnd
, NULL
, FALSE
);
253 switch (AlertFileDoesNotExist(file_name
)) {
255 DoOpenFile(file_name
);
265 /***********************************************************************
269 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
273 char className
[] = "NPClass";
274 char winName
[] = "Notepad";
276 ZeroMemory(&Globals
, sizeof(Globals
));
277 Globals
.hInstance
= hInstance
;
279 ZeroMemory(&class, sizeof(class));
280 class.cbSize
= sizeof(class);
281 class.lpfnWndProc
= NOTEPAD_WndProc
;
282 class.hInstance
= Globals
.hInstance
;
283 class.hIcon
= LoadIcon(0, IDI_APPLICATION
);
284 class.hCursor
= LoadCursor(0, IDC_ARROW
);
285 class.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
);
286 class.lpszMenuName
= MAKEINTRESOURCE(MAIN_MENU
);
287 class.lpszClassName
= className
;
289 if (!RegisterClassEx(&class)) return FALSE
;
294 CreateWindow(className
, winName
, WS_OVERLAPPEDWINDOW
,
295 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
296 NULL
, NULL
, Globals
.hInstance
, NULL
);
297 if (!Globals
.hMainWnd
)
303 ShowWindow(Globals
.hMainWnd
, show
);
304 UpdateWindow(Globals
.hMainWnd
);
305 DragAcceptFiles(Globals
.hMainWnd
, TRUE
);
307 HandleCommandLine(cmdline
);
309 while (GetMessage(&msg
, 0, 0, 0)) {
310 TranslateMessage(&msg
);
311 DispatchMessage(&msg
);