DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / programs / notepad / main.c
blobca628c21d7fbfb8a0d6c4b1cde325b384715d2e5
1 /*
2 * Notepad
4 * Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
5 * To be distributed under the Wine License
6 */
8 #include <stdio.h>
9 #include "windows.h"
11 #ifdef LCC
12 #include "lcc.h"
13 #endif
15 #include "main.h"
16 #include "license.h"
17 #include "dialog.h"
18 #include "language.h"
20 extern BOOL DoCloseFile(void);
21 extern void DoOpenFile(LPCSTR szFileName);
23 NOTEPAD_GLOBALS Globals;
25 /***********************************************************************
27 * NOTEPAD_MenuCommand
29 * All handling of main menu events
32 int NOTEPAD_MenuCommand (WPARAM wParam)
34 switch (wParam) {
35 case NP_FILE_NEW: DIALOG_FileNew(); break;
36 case NP_FILE_OPEN: DIALOG_FileOpen(); break;
37 case NP_FILE_SAVE: DIALOG_FileSave(); break;
38 case NP_FILE_SAVEAS: DIALOG_FileSaveAs(); break;
39 case NP_FILE_PRINT: DIALOG_FilePrint(); break;
40 case NP_FILE_PAGESETUP: DIALOG_FilePageSetup(); break;
41 case NP_FILE_PRINTSETUP: DIALOG_FilePrinterSetup();break;
42 case NP_FILE_EXIT: DIALOG_FileExit(); break;
44 case NP_EDIT_UNDO: DIALOG_EditUndo(); break;
45 case NP_EDIT_CUT: DIALOG_EditCut(); break;
46 case NP_EDIT_COPY: DIALOG_EditCopy(); break;
47 case NP_EDIT_PASTE: DIALOG_EditPaste(); break;
48 case NP_EDIT_DELETE: DIALOG_EditDelete(); break;
49 case NP_EDIT_SELECTALL: DIALOG_EditSelectAll(); break;
50 case NP_EDIT_TIMEDATE: DIALOG_EditTimeDate();break;
51 case NP_EDIT_WRAP: DIALOG_EditWrap(); break;
53 case NP_SEARCH_SEARCH: DIALOG_Search(); break;
54 case NP_SEARCH_NEXT: DIALOG_SearchNext(); break;
56 case NP_HELP_CONTENTS: DIALOG_HelpContents(); break;
57 case NP_HELP_SEARCH: DIALOG_HelpSearch(); break;
58 case NP_HELP_ON_HELP: DIALOG_HelpHelp(); break;
59 case NP_HELP_LICENSE: DIALOG_HelpLicense(); break;
60 case NP_HELP_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
61 case NP_HELP_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
63 /* Handle languages */
64 default:
65 LANGUAGE_DefaultHandle(wParam);
67 return 0;
72 /***********************************************************************
74 * NOTEPAD_WndProc
77 LRESULT NOTEPAD_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
79 PAINTSTRUCT ps;
80 HDC hContext;
81 HANDLE hDrop; /* drag & drop */
82 CHAR szFileName[MAX_STRING_LEN];
83 RECT Windowsize;
85 lstrcpy(szFileName, "");
87 switch (msg) {
89 case WM_CREATE:
90 break;
92 case WM_PAINT:
93 hContext = BeginPaint(hWnd, &ps);
94 TextOut(hContext, 1, 1, Globals.Buffer, strlen(Globals.Buffer));
95 EndPaint(hWnd, &ps);
96 break;
98 case WM_COMMAND:
99 NOTEPAD_MenuCommand(wParam);
100 break;
102 case WM_DESTROYCLIPBOARD:
103 MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);
104 break;
106 case WM_CLOSE:
107 if (DoCloseFile()) {
108 PostQuitMessage(0);
110 break;
112 case WM_DESTROY:
113 PostQuitMessage (0);
114 break;
116 case WM_SIZE:
117 GetClientRect(Globals.hMainWnd, &Windowsize);
118 break;
120 case WM_DROPFILES:
121 /* User has dropped a file into main window */
122 hDrop = (HANDLE) wParam;
123 DragQueryFile(hDrop, 0, (CHAR *) &szFileName, sizeof(szFileName));
124 DragFinish(hDrop);
125 DoOpenFile(szFileName);
126 break;
128 default:
129 return DefWindowProc (hWnd, msg, wParam, lParam);
131 return 0l;
136 /***********************************************************************
138 * WinMain
141 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
143 MSG msg;
144 WNDCLASS class;
145 char className[] = "NPClass"; /* To make sure className >= 0x10000 */
146 char winName[] = "Notepad";
148 /* Select Language */
149 LANGUAGE_Init();
152 /* Setup Globals */
154 Globals.lpszIniFile = "notepad.ini";
155 Globals.lpszIcoFile = "notepad.ico";
157 Globals.hInstance = hInstance;
159 #ifndef LCC
160 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
161 Globals.lpszIcoFile, 0);
162 #endif
163 if (!Globals.hMainIcon) {
164 Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
167 lstrcpy(Globals.szFindText, "");
168 lstrcpy(Globals.szFileName, "");
169 lstrcpy(Globals.szMarginTop, "25 mm");
170 lstrcpy(Globals.szMarginBottom, "25 mm");
171 lstrcpy(Globals.szMarginLeft, "20 mm");
172 lstrcpy(Globals.szMarginRight, "20 mm");
173 lstrcpy(Globals.szHeader, "&n");
174 lstrcpy(Globals.szFooter, "Page &s");
175 lstrcpy(Globals.Buffer, "Hello World");
177 if (!prev){
178 class.style = CS_HREDRAW | CS_VREDRAW;
179 class.lpfnWndProc = NOTEPAD_WndProc;
180 class.cbClsExtra = 0;
181 class.cbWndExtra = 0;
182 class.hInstance = Globals.hInstance;
183 class.hIcon = LoadIcon (0, IDI_APPLICATION);
184 class.hCursor = LoadCursor (0, IDC_ARROW);
185 class.hbrBackground = GetStockObject (WHITE_BRUSH);
186 class.lpszMenuName = 0;
187 class.lpszClassName = className;
190 if (!RegisterClass (&class)) return FALSE;
192 /* Setup windows */
195 Globals.hMainWnd = CreateWindow (className, winName,
196 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
197 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
198 LoadMenu(Globals.hInstance, STRING_MENU_Xx),
199 Globals.hInstance, 0);
201 Globals.hFindReplaceDlg = 0;
203 LANGUAGE_SelectByName(Globals.lpszLanguage);
205 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
207 ShowWindow (Globals.hMainWnd, show);
208 UpdateWindow (Globals.hMainWnd);
210 /* Set up dialogs */
212 /* Identify Messages originating from FindReplace */
214 Globals.nCommdlgFindReplaceMsg = RegisterWindowMessage("commdlg_FindReplace");
215 if (Globals.nCommdlgFindReplaceMsg==0) {
216 MessageBox(Globals.hMainWnd, "Could not register commdlg_FindReplace window message",
217 "Error", MB_ICONEXCLAMATION);
220 /* now handle command line */
222 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
225 CHAR option;
226 /* LPCSTR topic_id; */
228 if (*cmdline++ == ' ') continue;
230 option = *cmdline;
231 if (option) cmdline++;
232 while (*cmdline && *cmdline == ' ') cmdline++;
234 switch(option)
236 case 'p':
237 case 'P': printf("Print file: ");
238 /* Not yet able to print a file */
239 break;
243 /* Set up Drag&Drop */
245 DragAcceptFiles(Globals.hMainWnd, TRUE);
247 MessageBox(Globals.hMainWnd, "BEWARE!\nThis is ALPHA software that may destroy your file system.\nPlease take care.",
248 "A note from the developer...", MB_ICONEXCLAMATION);
250 /* now enter mesage loop */
252 while (GetMessage (&msg, 0, 0, 0)) {
253 if (IsDialogMessage(Globals.hFindReplaceDlg, &msg)!=0) {
254 /* Message belongs to FindReplace dialog */
255 /* We just let IsDialogMessage handle it */
257 else
259 /* Message belongs to the Notepad Main Window */
260 TranslateMessage (&msg);
261 DispatchMessage (&msg);
264 return 0;