Added some ordinals and GetDriverResourceID().
[wine/gsoc_dplay.git] / programs / notepad / dialog.c
blobe4c94281dbb037d8c5b4f1fbbf686a1ae4d5aecf
1 /*
2 * Notepad (dialog.c)
4 * Copyright 1998,99 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 #ifdef LCC
24 #define LCC_HASASSERT
25 #include "lcc.h"
26 #else
27 #include "version.h"
28 #include "winnls.h"
29 #endif
31 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
35 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
37 * Given some ids strings, this acts as a language-aware wrapper for
38 * "MessageBox"
40 CHAR szMessage[MAX_STRING_LEN];
41 CHAR szCaption[MAX_STRING_LEN];
43 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
44 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
46 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
49 void AlertFileNotFound(LPCSTR szFileName) {
51 int nResult;
52 CHAR szMessage[MAX_STRING_LEN];
53 CHAR szRessource[MAX_STRING_LEN];
55 /* Load and format szMessage */
56 LoadString(Globals.hInstance, IDS_NOTFOUND, szRessource, sizeof(szRessource));
57 wvsprintf(szMessage, szRessource, szFileName);
59 /* Load szCaption */
60 LoadString(Globals.hInstance, IDS_ERROR, szRessource, sizeof(szRessource));
62 /* Display Modal Dialog */
63 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
67 int AlertFileNotSaved(LPCSTR szFileName) {
69 int nResult;
70 CHAR szMessage[MAX_STRING_LEN];
71 CHAR szRessource[MAX_STRING_LEN];
73 /* Load and format Message */
75 LoadString(Globals.hInstance, IDS_NOTSAVED, szRessource, sizeof(szRessource));
76 wvsprintf(szMessage, szRessource, szFileName);
78 /* Load Caption */
80 LoadString(Globals.hInstance, IDS_ERROR, szRessource, sizeof(szRessource));
82 /* Display modal */
83 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION + MB_YESNOCANCEL);
84 return(nResult);
88 VOID AlertOutOfMemory(void) {
89 int nResult;
91 nResult = AlertIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_ICONEXCLAMATION);
92 PostQuitMessage(1);
96 BOOL ExistFile(LPCSTR szFilename) {
98 * Returns: TRUE - if "szFileName" exists
99 * FALSE - if it does not
101 WIN32_FIND_DATA entry;
102 HANDLE hFile;
104 hFile = FindFirstFile(szFilename, &entry);
106 return (hFile!=INVALID_HANDLE_VALUE);
109 VOID DoSaveFile(VOID) {
111 /* FIXME: Really Save the file */
112 /* ... (Globals.szFileName); */
116 BOOL DoCloseFile(void) {
117 /* Return value: TRUE - User agreed to close (both save/don't save) */
118 /* FALSE - User cancelled close by selecting "Cancel" */
120 int nResult;
122 if (strlen(Globals.szFileName)>0) {
123 /* prompt user to save changes */
124 nResult = AlertFileNotSaved(Globals.szFileName);
125 switch (nResult) {
126 case IDYES: DoSaveFile();
127 break;
129 case IDNO: break;
131 case IDCANCEL: return(FALSE);
132 break;
134 default: return(FALSE);
135 break;
136 } /* switch */
137 } /* if */
139 /* Forget file name */
140 lstrcpy(Globals.szFileName, "");
141 LANGUAGE_UpdateWindowCaption();
142 return(TRUE);
146 void DoOpenFile(LPCSTR szFileName) {
148 int hFile;
149 WORD nResult;
151 /* Close any files and prompt to save changes */
152 if (DoCloseFile) {
153 GetFileTitle(szFileName, Globals.szFileName, sizeof(Globals.szFileName));
154 LANGUAGE_UpdateWindowCaption();
155 hFile = _lopen(szFileName, OF_READ);
156 nResult = _lread(hFile, Globals.Buffer, sizeof(Globals.Buffer));
157 _lclose(hFile);
159 /* FIXME: Append time/date if first line contains LOGPREFIX */
160 /* (Globals.Buffer, ) */
165 VOID DIALOG_FileNew(VOID)
167 /* Close any files and promt to save changes */
168 if (DoCloseFile()) {
169 /* do nothing yet */
173 VOID DIALOG_FileOpen(VOID)
175 OPENFILENAME openfilename;
176 CHAR szPath[MAX_PATHNAME_LEN];
177 CHAR szDir[MAX_PATHNAME_LEN];
178 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
179 CHAR szDefaultExt[4];
180 LPSTR p = szzFilter;
182 lstrcpy(szDefaultExt, "txt");
184 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
185 p += strlen(p) + 1;
186 lstrcpy(p, "*.txt");
187 p += strlen(p) + 1;
188 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
189 p += strlen(p) + 1;
190 lstrcpy(p, "*.*");
191 p += strlen(p) + 1;
192 *p = '\0';
194 GetCurrentDirectory(sizeof(szDir), szDir);
195 lstrcpy(szPath,"*.txt");
197 openfilename.lStructSize = sizeof(OPENFILENAME);
198 openfilename.hwndOwner = Globals.hMainWnd;
199 openfilename.hInstance = Globals.hInstance;
200 openfilename.lpstrFilter = szzFilter;
201 openfilename.lpstrCustomFilter = 0;
202 openfilename.nMaxCustFilter = 0;
203 openfilename.nFilterIndex = 0;
204 openfilename.lpstrFile = szPath;
205 openfilename.nMaxFile = sizeof(szPath);
206 openfilename.lpstrFileTitle = 0;
207 openfilename.nMaxFileTitle = 0;
208 openfilename.lpstrInitialDir = szDir;
209 openfilename.lpstrTitle = 0;
210 openfilename.Flags = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
211 openfilename.nFileOffset = 0;
212 openfilename.nFileExtension = 0;
213 openfilename.lpstrDefExt = szDefaultExt;
214 openfilename.lCustData = 0;
215 openfilename.lpfnHook = 0;
216 openfilename.lpTemplateName = 0;
218 if (GetOpenFileName(&openfilename)) {
220 if (ExistFile(openfilename.lpstrFile))
221 DoOpenFile(openfilename.lpstrFile);
222 else
223 AlertFileNotFound(openfilename.lpstrFile);
228 VOID DIALOG_FileSave(VOID)
230 /* FIXME: Save File */
232 DIALOG_FileSaveAs();
235 VOID DIALOG_FileSaveAs(VOID)
237 OPENFILENAME saveas;
238 CHAR szPath[MAX_PATHNAME_LEN];
239 CHAR szDir[MAX_PATHNAME_LEN];
240 CHAR szDefaultExt[4];
241 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
243 LPSTR p = szzFilter;
245 lstrcpy(szDefaultExt, "txt");
247 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
248 p += strlen(p) + 1;
249 lstrcpy(p, "*.txt");
250 p += strlen(p) + 1;
251 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
252 p += strlen(p) + 1;
253 lstrcpy(p, "*.*");
254 p += strlen(p) + 1;
255 *p = '\0';
257 lstrcpy(szPath,"*.*");
259 GetCurrentDirectory(sizeof(szDir), szDir);
261 saveas.lStructSize = sizeof(OPENFILENAME);
262 saveas.hwndOwner = Globals.hMainWnd;
263 saveas.hInstance = Globals.hInstance;
264 saveas.lpstrFilter = szzFilter;
265 saveas.lpstrCustomFilter = 0;
266 saveas.nMaxCustFilter = 0;
267 saveas.nFilterIndex = 0;
268 saveas.lpstrFile = szPath;
269 saveas.nMaxFile = sizeof(szPath);
270 saveas.lpstrFileTitle = 0;
271 saveas.nMaxFileTitle = 0;
272 saveas.lpstrInitialDir = szDir;
273 saveas.lpstrTitle = 0;
274 saveas.Flags = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
275 saveas.nFileOffset = 0;
276 saveas.nFileExtension = 0;
277 saveas.lpstrDefExt = szDefaultExt;
278 saveas.lCustData = 0;
279 saveas.lpfnHook = 0;
280 saveas.lpTemplateName = 0;
282 if (GetSaveFileName(&saveas)) {
283 lstrcpy(Globals.szFileName, saveas.lpstrFile);
284 LANGUAGE_UpdateWindowCaption();
285 DIALOG_FileSave();
289 VOID DIALOG_FilePrint(VOID)
291 LONG bFlags, nBase;
292 WORD nOffset;
293 DOCINFO di;
294 int nResult;
295 HDC hContext;
296 PRINTDLG printer;
298 CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
299 CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */
300 CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */
301 CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */
303 /* LPDEVMODE hDevMode; */
304 /* LPDEVNAMES hDevNames; */
306 /* hDevMode = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
307 /* hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
309 /* Get Current Settings */
311 printer.lStructSize = sizeof(PRINTDLG);
312 printer.hwndOwner = Globals.hMainWnd;
313 printer.hInstance = Globals.hInstance;
315 /* Let PrintDlg create a DEVMODE structure */
316 printer.hDevMode = 0;
317 printer.hDevNames = 0;
318 printer.hDC = 0;
319 printer.Flags = PD_RETURNDEFAULT;
320 printer.nFromPage = 0;
321 printer.nToPage = 0;
322 printer.nMinPage = 0;
323 printer.nMaxPage = 0;
324 printer.nCopies = 0;
325 printer.lCustData = 0;
326 printer.lpfnPrintHook = 0;
327 printer.lpfnSetupHook = 0;
328 printer.lpPrintTemplateName = 0;
329 printer.lpSetupTemplateName = 0;
330 printer.hPrintTemplate = 0;
331 printer.hSetupTemplate = 0;
333 nResult = PrintDlg(&printer);
335 /* hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
337 /* Congratulations to those Microsoft Engineers responsable */
338 /* for the following pointer acrobatics */
340 assert(printer.hDevNames!=0);
342 nBase = (LONG)(printer.hDevNames);
344 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
345 lstrcpy(szPrinterName, (LPCSTR) (nBase + nOffset));
347 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
348 lstrcpy(szDeviceName, (LPCSTR) (nBase + nOffset));
350 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
351 lstrcpy(szOutput, (LPCSTR) (nBase + nOffset));
353 MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
354 MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION);
355 MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION);
357 /* Set some default flags */
359 bFlags = PD_RETURNDC + PD_SHOWHELP;
361 if (TRUE) {
362 /* Remove "Print Selection" if there is no selection */
363 bFlags = bFlags + PD_NOSELECTION;
366 printer.Flags = bFlags;
368 printer.nFromPage = 0;
369 printer.nToPage = 0;
370 printer.nMinPage = 0;
371 printer.nMaxPage = 0;
374 /* Let commdlg manage copy settings */
375 printer.nCopies = PD_USEDEVMODECOPIES;
377 if (PrintDlg(&printer)) {
379 /* initialize DOCINFO */
380 di.cbSize = sizeof(DOCINFO);
381 lstrcpy(di.lpszDocName, szDocumentName);
382 lstrcpy(di.lpszOutput, szOutput);
384 hContext = printer.hDC;
385 assert(hContext!=0);
386 assert( (int) hContext!=PD_RETURNDC);
388 SetMapMode(hContext, MM_LOMETRIC);
389 /* SetViewPortExExt(hContext, 10, 10, 0); */
390 SetBkMode(hContext, OPAQUE);
392 nResult = TextOut(hContext, 0, 0, " ", 1);
393 assert(nResult != 0);
395 nResult = StartDoc(hContext, &di);
396 assert(nResult != SP_ERROR);
398 nResult = StartPage(hContext);
399 assert(nResult >0);
401 /* FIXME: actually print */
403 nResult = EndPage(hContext);
405 switch (nResult) {
406 case SP_ERROR:
407 MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
408 break;
409 case SP_APPABORT:
410 MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
411 break;
412 case SP_USERABORT:
413 MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
414 break;
415 case SP_OUTOFDISK:
416 MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
417 break;
418 case SP_OUTOFMEMORY:
419 AlertOutOfMemory();
420 break;
421 default:
422 MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION);
423 } /* switch */
424 nResult = EndDoc(hContext);
425 assert(nResult>=0);
426 nResult = DeleteDC(hContext);
427 assert(nResult!=0);
428 } /* if */
430 /* GlobalFree(hDevNames); */
431 /* GlobalFree(hDevMode); */
434 VOID DIALOG_FilePageSetup(VOID)
436 DIALOG_PageSetup();
439 VOID DIALOG_FilePrinterSetup(VOID)
441 PRINTDLG printer;
443 printer.lStructSize = sizeof(PRINTDLG);
444 printer.hwndOwner = Globals.hMainWnd;
445 printer.hInstance = Globals.hInstance;
446 printer.hDevMode = 0;
447 printer.hDevNames = 0;
448 printer.hDC = 0;
449 printer.Flags = PD_PRINTSETUP;
450 printer.nFromPage = 0;
451 printer.nToPage = 0;
452 printer.nMinPage = 0;
453 printer.nMaxPage = 0;
454 printer.nCopies = 1;
455 printer.lCustData = 0;
456 printer.lpfnPrintHook = 0;
457 printer.lpfnSetupHook = 0;
458 printer.lpPrintTemplateName = 0;
459 printer.lpSetupTemplateName = 0;
460 printer.hPrintTemplate = 0;
461 printer.hSetupTemplate = 0;
463 if (PrintDlg(&printer)) {
464 /* do nothing */
469 VOID DIALOG_FileExit(VOID)
471 if (DoCloseFile()) {
472 PostQuitMessage(0);
476 VOID DIALOG_EditUndo(VOID)
478 MessageBox(Globals.hMainWnd, "Undo", "Debug", MB_ICONEXCLAMATION);
479 /* undo */
482 VOID DIALOG_EditCut(VOID)
484 HANDLE hMem;
486 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
488 OpenClipboard(Globals.hMainWnd);
489 EmptyClipboard();
491 /* FIXME: Get text */
492 lstrcpy((CHAR *)hMem, "Hello World");
494 SetClipboardData(CF_TEXT, hMem);
495 CloseClipboard();
497 GlobalFree(hMem);
500 VOID DIALOG_EditCopy(VOID)
502 HANDLE hMem;
504 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
506 OpenClipboard(Globals.hMainWnd);
507 EmptyClipboard();
509 /* FIXME: Get text */
510 lstrcpy((CHAR *)hMem, "Hello World");
512 SetClipboardData(CF_TEXT, hMem);
513 CloseClipboard();
515 GlobalFree(hMem);
518 VOID DIALOG_EditPaste(VOID)
520 HANDLE hClipText;
522 if (IsClipboardFormatAvailable(CF_TEXT)) {
523 OpenClipboard(Globals.hMainWnd);
524 hClipText = GetClipboardData(CF_TEXT);
525 CloseClipboard();
526 MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
530 VOID DIALOG_EditDelete(VOID)
532 /* Delete */
535 VOID DIALOG_EditSelectAll(VOID)
537 /* Select all */
540 VOID DIALOG_EditTimeDate(VOID)
542 SYSTEMTIME st;
543 LPSYSTEMTIME lpst = &st;
544 CHAR szDate[MAX_STRING_LEN];
545 LPSTR date = szDate;
547 GetLocalTime(&st);
548 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
549 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
553 VOID DIALOG_EditWrap(VOID)
555 Globals.bWrapLongLines = !Globals.bWrapLongLines;
556 CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND |
557 (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
560 VOID DIALOG_Search(VOID)
562 Globals.find.lStructSize = sizeof(Globals.find);
563 Globals.find.hwndOwner = Globals.hMainWnd;
564 Globals.find.hInstance = Globals.hInstance;
565 Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText;
566 Globals.find.wFindWhatLen = sizeof(Globals.szFindText);
567 Globals.find.lpstrReplaceWith = 0;
568 Globals.find.wReplaceWithLen = 0;
569 Globals.find.Flags = FR_DOWN;
570 Globals.find.lCustData = 0;
571 Globals.find.lpfnHook = 0;
572 Globals.find.lpTemplateName = 0;
574 /* We only need to create the modal FindReplace dialog which will */
575 /* notify us of incoming events using hMainWnd Window Messages */
577 Globals.hFindReplaceDlg = FindText(&Globals.find);
578 assert(Globals.hFindReplaceDlg !=0);
581 VOID DIALOG_SearchNext(VOID)
583 /* Search Next */
586 VOID DIALOG_HelpContents(VOID)
588 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
591 VOID DIALOG_HelpSearch(VOID)
593 /* Search Help */
596 VOID DIALOG_HelpHelp(VOID)
598 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
601 VOID DIALOG_HelpLicense(VOID)
603 WineLicense(Globals.hMainWnd, Globals.lpszLanguage);
606 VOID DIALOG_HelpNoWarranty(VOID)
608 WineWarranty(Globals.hMainWnd, Globals.lpszLanguage);
611 VOID DIALOG_HelpAboutWine(VOID)
613 CHAR szNotepad[MAX_STRING_LEN];
615 LoadString(Globals.hInstance, IDS_NOTEPAD, szNotepad, sizeof(szNotepad));
616 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
619 /***********************************************************************
621 * DIALOG_PageSetup
624 VOID DIALOG_PageSetup(VOID)
626 WNDPROC lpfnDlg;
628 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
629 DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, lpfnDlg);
630 FreeProcInstance(lpfnDlg);
634 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
636 * DIALOG_PAGESETUP_DlgProc
639 static LRESULT DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
642 switch (msg)
644 case WM_COMMAND:
645 switch (wParam)
647 case IDOK:
648 /* save user input and close dialog */
649 GetDlgItemText(hDlg, NP_PAGESETUP_HEAD, Globals.szHeader, sizeof(Globals.szHeader));
650 GetDlgItemText(hDlg, NP_PAGESETUP_TAIL, Globals.szFooter, sizeof(Globals.szFooter));
651 GetDlgItemText(hDlg, NP_PAGESETUP_TOP, Globals.szMarginTop, sizeof(Globals.szMarginTop));
652 GetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
653 GetDlgItemText(hDlg, NP_PAGESETUP_LEFT, Globals.szMarginLeft, sizeof(Globals.szMarginLeft));
654 GetDlgItemText(hDlg, NP_PAGESETUP_RIGHT, Globals.szMarginRight, sizeof(Globals.szMarginRight));
655 EndDialog(hDlg, IDOK);
656 return TRUE;
658 case IDCANCEL:
659 /* discard user input and close dialog */
660 EndDialog(hDlg, IDCANCEL);
661 return TRUE;
663 case IDHELP:
664 /* FIXME: Bring this to work */
665 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
666 return TRUE;
668 break;
670 case WM_INITDIALOG:
671 /* fetch last user input prior to display dialog */
672 SetDlgItemText(hDlg, NP_PAGESETUP_HEAD, Globals.szHeader);
673 SetDlgItemText(hDlg, NP_PAGESETUP_TAIL, Globals.szFooter);
674 SetDlgItemText(hDlg, NP_PAGESETUP_TOP, Globals.szMarginTop);
675 SetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom);
676 SetDlgItemText(hDlg, NP_PAGESETUP_LEFT, Globals.szMarginLeft);
677 SetDlgItemText(hDlg, NP_PAGESETUP_RIGHT, Globals.szMarginRight);
678 break;
681 return FALSE;