Release 981025.
[wine/gsoc-2012-control.git] / programs / notepad / dialog.c
blob36f486208ccfe5517430f5016f7d675b7a8c61fc
1 /*
2 * Notepad (dialog.c)
4 * Copyright 1998 Marcel Baur <mbaur@g26.ethz.ch>
5 * To be distributed under the Wine License
6 */
8 #include <stdio.h>
9 #include <windows.h>
10 #include <commdlg.h>
11 #include <winerror.h>
13 #ifdef WINELIB
14 #include "shell.h"
15 #include "options.h"
16 #endif
18 #include "main.h"
19 #include "license.h"
20 #include "language.h"
21 #include "dialog.h"
23 #include "version.h"
24 #include "winnls.h"
25 #include "debug.h"
28 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
31 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
33 * Given some ids strings, this acts as a language-aware wrapper for
34 * "MessageBox"
36 CHAR szMessage[MAX_STRING_LEN];
37 CHAR szCaption[MAX_STRING_LEN];
39 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
40 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
42 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
45 void AlertFileNotFound(LPCSTR szFilename) {
47 int nResult;
49 nResult = AlertIDS(IDS_NOTFOUND, IDS_ERROR, MB_ICONEXCLAMATION);
53 VOID AlertOutOfMemory(void) {
55 int nResult;
57 nResult = AlertIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_ICONEXCLAMATION);
58 PostQuitMessage(1);
62 BOOL ExistFile(LPCSTR szFilename) {
64 * Returns: TRUE - if "szFileName" exists
65 * FALSE - if it does not
67 WIN32_FIND_DATA entry;
68 HANDLE32 handle;
70 handle = FindFirstFile(szFilename, &entry);
72 return (handle!=INVALID_HANDLE_VALUE32);
75 VOID DoSaveFile(VOID) {
76 // Really Save the file
78 // ... (Globals.szFileName);
82 BOOL DoCloseFile(void) {
83 // Return value: TRUE - User agreed to close (both save/don't save)
84 // FALSE - User cancelled close by selecting "Cancel"
86 CHAR szMessage[MAX_STRING_LEN];
87 CHAR szCaption[MAX_STRING_LEN];
89 INT nResult;
91 if (strlen(Globals.szFileName)>0) {
93 // prompt user to save changes
95 // FIXME: The following resources are not yet in the .rc files
96 // szMessage, szCaption show up random values. Please keep these lines!
98 strcpy(szMessage, "Save changes ?");
99 strcpy(szCaption, "Save changes");
101 // LoadString(Globals.hInstance, ids_savechanges, szMessage, sizeof(szMessage));
102 // LoadString(Globals.hInstance, ids_savetitle, szCaption, sizeof(szCaption));
104 nResult = MessageBox(Globals.hMainWnd, szMessage, szCaption, MB_YESNOCANCEL);
106 switch (nResult) {
107 case IDYES: DoSaveFile();
108 break;
110 case IDNO: break;
112 case IDCANCEL: return(FALSE);
113 break;
115 default: return(FALSE);
116 break;
122 // Forget file name
123 lstrcpy(Globals.szFileName, "");
124 LANGUAGE_UpdateWindowCaption();
126 return(TRUE);
131 void DoOpenFile(LPCSTR szFileName) {
133 // Close any files and prompt to save changes
134 if (DoCloseFile) {
136 // Open file
137 lstrcpy(Globals.szFileName, szFileName);
138 LANGUAGE_UpdateWindowCaption();
144 VOID DIALOG_FileNew(VOID)
146 // Close any files and promt to save changes
147 if (DoCloseFile()) {
149 // do nothing yet
155 VOID DIALOG_FileOpen(VOID)
158 OPENFILENAME openfilename;
159 CHAR szPath[MAX_PATHNAME_LEN];
160 CHAR szDir[MAX_PATHNAME_LEN];
161 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
162 CHAR szDefaultExt[4];
163 LPSTR p = szzFilter;
165 lstrcpy(szDefaultExt, "txt");
167 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
168 p += strlen(p) + 1;
169 lstrcpy(p, "*.txt");
170 p += strlen(p) + 1;
171 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
172 p += strlen(p) + 1;
173 lstrcpy(p, "*.*");
174 p += strlen(p) + 1;
175 *p = '\0';
177 GetCurrentDirectory(sizeof(szDir), szDir);
178 lstrcpy(szPath,"*.txt");
180 openfilename.lStructSize = sizeof(OPENFILENAME);
181 openfilename.hwndOwner = Globals.hMainWnd;
182 openfilename.hInstance = Globals.hInstance;
183 openfilename.lpstrFilter = szzFilter;
184 openfilename.lpstrCustomFilter = 0;
185 openfilename.nMaxCustFilter = 0;
186 openfilename.nFilterIndex = 0;
187 openfilename.lpstrFile = szPath;
188 openfilename.nMaxFile = sizeof(szPath);
189 openfilename.lpstrFileTitle = 0;
190 openfilename.nMaxFileTitle = 0;
191 openfilename.lpstrInitialDir = szDir;
192 openfilename.lpstrTitle = 0;
193 openfilename.Flags = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
194 openfilename.nFileOffset = 0;
195 openfilename.nFileExtension = 0;
196 openfilename.lpstrDefExt = szDefaultExt;
197 openfilename.lCustData = 0;
198 openfilename.lpfnHook = 0;
199 openfilename.lpTemplateName = 0;
201 if (GetOpenFileName(&openfilename)) {
203 if (ExistFile(openfilename.lpstrFile))
204 DoOpenFile(openfilename.lpstrFile);
205 else
206 AlertFileNotFound(openfilename.lpstrFile);
211 VOID DIALOG_FileSave(VOID)
213 fprintf(stderr, "FileSave()\n");
216 VOID DIALOG_FileSaveAs(VOID)
218 OPENFILENAME saveas;
219 CHAR szPath[MAX_PATHNAME_LEN];
220 CHAR szDir[MAX_PATHNAME_LEN];
221 CHAR szDefaultExt[4];
222 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
224 LPSTR p = szzFilter;
226 lstrcpy(szDefaultExt, "txt");
228 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
229 p += strlen(p) + 1;
230 lstrcpy(p, "*.txt");
231 p += strlen(p) + 1;
232 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
233 p += strlen(p) + 1;
234 lstrcpy(p, "*.*");
235 p += strlen(p) + 1;
236 *p = '\0';
238 lstrcpy(szPath,"*.*");
240 GetCurrentDirectory(sizeof(szDir), szDir);
242 saveas.lStructSize = sizeof(OPENFILENAME);
243 saveas.hwndOwner = Globals.hMainWnd;
244 saveas.hInstance = Globals.hInstance;
245 saveas.lpstrFilter = szzFilter;
246 saveas.lpstrCustomFilter = 0;
247 saveas.nMaxCustFilter = 0;
248 saveas.nFilterIndex = 0;
249 saveas.lpstrFile = szPath;
250 saveas.nMaxFile = sizeof(szPath);
251 saveas.lpstrFileTitle = 0;
252 saveas.nMaxFileTitle = 0;
253 saveas.lpstrInitialDir = szDir;
254 saveas.lpstrTitle = 0;
255 saveas.Flags = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
256 saveas.nFileOffset = 0;
257 saveas.nFileExtension = 0;
258 saveas.lpstrDefExt = szDefaultExt;
259 saveas.lCustData = 0;
260 saveas.lpfnHook = 0;
261 saveas.lpTemplateName = 0;
263 if (GetSaveFileName(&saveas)) {
264 lstrcpy(Globals.szFileName, saveas.lpstrFile);
265 LANGUAGE_UpdateWindowCaption();
266 DIALOG_FileSave();
270 VOID DIALOG_FilePrint(VOID)
272 PRINTDLG printer;
273 printer.lStructSize = sizeof(PRINTDLG);
274 printer.hwndOwner = Globals.hMainWnd;
275 printer.hInstance = Globals.hInstance;
276 printer.hDevMode = 0;
277 printer.hDevNames = 0;
278 printer.hDC = 0;
279 printer.Flags = 0;
280 printer.nFromPage = 0;
281 printer.nToPage = 0;
282 printer.nMinPage = 0;
283 printer.nMaxPage = 0;
284 printer.nCopies = 1;
285 printer.lCustData = 0;
286 printer.lpfnPrintHook = 0;
287 printer.lpfnSetupHook = 0;
288 printer.lpPrintTemplateName = 0;
289 printer.lpSetupTemplateName = 0;
290 printer.hPrintTemplate = 0;
291 printer.hSetupTemplate = 0;
293 if (PrintDlg(&printer)) {
294 // do nothing
298 VOID DIALOG_FilePageSetup(VOID)
300 DIALOG_PageSetup();
303 VOID DIALOG_FilePrinterSetup(VOID)
305 PRINTDLG printer;
306 printer.lStructSize = sizeof(PRINTDLG);
307 printer.hwndOwner = Globals.hMainWnd;
308 printer.hInstance = Globals.hInstance;
309 printer.hDevMode = 0;
310 printer.hDevNames = 0;
311 printer.hDC = 0;
312 printer.Flags = PD_PRINTSETUP;
313 printer.nFromPage = 0;
314 printer.nToPage = 0;
315 printer.nMinPage = 0;
316 printer.nMaxPage = 0;
317 printer.nCopies = 1;
318 printer.lCustData = 0;
319 printer.lpfnPrintHook = 0;
320 printer.lpfnSetupHook = 0;
321 printer.lpPrintTemplateName = 0;
322 printer.lpSetupTemplateName = 0;
323 printer.hPrintTemplate = 0;
324 printer.hSetupTemplate = 0;
326 if (PrintDlg(&printer)) {
327 // do nothing
332 VOID DIALOG_FileExit(VOID)
334 if (DoCloseFile()) {
335 PostQuitMessage(0);
339 VOID DIALOG_EditUndo(VOID)
341 fprintf(stderr, "EditUndo()\n");
344 VOID DIALOG_EditCut(VOID)
346 fprintf(stderr, "EditCut()\n");
349 VOID DIALOG_EditCopy(VOID)
351 fprintf(stderr, "EditCopy()\n");
354 VOID DIALOG_EditPaste(VOID)
356 fprintf(stderr, "EditPaste()\n");
359 VOID DIALOG_EditDelete(VOID)
361 fprintf(stderr, "EditDelete()\n");
364 VOID DIALOG_EditSelectAll(VOID)
366 fprintf(stderr, "EditSelectAll()\n");
369 VOID DIALOG_EditTimeDate(VOID)
371 DIALOG_TimeDate();
374 VOID DIALOG_EditWrap(VOID)
376 Globals.bWrapLongLines = !Globals.bWrapLongLines;
377 CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND |
378 (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
381 VOID DIALOG_Search(VOID)
383 FINDREPLACE find;
384 CHAR szFind[MAX_PATHNAME_LEN+10];
385 CHAR szReplace[MAX_PATHNAME_LEN+10];
387 HWND hResult;
389 lstrcpy(szReplace, "");
390 lstrcpy(szFind, Globals.szFindText);
392 find.lStructSize = sizeof(FINDREPLACE);
393 find.hwndOwner = Globals.hMainWnd;
394 find.hInstance = 0;
395 find.lpstrFindWhat = szFind;
396 find.wFindWhatLen = MAX_PATHNAME_LEN;
397 find.lpstrReplaceWith = szReplace;
398 find.wReplaceWithLen = MAX_PATHNAME_LEN;
399 find.Flags = FR_DOWN;
400 find.lCustData = 0;
401 find.lpfnHook = 0;
402 find.lpTemplateName = 0;
404 hResult = FindText(&find);
406 if (hResult) {
407 lstrcpy(Globals.szFindText, szFind);
409 else
411 // do nothing yet
416 VOID DIALOG_SearchNext(VOID)
418 fprintf(stderr, "SearchNext()\n");
421 VOID DIALOG_HelpContents(VOID)
423 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
426 VOID DIALOG_HelpSearch(VOID)
428 fprintf(stderr, "HelpSearch()\n");
431 VOID DIALOG_HelpHelp(VOID)
433 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
436 VOID DIALOG_HelpLicense(VOID)
438 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
441 VOID DIALOG_HelpNoWarranty(VOID)
443 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
446 VOID DIALOG_HelpAboutWine(VOID)
448 ShellAbout(Globals.hMainWnd, "Notepad", "Notepad\n" WINE_RELEASE_INFO, 0);
451 /***********************************************************************
453 * DIALOG_PageSetup
456 VOID DIALOG_PageSetup(VOID)
458 WNDPROC lpfnDlg;
460 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
461 DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, lpfnDlg);
462 FreeProcInstance(lpfnDlg);
465 /***********************************************************************
467 * DIALOG_TimeDate
470 VOID DIALOG_TimeDate(VOID)
472 // uses [KERNEL32.310] (ole2nls.c)
474 SYSTEMTIME st;
475 LPSYSTEMTIME lpst = &st;
476 CHAR szDate[MAX_STRING_LEN];
477 LPSTR date = szDate;
479 GetLocalTime(&st);
480 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
482 printf("Date: %s\n", date);
484 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
486 printf("Time: %s\n", date);
490 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
492 * DIALOG_PAGESETUP_DlgProc
495 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
497 switch (msg)
499 case WM_COMMAND:
500 switch (wParam)
502 case IDOK:
503 EndDialog(hDlg, IDOK);
504 return TRUE;
506 case IDCANCEL:
507 EndDialog(hDlg, IDCANCEL);
508 return TRUE;
510 break;
512 case WM_INITDIALOG:
513 SetDlgItemText(hDlg, NP_PAGESETUP_HEAD, Globals.szHeader);
514 SetDlgItemText(hDlg, NP_PAGESETUP_TAIL, Globals.szFooter);
515 SetDlgItemText(hDlg, NP_PAGESETUP_TOP, Globals.szMarginTop);
516 SetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom);
517 SetDlgItemText(hDlg, NP_PAGESETUP_LEFT, Globals.szMarginLeft);
518 SetDlgItemText(hDlg, NP_PAGESETUP_RIGHT, Globals.szMarginRight);
519 break;
521 case WM_CLOSE:
522 break;
524 return FALSE;
527 /* Local Variables: */
528 /* c-file-style: "GNU" */
529 /* End: */