4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * 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);
37 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
39 * Given some ids strings, this acts as a language-aware wrapper for
42 CHAR szMessage[MAX_STRING_LEN];
43 CHAR szCaption[MAX_STRING_LEN];
45 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
46 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
48 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
51 void AlertFileNotFound(LPSTR szFileName) {
54 CHAR szMessage[MAX_STRING_LEN];
55 CHAR szRessource[MAX_STRING_LEN];
57 /* Load and format szMessage */
58 LoadString(Globals.hInstance, STRING_NOTFOUND, szRessource, sizeof(szRessource));
59 wsprintf(szMessage, szRessource, szFileName);
62 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
64 /* Display Modal Dialog */
65 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
69 int AlertFileNotSaved(LPSTR szFileName) {
72 CHAR szMessage[MAX_STRING_LEN];
73 CHAR szRessource[MAX_STRING_LEN];
75 /* Load and format Message */
77 LoadString(Globals.hInstance, STRING_NOTSAVED, szRessource, sizeof(szRessource));
78 wsprintf(szMessage, szRessource, szFileName);
82 LoadString(Globals.hInstance, STRING_ERROR, szRessource, sizeof(szRessource));
85 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
90 VOID AlertOutOfMemory(void) {
93 nResult = AlertIDS(STRING_OUT_OF_MEMORY, STRING_ERROR, MB_ICONEXCLAMATION);
98 BOOL FileExists(LPCSTR szFilename) {
100 * Returns: TRUE - if "szFileName" exists
101 * FALSE - if it does not
103 WIN32_FIND_DATA entry;
106 hFile = FindFirstFile(szFilename, &entry);
108 return (hFile!=INVALID_HANDLE_VALUE);
111 VOID DoSaveFile(VOID) {
113 /* FIXME: Really Save the file */
114 /* ... (Globals.szFileName); */
118 BOOL DoCloseFile(void) {
119 /* Return value: TRUE - User agreed to close (both save/don't save) */
120 /* FALSE - User cancelled close by selecting "Cancel" */
124 if (strlen(Globals.szFileName)>0) {
125 /* prompt user to save changes */
126 nResult = AlertFileNotSaved(Globals.szFileName);
128 case IDYES: DoSaveFile();
133 case IDCANCEL: return(FALSE);
136 default: return(FALSE);
141 /* Forget file name */
142 lstrcpy(Globals.szFileName, "");
143 LANGUAGE_UpdateWindowCaption();
148 void DoOpenFile(LPCSTR szFileName) {
150 /* Close any files and prompt to save changes */
152 GetFileTitle(szFileName, Globals.szFileName, sizeof(Globals.szFileName));
153 LANGUAGE_UpdateWindowCaption();
155 LoadBufferFromFile(szFileName);
160 VOID DIALOG_FileNew(VOID)
162 /* Close any files and promt to save changes */
168 VOID DIALOG_FileOpen(VOID)
170 OPENFILENAME openfilename;
171 CHAR szPath[MAX_PATHNAME_LEN];
172 CHAR szDir[MAX_PATHNAME_LEN];
173 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
174 CHAR szDefaultExt[4];
177 lstrcpy(szDefaultExt, "txt");
179 LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
183 LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
189 GetCurrentDirectory(sizeof(szDir), szDir);
190 lstrcpy(szPath,"*.txt");
192 openfilename.lStructSize = sizeof(OPENFILENAME);
193 openfilename.hwndOwner = Globals.hMainWnd;
194 openfilename.hInstance = Globals.hInstance;
195 openfilename.lpstrFilter = szzFilter;
196 openfilename.lpstrCustomFilter = 0;
197 openfilename.nMaxCustFilter = 0;
198 openfilename.nFilterIndex = 0;
199 openfilename.lpstrFile = szPath;
200 openfilename.nMaxFile = sizeof(szPath);
201 openfilename.lpstrFileTitle = 0;
202 openfilename.nMaxFileTitle = 0;
203 openfilename.lpstrInitialDir = szDir;
204 openfilename.lpstrTitle = 0;
205 openfilename.Flags = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
206 openfilename.nFileOffset = 0;
207 openfilename.nFileExtension = 0;
208 openfilename.lpstrDefExt = szDefaultExt;
209 openfilename.lCustData = 0;
210 openfilename.lpfnHook = 0;
211 openfilename.lpTemplateName = 0;
213 if (GetOpenFileName(&openfilename)) {
215 if (FileExists(openfilename.lpstrFile))
216 DoOpenFile(openfilename.lpstrFile);
218 AlertFileNotFound(openfilename.lpstrFile);
223 VOID DIALOG_FileSave(VOID)
225 /* FIXME: Save File */
230 VOID DIALOG_FileSaveAs(VOID)
233 CHAR szPath[MAX_PATHNAME_LEN];
234 CHAR szDir[MAX_PATHNAME_LEN];
235 CHAR szDefaultExt[4];
236 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
240 lstrcpy(szDefaultExt, "txt");
242 LoadString(Globals.hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
246 LoadString(Globals.hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
252 lstrcpy(szPath,"*.*");
254 GetCurrentDirectory(sizeof(szDir), szDir);
256 saveas.lStructSize = sizeof(OPENFILENAME);
257 saveas.hwndOwner = Globals.hMainWnd;
258 saveas.hInstance = Globals.hInstance;
259 saveas.lpstrFilter = szzFilter;
260 saveas.lpstrCustomFilter = 0;
261 saveas.nMaxCustFilter = 0;
262 saveas.nFilterIndex = 0;
263 saveas.lpstrFile = szPath;
264 saveas.nMaxFile = sizeof(szPath);
265 saveas.lpstrFileTitle = 0;
266 saveas.nMaxFileTitle = 0;
267 saveas.lpstrInitialDir = szDir;
268 saveas.lpstrTitle = 0;
269 saveas.Flags = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
270 saveas.nFileOffset = 0;
271 saveas.nFileExtension = 0;
272 saveas.lpstrDefExt = szDefaultExt;
273 saveas.lCustData = 0;
275 saveas.lpTemplateName = 0;
277 if (GetSaveFileName(&saveas)) {
278 lstrcpy(Globals.szFileName, saveas.lpstrFile);
279 LANGUAGE_UpdateWindowCaption();
284 VOID DIALOG_FilePrint(VOID)
293 CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
294 CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */
295 CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */
296 CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */
298 /* LPDEVMODE hDevMode; */
299 /* LPDEVNAMES hDevNames; */
301 /* hDevMode = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
302 /* hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
304 /* Get Current Settings */
306 printer.lStructSize = sizeof(PRINTDLG);
307 printer.hwndOwner = Globals.hMainWnd;
308 printer.hInstance = Globals.hInstance;
310 /* Let PrintDlg create a DEVMODE structure */
311 printer.hDevMode = 0;
312 printer.hDevNames = 0;
314 printer.Flags = PD_RETURNDEFAULT;
315 printer.nFromPage = 0;
317 printer.nMinPage = 0;
318 printer.nMaxPage = 0;
320 printer.lCustData = 0;
321 printer.lpfnPrintHook = 0;
322 printer.lpfnSetupHook = 0;
323 printer.lpPrintTemplateName = 0;
324 printer.lpSetupTemplateName = 0;
325 printer.hPrintTemplate = 0;
326 printer.hSetupTemplate = 0;
328 nResult = PrintDlg(&printer);
330 /* hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
332 /* Congratulations to those Microsoft Engineers responsable */
333 /* for the following pointer acrobatics */
335 assert(printer.hDevNames!=0);
337 nBase = (LONG)(printer.hDevNames);
339 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
340 lstrcpy(szPrinterName, (LPCSTR) (nBase + nOffset));
342 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
343 lstrcpy(szDeviceName, (LPCSTR) (nBase + nOffset));
345 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
346 lstrcpy(szOutput, (LPCSTR) (nBase + nOffset));
348 MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
349 MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION);
350 MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION);
352 /* Set some default flags */
354 bFlags = PD_RETURNDC + PD_SHOWHELP;
357 /* Remove "Print Selection" if there is no selection */
358 bFlags = bFlags + PD_NOSELECTION;
361 printer.Flags = bFlags;
363 printer.nFromPage = 0;
365 printer.nMinPage = 0;
366 printer.nMaxPage = 0;
369 /* Let commdlg manage copy settings */
370 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
372 if (PrintDlg(&printer)) {
374 /* initialize DOCINFO */
375 di.cbSize = sizeof(DOCINFO);
376 lstrcpy((LPSTR)di.lpszDocName, szDocumentName);
377 lstrcpy((LPSTR)di.lpszOutput, szOutput);
379 hContext = printer.hDC;
381 assert( (int) hContext!=PD_RETURNDC);
383 SetMapMode(hContext, MM_LOMETRIC);
384 /* SetViewPortExExt(hContext, 10, 10, 0); */
385 SetBkMode(hContext, OPAQUE);
387 nResult = TextOut(hContext, 0, 0, " ", 1);
388 assert(nResult != 0);
390 nResult = StartDoc(hContext, &di);
391 assert(nResult != SP_ERROR);
393 nResult = StartPage(hContext);
396 /* FIXME: actually print */
398 nResult = EndPage(hContext);
402 MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
405 MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
408 MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
411 MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
417 MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION);
419 nResult = EndDoc(hContext);
421 nResult = DeleteDC(hContext);
425 /* GlobalFree(hDevNames); */
426 /* GlobalFree(hDevMode); */
429 VOID DIALOG_FilePageSetup(VOID)
434 VOID DIALOG_FilePrinterSetup(VOID)
438 printer.lStructSize = sizeof(PRINTDLG);
439 printer.hwndOwner = Globals.hMainWnd;
440 printer.hInstance = Globals.hInstance;
441 printer.hDevMode = 0;
442 printer.hDevNames = 0;
444 printer.Flags = PD_PRINTSETUP;
445 printer.nFromPage = 0;
447 printer.nMinPage = 0;
448 printer.nMaxPage = 0;
450 printer.lCustData = 0;
451 printer.lpfnPrintHook = 0;
452 printer.lpfnSetupHook = 0;
453 printer.lpPrintTemplateName = 0;
454 printer.lpSetupTemplateName = 0;
455 printer.hPrintTemplate = 0;
456 printer.hSetupTemplate = 0;
458 if (PrintDlg(&printer)) {
464 VOID DIALOG_FileExit(VOID)
471 VOID DIALOG_EditUndo(VOID)
473 MessageBox(Globals.hMainWnd, "Undo", "Debug", MB_ICONEXCLAMATION);
477 VOID DIALOG_EditCut(VOID)
481 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
483 OpenClipboard(Globals.hMainWnd);
486 /* FIXME: Get text */
487 lstrcpy((CHAR *)hMem, "Hello World");
489 SetClipboardData(CF_TEXT, hMem);
495 VOID DIALOG_EditCopy(VOID)
499 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
501 OpenClipboard(Globals.hMainWnd);
504 /* FIXME: Get text */
505 lstrcpy((CHAR *)hMem, "Hello World");
507 SetClipboardData(CF_TEXT, hMem);
513 VOID DIALOG_EditPaste(VOID)
517 if (IsClipboardFormatAvailable(CF_TEXT)) {
518 OpenClipboard(Globals.hMainWnd);
519 hClipText = GetClipboardData(CF_TEXT);
521 MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
525 VOID DIALOG_EditDelete(VOID)
530 VOID DIALOG_EditSelectAll(VOID)
535 VOID DIALOG_EditTimeDate(VOID)
538 LPSYSTEMTIME lpst = &st;
539 CHAR szDate[MAX_STRING_LEN];
543 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
544 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
548 VOID DIALOG_EditWrap(VOID)
550 Globals.bWrapLongLines = !Globals.bWrapLongLines;
551 CheckMenuItem(Globals.hEditMenu, 0x119, MF_BYCOMMAND |
552 (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
555 VOID DIALOG_Search(VOID)
557 Globals.find.lStructSize = sizeof(Globals.find);
558 Globals.find.hwndOwner = Globals.hMainWnd;
559 Globals.find.hInstance = Globals.hInstance;
560 Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText;
561 Globals.find.wFindWhatLen = sizeof(Globals.szFindText);
562 Globals.find.lpstrReplaceWith = 0;
563 Globals.find.wReplaceWithLen = 0;
564 Globals.find.Flags = FR_DOWN;
565 Globals.find.lCustData = 0;
566 Globals.find.lpfnHook = 0;
567 Globals.find.lpTemplateName = 0;
569 /* We only need to create the modal FindReplace dialog which will */
570 /* notify us of incoming events using hMainWnd Window Messages */
572 Globals.hFindReplaceDlg = FindText(&Globals.find);
573 assert(Globals.hFindReplaceDlg !=0);
576 VOID DIALOG_SearchNext(VOID)
581 VOID DIALOG_HelpContents(VOID)
583 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
586 VOID DIALOG_HelpSearch(VOID)
591 VOID DIALOG_HelpHelp(VOID)
593 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
596 VOID DIALOG_HelpLicense(VOID)
598 WineLicense(Globals.hMainWnd);
601 VOID DIALOG_HelpNoWarranty(VOID)
603 WineWarranty(Globals.hMainWnd);
606 VOID DIALOG_HelpAboutWine(VOID)
608 CHAR szNotepad[MAX_STRING_LEN];
610 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, sizeof(szNotepad));
611 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
614 /***********************************************************************
619 VOID DIALOG_PageSetup(VOID)
623 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
624 DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, (DLGPROC)lpfnDlg);
625 FreeProcInstance(lpfnDlg);
629 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
631 * DIALOG_PAGESETUP_DlgProc
634 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
643 /* save user input and close dialog */
644 GetDlgItemText(hDlg, 0x141, Globals.szHeader, sizeof(Globals.szHeader));
645 GetDlgItemText(hDlg, 0x143, Globals.szFooter, sizeof(Globals.szFooter));
646 GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, sizeof(Globals.szMarginTop));
647 GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
648 GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, sizeof(Globals.szMarginLeft));
649 GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, sizeof(Globals.szMarginRight));
650 EndDialog(hDlg, IDOK);
654 /* discard user input and close dialog */
655 EndDialog(hDlg, IDCANCEL);
659 /* FIXME: Bring this to work */
660 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
666 /* fetch last user input prior to display dialog */
667 SetDlgItemText(hDlg, 0x141, Globals.szHeader);
668 SetDlgItemText(hDlg, 0x143, Globals.szFooter);
669 SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
670 SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
671 SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
672 SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);