4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
39 DWORD error = GetLastError();
40 if (error != NO_ERROR)
43 CHAR szTitle[MAX_STRING_LEN];
45 LoadString(Globals.hInstance, STRING_ERROR, szTitle, sizeof(szTitle));
47 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
49 (LPTSTR) &lpMsgBuf, 0, NULL);
50 MessageBox(NULL, (char*)lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
56 * Sets the caption of the main window according to Globals.szFileTitle:
57 * Notepad - (untitled) if no file is open
58 * Notepad - [filename] if a file is given
60 void UpdateWindowCaption(void) {
61 CHAR szCaption[MAX_STRING_LEN];
62 CHAR szUntitled[MAX_STRING_LEN];
64 LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, sizeof(szCaption));
66 if (Globals.szFileTitle[0] != '\0') {
67 lstrcat(szCaption, " - [");
68 lstrcat(szCaption, Globals.szFileTitle);
69 lstrcat(szCaption, "]");
73 LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, sizeof(szUntitled));
74 lstrcat(szCaption, " - ");
75 lstrcat(szCaption, szUntitled);
78 SetWindowText(Globals.hMainWnd, szCaption);
82 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
84 * Given some ids strings, this acts as a language-aware wrapper for
87 CHAR szMessage[MAX_STRING_LEN];
88 CHAR szCaption[MAX_STRING_LEN];
90 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
91 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
93 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
96 void AlertFileNotFound(LPSTR szFileName) {
99 CHAR szMessage[MAX_STRING_LEN];
100 CHAR szRessource[MAX_STRING_LEN];
102 /* Load and format szMessage */
103 LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource));
104 wsprintf(szMessage, szRessource, szFileName);
107 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
109 /* Display Modal Dialog */
110 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
114 int AlertFileNotSaved(LPSTR szFileName) {
117 CHAR szMessage[MAX_STRING_LEN];
118 CHAR szRessource[MAX_STRING_LEN];
120 /* Load and format Message */
122 LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource));
123 wsprintf(szMessage, szRessource, szFileName);
127 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
130 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
135 VOID AlertOutOfMemory(void) {
138 nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
145 * TRUE - if file exists
146 * FALSE - if file does not exist
148 BOOL FileExists(LPSTR szFilename) {
149 WIN32_FIND_DATA entry;
152 hFile = FindFirstFile(szFilename, &entry);
155 return (hFile != INVALID_HANDLE_VALUE);
159 VOID DoSaveFile(VOID) {
166 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
167 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
168 if(hFile == INVALID_HANDLE_VALUE)
174 size = GetWindowTextLength(Globals.hEdit);
175 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
181 GetWindowText(Globals.hEdit, pTemp, size);
183 bTest = WriteFile(hFile, pTemp, size, &dwNumWrite, NULL);
194 * TRUE - User agreed to close (both save/don't save)
195 * FALSE - User cancelled close by selecting "Cancel"
197 BOOL DoCloseFile(void) {
200 if (Globals.szFileName[0] != 0) {
201 /* prompt user to save changes */
202 nResult = AlertFileNotSaved(Globals.szFileName);
204 case IDYES: DIALOG_FileSave();
209 case IDCANCEL: return(FALSE);
212 default: return(FALSE);
219 UpdateWindowCaption();
224 void DoOpenFile(LPSTR szFileName) {
225 /* Close any files and prompt to save changes */
233 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
234 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
235 if(hFile == INVALID_HANDLE_VALUE)
241 size = GetFileSize(hFile, NULL);
242 if (size == 0xFFFFFFFF)
248 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
254 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
260 pTemp[dwNumRead] = '\0';
261 if (!SetWindowText(Globals.hEdit, pTemp))
267 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
269 SetFocus(Globals.hEdit);
271 SetFileName(szFileName);
272 UpdateWindowCaption();
276 VOID DIALOG_FileNew(VOID)
278 /* Close any files and promt to save changes */
280 SetWindowText(Globals.hEdit, "");
281 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
282 SetFocus(Globals.hEdit);
286 VOID DIALOG_FileOpen(VOID)
288 OPENFILENAME openfilename;
290 CHAR szPath[MAX_PATH];
291 CHAR szDir[MAX_PATH];
292 CHAR szDefaultExt[] = "txt";
294 ZeroMemory(&openfilename, sizeof(openfilename));
296 GetCurrentDirectory(sizeof(szDir), szDir);
297 lstrcpy(szPath,"*.txt");
299 openfilename.lStructSize = sizeof(openfilename);
300 openfilename.hwndOwner = Globals.hMainWnd;
301 openfilename.hInstance = Globals.hInstance;
302 openfilename.lpstrFilter = Globals.szFilter;
303 openfilename.lpstrFile = szPath;
304 openfilename.nMaxFile = sizeof(szPath);
305 openfilename.lpstrInitialDir = szDir;
306 openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
308 openfilename.lpstrDefExt = szDefaultExt;
311 if (GetOpenFileName(&openfilename)) {
312 if (FileExists(openfilename.lpstrFile))
313 DoOpenFile(openfilename.lpstrFile);
315 AlertFileNotFound(openfilename.lpstrFile);
320 VOID DIALOG_FileSave(VOID)
322 if (Globals.szFileName[0] == '\0')
328 VOID DIALOG_FileSaveAs(VOID)
331 CHAR szPath[MAX_PATH];
332 CHAR szDir[MAX_PATH];
333 CHAR szDefaultExt[] = "txt";
335 ZeroMemory(&saveas, sizeof(saveas));
337 GetCurrentDirectory(sizeof(szDir), szDir);
338 lstrcpy(szPath,"*.*");
340 saveas.lStructSize = sizeof(OPENFILENAME);
341 saveas.hwndOwner = Globals.hMainWnd;
342 saveas.hInstance = Globals.hInstance;
343 saveas.lpstrFilter = Globals.szFilter;
344 saveas.lpstrFile = szPath;
345 saveas.nMaxFile = sizeof(szPath);
346 saveas.lpstrInitialDir = szDir;
347 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
349 saveas.lpstrDefExt = szDefaultExt;
351 if (GetSaveFileName(&saveas)) {
353 UpdateWindowCaption();
358 VOID DIALOG_FilePrint(VOID)
367 CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
368 CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */
369 CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */
370 CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */
372 /* LPDEVMODE hDevMode; */
373 /* LPDEVNAMES hDevNames; */
375 /* hDevMode = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
376 /* hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
378 /* Get Current Settings */
379 ZeroMemory(&printer, sizeof(printer));
380 printer.lStructSize = sizeof(printer);
381 printer.hwndOwner = Globals.hMainWnd;
382 printer.hInstance = Globals.hInstance;
384 nResult = PrintDlg(&printer);
386 /* hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
388 /* Congratulations to those Microsoft Engineers responsible */
389 /* for the following pointer acrobatics */
391 assert(printer.hDevNames!=0);
393 nBase = (LONG)(printer.hDevNames);
395 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
396 lstrcpy(szPrinterName, (LPSTR) (nBase + nOffset));
398 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
399 lstrcpy(szDeviceName, (LPSTR) (nBase + nOffset));
401 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
402 lstrcpy(szOutput, (LPSTR) (nBase + nOffset));
404 MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
405 MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION);
406 MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION);
408 /* Set some default flags */
410 bFlags = PD_RETURNDC + PD_SHOWHELP;
413 /* Remove "Print Selection" if there is no selection */
414 bFlags = bFlags + PD_NOSELECTION;
417 printer.Flags = bFlags;
419 printer.nFromPage = 0;
421 printer.nMinPage = 0;
422 printer.nMaxPage = 0;
425 /* Let commdlg manage copy settings */
426 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
428 if (PrintDlg(&printer)) {
430 /* initialize DOCINFO */
431 di.cbSize = sizeof(DOCINFO);
432 lstrcpy((LPSTR)di.lpszDocName, szDocumentName);
433 lstrcpy((LPSTR)di.lpszOutput, szOutput);
435 hContext = printer.hDC;
437 assert( (int) hContext!=PD_RETURNDC);
439 SetMapMode(hContext, MM_LOMETRIC);
440 /* SetViewPortExExt(hContext, 10, 10, 0); */
441 SetBkMode(hContext, OPAQUE);
443 nResult = TextOut(hContext, 0, 0, " ", 1);
444 assert(nResult != 0);
446 nResult = StartDoc(hContext, &di);
447 assert(nResult != SP_ERROR);
449 nResult = StartPage(hContext);
452 /* FIXME: actually print */
454 nResult = EndPage(hContext);
458 MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
461 MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
464 MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
467 MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
473 MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION);
475 nResult = EndDoc(hContext);
477 nResult = DeleteDC(hContext);
481 /* GlobalFree(hDevNames); */
482 /* GlobalFree(hDevMode); */
485 VOID DIALOG_FilePageSetup(VOID)
490 VOID DIALOG_FilePrinterSetup(VOID)
494 ZeroMemory(&printer, sizeof(printer));
495 printer.lStructSize = sizeof(printer);
496 printer.hwndOwner = Globals.hMainWnd;
497 printer.hInstance = Globals.hInstance;
498 printer.Flags = PD_PRINTSETUP;
501 if (PrintDlg(&printer)) {
506 VOID DIALOG_FileExit(VOID)
508 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
511 VOID DIALOG_EditUndo(VOID)
513 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
516 VOID DIALOG_EditCut(VOID)
520 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
522 OpenClipboard(Globals.hMainWnd);
525 /* FIXME: Get text */
526 lstrcpy((CHAR *)hMem, "Hello World");
528 SetClipboardData(CF_TEXT, hMem);
534 VOID DIALOG_EditCopy(VOID)
538 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
540 OpenClipboard(Globals.hMainWnd);
543 /* FIXME: Get text */
544 lstrcpy((CHAR *)hMem, "Hello World");
546 SetClipboardData(CF_TEXT, hMem);
552 VOID DIALOG_EditPaste(VOID)
556 if (IsClipboardFormatAvailable(CF_TEXT)) {
557 OpenClipboard(Globals.hMainWnd);
558 hClipText = GetClipboardData(CF_TEXT);
560 MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
564 VOID DIALOG_EditDelete(VOID)
569 VOID DIALOG_EditSelectAll(VOID)
575 VOID DIALOG_EditTimeDate(VOID)
578 LPSYSTEMTIME lpst = &st;
579 CHAR szDate[MAX_STRING_LEN];
583 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
584 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
587 VOID DIALOG_EditWrap(VOID)
589 Globals.bWrapLongLines = !Globals.bWrapLongLines;
590 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
591 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
594 VOID DIALOG_Search(VOID)
596 ZeroMemory(&Globals.find, sizeof(Globals.find));
597 Globals.find.lStructSize = sizeof(Globals.find);
598 Globals.find.hwndOwner = Globals.hMainWnd;
599 Globals.find.hInstance = Globals.hInstance;
600 Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText;
601 Globals.find.wFindWhatLen = sizeof(Globals.szFindText);
602 Globals.find.Flags = FR_DOWN;
604 /* We only need to create the modal FindReplace dialog which will */
605 /* notify us of incoming events using hMainWnd Window Messages */
607 Globals.hFindReplaceDlg = FindText(&Globals.find);
608 assert(Globals.hFindReplaceDlg !=0);
611 VOID DIALOG_SearchNext(VOID)
616 VOID DIALOG_HelpContents(VOID)
618 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
621 VOID DIALOG_HelpSearch(VOID)
626 VOID DIALOG_HelpHelp(VOID)
628 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
631 VOID DIALOG_HelpLicense(VOID)
633 WineLicense(Globals.hMainWnd);
636 VOID DIALOG_HelpNoWarranty(VOID)
638 WineWarranty(Globals.hMainWnd);
641 VOID DIALOG_HelpAboutWine(VOID)
643 CHAR szNotepad[MAX_STRING_LEN];
645 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad));
646 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
650 /***********************************************************************
655 VOID DIALOG_PageSetup(VOID)
659 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
660 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
661 Globals.hMainWnd, (DLGPROC)lpfnDlg);
662 FreeProcInstance(lpfnDlg);
666 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
668 * DIALOG_PAGESETUP_DlgProc
671 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
680 /* save user input and close dialog */
681 GetDlgItemText(hDlg, 0x141, Globals.szHeader, sizeof(Globals.szHeader));
682 GetDlgItemText(hDlg, 0x143, Globals.szFooter, sizeof(Globals.szFooter));
683 GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, sizeof(Globals.szMarginTop));
684 GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
685 GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, sizeof(Globals.szMarginLeft));
686 GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, sizeof(Globals.szMarginRight));
687 EndDialog(hDlg, IDOK);
691 /* discard user input and close dialog */
692 EndDialog(hDlg, IDCANCEL);
696 /* FIXME: Bring this to work */
697 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
703 /* fetch last user input prior to display dialog */
704 SetDlgItemText(hDlg, 0x141, Globals.szHeader);
705 SetDlgItemText(hDlg, 0x143, Globals.szFooter);
706 SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
707 SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
708 SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
709 SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);