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;
76 case CMD_SEARCH
: DIALOG_Search(); break;
77 case CMD_SEARCH_NEXT
: DIALOG_SearchNext(); break;
79 case CMD_WRAP
: DIALOG_EditWrap(); break;
80 case CMD_FONT
: DIALOG_SelectFont(); break;
82 case CMD_HELP_CONTENTS
: DIALOG_HelpContents(); break;
83 case CMD_HELP_SEARCH
: DIALOG_HelpSearch(); break;
84 case CMD_HELP_ON_HELP
: DIALOG_HelpHelp(); break;
85 case CMD_LICENSE
: DIALOG_HelpLicense(); break;
86 case CMD_NO_WARRANTY
: DIALOG_HelpNoWarranty(); break;
87 case CMD_ABOUT_WINE
: DIALOG_HelpAboutWine(); break;
92 /***********************************************************************
95 VOID
NOTEPAD_InitData(VOID
)
97 LPSTR p
= Globals
.szFilter
;
99 LoadString(Globals
.hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
103 LoadString(Globals
.hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
110 /***********************************************************************
114 LRESULT WINAPI
NOTEPAD_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
,
122 GetClientRect(hWnd
, &rc
);
123 Globals
.hEdit
= CreateWindow("EDIT", "",
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
);
132 NOTEPAD_MenuCommand(LOWORD(wParam
));
135 case WM_DESTROYCLIPBOARD
:
136 MessageBox(Globals
.hMainWnd
, "Empty clipboard", "Debug", MB_ICONEXCLAMATION
);
150 SetWindowPos(Globals
.hEdit
, NULL
, 0, 0, LOWORD(lParam
), HIWORD(lParam
),
151 SWP_NOOWNERZORDER
| SWP_NOZORDER
);
156 CHAR szFileName
[MAX_PATH
];
157 HANDLE hDrop
= (HANDLE
) wParam
;
159 DragQueryFile(hDrop
, 0, (CHAR
*) &szFileName
, sizeof(szFileName
));
161 DoOpenFile(szFileName
);
166 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
171 int AlertFileDoesNotExist(LPSTR szFileName
) {
174 CHAR szMessage
[MAX_STRING_LEN
];
175 CHAR szRessource
[MAX_STRING_LEN
];
177 LoadString(Globals
.hInstance
, STRING_DOESNOTEXIST
, szRessource
,
178 sizeof(szRessource
));
179 wsprintf(szMessage
, szRessource
, szFileName
);
181 LoadString(Globals
.hInstance
, STRING_ERROR
, szRessource
, sizeof(szRessource
));
183 nResult
= MessageBox(Globals
.hMainWnd
, szMessage
, szRessource
,
184 MB_ICONEXCLAMATION
| MB_YESNO
);
189 void HandleCommandLine(LPSTR cmdline
)
192 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
196 if (*cmdline
++ == ' ') continue;
199 if (option
) cmdline
++;
200 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
205 case 'P': printf("Print file: ");
206 /* TODO - not yet able to print a file */
213 /* file name is passed in the command line */
218 if (cmdline
[0] == '"')
221 cmdline
[strlen(cmdline
) - 1] = 0;
223 if (FileExists(cmdline
))
230 /* try to find file with ".txt" extention */
231 if (!strcmp(".txt", cmdline
+ strlen(cmdline
) - strlen(".txt")))
238 strncpy(buf
, cmdline
, MAX_PATH
- strlen(".txt") - 1);
241 file_exists
= FileExists(buf
);
247 DoOpenFile(file_name
);
248 InvalidateRect(Globals
.hMainWnd
, NULL
, FALSE
);
252 switch (AlertFileDoesNotExist(file_name
)) {
254 DoOpenFile(file_name
);
264 /***********************************************************************
268 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
)
306 ShowWindow(Globals
.hMainWnd
, show
);
307 UpdateWindow(Globals
.hMainWnd
);
308 DragAcceptFiles(Globals
.hMainWnd
, TRUE
);
310 HandleCommandLine(cmdline
);
312 hAccel
=LoadAccelerators( hInstance
, MAKEINTRESOURCE(ID_ACCEL
) );
316 while( GetMessage(&msg
, 0, 0, 0)) {
317 if( !TranslateAccelerator( Globals
.hMainWnd
, hAccel
, &msg
) ) {
318 TranslateMessage( &msg
);
319 DispatchMessage( &msg
);
324 while (GetMessage(&msg
, 0, 0, 0)) {
325 TranslateMessage(&msg
);
326 DispatchMessage(&msg
);