Fixed small typo.
[wine.git] / programs / notepad / dialog.c
blob3fb491a8e910c56fe1cec35e69d9de80a77e7c48
1 /*
2 * Notepad
4 * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
5 */
7 #include <stdio.h>
8 #include "windows.h"
9 #include "commdlg.h"
10 #include "winnls.h"
11 #include "winerror.h"
12 #ifdef WINELIB
13 #include "shell.h"
14 #include "options.h"
15 #endif
16 #include "main.h"
17 #include "license.h"
18 #include "language.h"
19 #include "dialog.h"
20 #include "version.h"
21 #include "debug.h"
24 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
27 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
29 * Given some ids strings, this acts as a language-aware wrapper for
30 * "MessageBox"
32 CHAR szMessage[MAX_STRING_LEN];
33 CHAR szCaption[MAX_STRING_LEN];
35 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
36 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
38 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
41 void AlertFileNotFound(LPCSTR szFilename) {
43 int nResult;
45 nResult = AlertIDS(IDS_NOTFOUND, IDS_ERROR, 0);
49 VOID AlertOutOfMemory(void) {
51 int nResult;
53 nResult = AlertIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, 0);
54 PostQuitMessage(1);
58 BOOL ExistFile(LPCSTR szFilename) {
60 * Returns: TRUE - if "szFileName" exists
61 * FALSE - if it does not
63 WIN32_FIND_DATA32A entry;
64 HANDLE32 handle;
66 handle = FindFirstFile32A(szFilename, &entry);
68 return (handle!=INVALID_HANDLE_VALUE32);
71 VOID DoSaveFile(VOID) {
72 // Really Save the file
74 // ... (Globals.szFileName);
78 BOOL DoCloseFile(void) {
79 // Return value: TRUE - User agreed to close (both save/don't save)
80 // FALSE - User cancelled close by selecting "Cancel"
82 CHAR szMessage[MAX_STRING_LEN];
83 CHAR szCaption[MAX_STRING_LEN];
85 INT nResult;
87 if (strlen(Globals.szFileName)>0) {
89 // prompt user to save changes
91 // FIXME: The following resources are not yet in the .rc files
92 // szMessage, szCaption show up random values. Please keep these lines!
94 // LoadString(Globals.hInstance, ids_savechanges, szMessage, sizeof(szMessage));
95 // LoadString(Globals.hInstance, ids_savetitle, szCaption, sizeof(szCaption));
97 nResult = MessageBox(Globals.hMainWnd, szMessage, szCaption, MB_YESNOCANCEL);
99 switch (nResult) {
100 case IDYES: DoSaveFile();
101 break;
102 case IDNO: break;
103 case IDCANCEL: return(FALSE);
104 break;
106 default: return(FALSE);
107 break;
113 // Forget file name
115 lstrcpyn(Globals.szFileName, "\0", 1);
116 LANGUAGE_UpdateWindowCaption();
118 return(TRUE);
123 void DoOpenFile(LPCSTR szFileName) {
125 // Close any files and prompt to save changes
126 if (DoCloseFile) {
128 // Open file
129 lstrcpyn(Globals.szFileName, szFileName, strlen(szFileName)+1);
130 LANGUAGE_UpdateWindowCaption();
136 VOID DIALOG_FileNew(VOID)
138 // Close any files and promt to save changes
139 if (DoCloseFile()) {
141 // do nothing yet
147 VOID DIALOG_FileOpen(VOID)
150 OPENFILENAME openfilename;
151 CHAR szPath[MAX_PATHNAME_LEN];
152 CHAR szDir[MAX_PATHNAME_LEN];
153 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
154 LPSTR p = szzFilter;
156 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
157 p += strlen(p) + 1;
158 lstrcpy(p, "*.txt");
159 p += strlen(p) + 1;
160 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
161 p += strlen(p) + 1;
162 lstrcpy(p, "*.*");
163 p += strlen(p) + 1;
164 *p = '\0';
166 GetWindowsDirectory(szDir, sizeof(szDir));
168 openfilename.lStructSize = sizeof(openfilename);
169 openfilename.hwndOwner = Globals.hMainWnd;
170 openfilename.hInstance = Globals.hInstance;
171 openfilename.lpstrFilter = szzFilter;
172 openfilename.lpstrCustomFilter = 0;
173 openfilename.nMaxCustFilter = 0;
174 openfilename.nFilterIndex = 0;
175 openfilename.lpstrFile = szPath;
176 openfilename.nMaxFile = sizeof(szPath);
177 openfilename.lpstrFileTitle = 0;
178 openfilename.nMaxFileTitle = 0;
179 openfilename.lpstrInitialDir = szDir;
180 openfilename.lpstrTitle = 0;
181 openfilename.Flags = 0;
182 openfilename.nFileOffset = 0;
183 openfilename.nFileExtension = 0;
184 openfilename.lpstrDefExt = 0;
185 openfilename.lCustData = 0;
186 openfilename.lpfnHook = 0;
187 openfilename.lpTemplateName = 0;
189 if (GetOpenFileName(&openfilename)) {
191 if (ExistFile(openfilename.lpstrFile))
192 DoOpenFile(openfilename.lpstrFile);
193 else
194 AlertFileNotFound(openfilename.lpstrFile);
200 VOID DIALOG_FileSave(VOID)
202 fprintf(stderr, "FileSave()\n");
205 VOID DIALOG_FileSaveAs(VOID)
207 OPENFILENAME saveas;
208 CHAR szPath[MAX_PATHNAME_LEN];
209 CHAR szDir[MAX_PATHNAME_LEN];
210 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
211 LPSTR p = szzFilter;
213 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
214 p += strlen(p) + 1;
215 lstrcpy(p, "*.txt");
216 p += strlen(p) + 1;
217 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
218 p += strlen(p) + 1;
219 lstrcpy(p, "*.*");
220 p += strlen(p) + 1;
221 *p = '\0';
223 GetWindowsDirectory(szDir, sizeof(szDir));
225 saveas.lStructSize = 0;
226 saveas.hwndOwner = Globals.hMainWnd;
227 saveas.hInstance = Globals.hInstance;
228 saveas.lpstrFilter = szzFilter;
229 saveas.lpstrCustomFilter = 0;
230 saveas.nMaxCustFilter = 0;
231 saveas.nFilterIndex = 0;
232 saveas.lpstrFile = szPath;
233 saveas.nMaxFile = sizeof(szPath);
234 saveas.lpstrFileTitle = 0;
235 saveas.nMaxFileTitle = 0;
236 saveas.lpstrInitialDir = szDir;
237 saveas.lpstrTitle = 0;
238 saveas.Flags = 0;
239 saveas.nFileOffset = 0;
240 saveas.nFileExtension = 0;
241 saveas.lpstrDefExt = 0;
242 saveas.lCustData = 0;
243 saveas.lpfnHook = 0;
244 saveas.lpTemplateName = 0;
246 if (GetSaveFileName(&saveas)) {
247 lstrcpyn(Globals.szFileName, saveas.lpstrFile,
248 strlen(saveas.lpstrFile)+1);
249 LANGUAGE_UpdateWindowCaption();
250 DIALOG_FileSave();
254 VOID DIALOG_FilePrint(VOID)
256 PRINTDLG printer;
257 printer.lStructSize = sizeof(printer);
258 printer.hwndOwner = Globals.hMainWnd;
259 printer.hInstance = Globals.hInstance;
260 printer.hDevMode = 0;
261 printer.hDevNames = 0;
262 printer.hDC = 0;
263 printer.Flags = 0;
264 printer.nFromPage = 0;
265 printer.nToPage = 0;
266 printer.nMinPage = 0;
267 printer.nMaxPage = 0;
268 printer.nCopies = 0;
269 printer.lCustData = 0;
270 printer.lpfnPrintHook = 0;
271 printer.lpfnSetupHook = 0;
272 printer.lpPrintTemplateName = 0;
273 printer.lpSetupTemplateName = 0;
274 printer.hPrintTemplate = 0;
275 printer.hSetupTemplate = 0;
277 if (PrintDlg16(&printer)) {
278 // do nothing
282 VOID DIALOG_FilePageSetup(VOID)
284 DIALOG_PageSetup();
287 VOID DIALOG_FilePrinterSetup(VOID)
289 fprintf(stderr, "FilePrinterSetup()\n");
292 VOID DIALOG_FileExit(VOID)
294 if (DoCloseFile()) {
295 PostQuitMessage(0);
299 VOID DIALOG_EditUndo(VOID)
301 fprintf(stderr, "EditUndo()\n");
304 VOID DIALOG_EditCut(VOID)
306 fprintf(stderr, "EditCut()\n");
309 VOID DIALOG_EditCopy(VOID)
311 fprintf(stderr, "EditCopy()\n");
314 VOID DIALOG_EditPaste(VOID)
316 fprintf(stderr, "EditPaste()\n");
319 VOID DIALOG_EditDelete(VOID)
321 fprintf(stderr, "EditDelete()\n");
324 VOID DIALOG_EditSelectAll(VOID)
326 fprintf(stderr, "EditSelectAll()\n");
329 VOID DIALOG_EditTimeDate(VOID)
331 DIALOG_TimeDate();
334 VOID DIALOG_EditWrap(VOID)
336 Globals.bWrapLongLines = !Globals.bWrapLongLines;
337 CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND |
338 (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
341 VOID DIALOG_Search(VOID)
343 FINDREPLACE find;
344 CHAR szFind[MAX_PATHNAME_LEN];
346 lstrcpyn(szFind, Globals.szFindText, strlen(Globals.szFindText)+1);
348 find.lStructSize = sizeof(find);
349 find.hwndOwner = Globals.hMainWnd;
350 find.hInstance = Globals.hInstance;
351 find.lpstrFindWhat = szFind;
352 find.wFindWhatLen = sizeof(szFind);
353 find.Flags = 0;
354 find.lCustData = 0;
355 find.lpfnHook = 0;
356 find.lpTemplateName = 0;
358 if (FindText(&find)) {
359 lstrcpyn(Globals.szFindText, szFind, strlen(szFind)+1);
361 else
363 // do nothing yet
367 VOID DIALOG_SearchNext(VOID)
369 fprintf(stderr, "SearchNext()\n");
372 VOID DIALOG_HelpContents(VOID)
374 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
377 VOID DIALOG_HelpSearch(VOID)
379 fprintf(stderr, "HelpSearch()\n");
382 VOID DIALOG_HelpHelp(VOID)
384 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
387 VOID DIALOG_HelpLicense(VOID)
389 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
392 VOID DIALOG_HelpNoWarranty(VOID)
394 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
397 VOID DIALOG_HelpAboutWine(VOID)
399 ShellAbout(Globals.hMainWnd, "Notepad", "Notepad\n" WINE_RELEASE_INFO, 0);
402 /***********************************************************************
404 * DIALOG_PageSetup
407 VOID DIALOG_PageSetup(VOID)
409 WNDPROC lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
410 DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, lpfnDlg);
411 FreeProcInstance(lpfnDlg);
414 /***********************************************************************
416 * DIALOG_TimeDate
419 VOID DIALOG_TimeDate(VOID)
421 // uses [KERNEL32.310] (ole2nls.c)
423 SYSTEMTIME st;
424 LPSYSTEMTIME lpst = &st;
425 CHAR szDate[MAX_STRING_LEN];
426 LPSTR date = szDate;
428 GetLocalTime(&st);
429 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
431 printf("Date: %s\n", date);
433 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
435 printf("Time: %s\n", date);
439 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
441 * DIALOG_PAGESETUP_DlgProc
444 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
446 switch (msg)
448 case WM_COMMAND:
449 switch (wParam)
451 case IDOK:
452 EndDialog(hDlg, IDOK);
453 return TRUE;
455 case IDCANCEL:
456 EndDialog(hDlg, IDCANCEL);
457 return TRUE;
460 return FALSE;
463 /* Local Variables: */
464 /* c-file-style: "GNU" */
465 /* End: */