4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
36 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
38 * Given some ids strings, this acts as a language-aware wrapper for
41 CHAR szMessage[MAX_STRING_LEN];
42 CHAR szCaption[MAX_STRING_LEN];
44 LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
45 LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
47 return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
50 void AlertFileNotFound(LPSTR szFileName) {
53 CHAR szMessage[MAX_STRING_LEN];
54 CHAR szRessource[MAX_STRING_LEN];
56 /* Load and format szMessage */
57 LoadString(Globals.hInstance, IDS_NOTFOUND, szRessource, sizeof(szRessource));
58 wsprintf(szMessage, szRessource, szFileName);
61 LoadString(Globals.hInstance, IDS_ERROR, szRessource, sizeof(szRessource));
63 /* Display Modal Dialog */
64 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
68 int AlertFileNotSaved(LPSTR szFileName) {
71 CHAR szMessage[MAX_STRING_LEN];
72 CHAR szRessource[MAX_STRING_LEN];
74 /* Load and format Message */
76 LoadString(Globals.hInstance, IDS_NOTSAVED, szRessource, sizeof(szRessource));
77 wsprintf(szMessage, szRessource, szFileName);
81 LoadString(Globals.hInstance, IDS_ERROR, szRessource, sizeof(szRessource));
84 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
89 VOID AlertOutOfMemory(void) {
92 nResult = AlertIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_ICONEXCLAMATION);
97 BOOL FileExists(LPCSTR szFilename) {
99 * Returns: TRUE - if "szFileName" exists
100 * FALSE - if it does not
102 WIN32_FIND_DATA entry;
105 hFile = FindFirstFile(szFilename, &entry);
107 return (hFile!=INVALID_HANDLE_VALUE);
110 VOID DoSaveFile(VOID) {
112 /* FIXME: Really Save the file */
113 /* ... (Globals.szFileName); */
117 BOOL DoCloseFile(void) {
118 /* Return value: TRUE - User agreed to close (both save/don't save) */
119 /* FALSE - User cancelled close by selecting "Cancel" */
123 if (strlen(Globals.szFileName)>0) {
124 /* prompt user to save changes */
125 nResult = AlertFileNotSaved(Globals.szFileName);
127 case IDYES: DoSaveFile();
132 case IDCANCEL: return(FALSE);
135 default: return(FALSE);
140 /* Forget file name */
141 lstrcpy(Globals.szFileName, "");
142 LANGUAGE_UpdateWindowCaption();
147 void DoOpenFile(LPCSTR szFileName) {
149 /* Close any files and prompt to save changes */
151 GetFileTitle(szFileName, Globals.szFileName, sizeof(Globals.szFileName));
152 LANGUAGE_UpdateWindowCaption();
154 LoadBufferFromFile(szFileName);
159 VOID DIALOG_FileNew(VOID)
161 /* Close any files and promt to save changes */
167 VOID DIALOG_FileOpen(VOID)
169 OPENFILENAME openfilename;
170 CHAR szPath[MAX_PATHNAME_LEN];
171 CHAR szDir[MAX_PATHNAME_LEN];
172 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
173 CHAR szDefaultExt[4];
176 lstrcpy(szDefaultExt, "txt");
178 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
182 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
188 GetCurrentDirectory(sizeof(szDir), szDir);
189 lstrcpy(szPath,"*.txt");
191 openfilename.lStructSize = sizeof(OPENFILENAME);
192 openfilename.hwndOwner = Globals.hMainWnd;
193 openfilename.hInstance = Globals.hInstance;
194 openfilename.lpstrFilter = szzFilter;
195 openfilename.lpstrCustomFilter = 0;
196 openfilename.nMaxCustFilter = 0;
197 openfilename.nFilterIndex = 0;
198 openfilename.lpstrFile = szPath;
199 openfilename.nMaxFile = sizeof(szPath);
200 openfilename.lpstrFileTitle = 0;
201 openfilename.nMaxFileTitle = 0;
202 openfilename.lpstrInitialDir = szDir;
203 openfilename.lpstrTitle = 0;
204 openfilename.Flags = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
205 openfilename.nFileOffset = 0;
206 openfilename.nFileExtension = 0;
207 openfilename.lpstrDefExt = szDefaultExt;
208 openfilename.lCustData = 0;
209 openfilename.lpfnHook = 0;
210 openfilename.lpTemplateName = 0;
212 if (GetOpenFileName(&openfilename)) {
214 if (FileExists(openfilename.lpstrFile))
215 DoOpenFile(openfilename.lpstrFile);
217 AlertFileNotFound(openfilename.lpstrFile);
222 VOID DIALOG_FileSave(VOID)
224 /* FIXME: Save File */
229 VOID DIALOG_FileSaveAs(VOID)
232 CHAR szPath[MAX_PATHNAME_LEN];
233 CHAR szDir[MAX_PATHNAME_LEN];
234 CHAR szDefaultExt[4];
235 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
239 lstrcpy(szDefaultExt, "txt");
241 LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
245 LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
251 lstrcpy(szPath,"*.*");
253 GetCurrentDirectory(sizeof(szDir), szDir);
255 saveas.lStructSize = sizeof(OPENFILENAME);
256 saveas.hwndOwner = Globals.hMainWnd;
257 saveas.hInstance = Globals.hInstance;
258 saveas.lpstrFilter = szzFilter;
259 saveas.lpstrCustomFilter = 0;
260 saveas.nMaxCustFilter = 0;
261 saveas.nFilterIndex = 0;
262 saveas.lpstrFile = szPath;
263 saveas.nMaxFile = sizeof(szPath);
264 saveas.lpstrFileTitle = 0;
265 saveas.nMaxFileTitle = 0;
266 saveas.lpstrInitialDir = szDir;
267 saveas.lpstrTitle = 0;
268 saveas.Flags = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
269 saveas.nFileOffset = 0;
270 saveas.nFileExtension = 0;
271 saveas.lpstrDefExt = szDefaultExt;
272 saveas.lCustData = 0;
274 saveas.lpTemplateName = 0;
276 if (GetSaveFileName(&saveas)) {
277 lstrcpy(Globals.szFileName, saveas.lpstrFile);
278 LANGUAGE_UpdateWindowCaption();
283 VOID DIALOG_FilePrint(VOID)
292 CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
293 CHAR szPrinterName[MAX_STRING_LEN]; /* Name of the printer */
294 CHAR szDeviceName[MAX_STRING_LEN]; /* Name of the printer device */
295 CHAR szOutput[MAX_STRING_LEN]; /* in which file/device to print */
297 /* LPDEVMODE hDevMode; */
298 /* LPDEVNAMES hDevNames; */
300 /* hDevMode = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
301 /* hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
303 /* Get Current Settings */
305 printer.lStructSize = sizeof(PRINTDLG);
306 printer.hwndOwner = Globals.hMainWnd;
307 printer.hInstance = Globals.hInstance;
309 /* Let PrintDlg create a DEVMODE structure */
310 printer.hDevMode = 0;
311 printer.hDevNames = 0;
313 printer.Flags = PD_RETURNDEFAULT;
314 printer.nFromPage = 0;
316 printer.nMinPage = 0;
317 printer.nMaxPage = 0;
319 printer.lCustData = 0;
320 printer.lpfnPrintHook = 0;
321 printer.lpfnSetupHook = 0;
322 printer.lpPrintTemplateName = 0;
323 printer.lpSetupTemplateName = 0;
324 printer.hPrintTemplate = 0;
325 printer.hSetupTemplate = 0;
327 nResult = PrintDlg(&printer);
329 /* hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
331 /* Congratulations to those Microsoft Engineers responsable */
332 /* for the following pointer acrobatics */
334 assert(printer.hDevNames!=0);
336 nBase = (LONG)(printer.hDevNames);
338 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
339 lstrcpy(szPrinterName, (LPCSTR) (nBase + nOffset));
341 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
342 lstrcpy(szDeviceName, (LPCSTR) (nBase + nOffset));
344 nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
345 lstrcpy(szOutput, (LPCSTR) (nBase + nOffset));
347 MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
348 MessageBox(Globals.hMainWnd, szDeviceName, "Device Name", MB_ICONEXCLAMATION);
349 MessageBox(Globals.hMainWnd, szOutput, "Output", MB_ICONEXCLAMATION);
351 /* Set some default flags */
353 bFlags = PD_RETURNDC + PD_SHOWHELP;
356 /* Remove "Print Selection" if there is no selection */
357 bFlags = bFlags + PD_NOSELECTION;
360 printer.Flags = bFlags;
362 printer.nFromPage = 0;
364 printer.nMinPage = 0;
365 printer.nMaxPage = 0;
368 /* Let commdlg manage copy settings */
369 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
371 if (PrintDlg(&printer)) {
373 /* initialize DOCINFO */
374 di.cbSize = sizeof(DOCINFO);
375 lstrcpy((LPSTR)di.lpszDocName, szDocumentName);
376 lstrcpy((LPSTR)di.lpszOutput, szOutput);
378 hContext = printer.hDC;
380 assert( (int) hContext!=PD_RETURNDC);
382 SetMapMode(hContext, MM_LOMETRIC);
383 /* SetViewPortExExt(hContext, 10, 10, 0); */
384 SetBkMode(hContext, OPAQUE);
386 nResult = TextOut(hContext, 0, 0, " ", 1);
387 assert(nResult != 0);
389 nResult = StartDoc(hContext, &di);
390 assert(nResult != SP_ERROR);
392 nResult = StartPage(hContext);
395 /* FIXME: actually print */
397 nResult = EndPage(hContext);
401 MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
404 MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
407 MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
410 MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
416 MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION);
418 nResult = EndDoc(hContext);
420 nResult = DeleteDC(hContext);
424 /* GlobalFree(hDevNames); */
425 /* GlobalFree(hDevMode); */
428 VOID DIALOG_FilePageSetup(VOID)
433 VOID DIALOG_FilePrinterSetup(VOID)
437 printer.lStructSize = sizeof(PRINTDLG);
438 printer.hwndOwner = Globals.hMainWnd;
439 printer.hInstance = Globals.hInstance;
440 printer.hDevMode = 0;
441 printer.hDevNames = 0;
443 printer.Flags = PD_PRINTSETUP;
444 printer.nFromPage = 0;
446 printer.nMinPage = 0;
447 printer.nMaxPage = 0;
449 printer.lCustData = 0;
450 printer.lpfnPrintHook = 0;
451 printer.lpfnSetupHook = 0;
452 printer.lpPrintTemplateName = 0;
453 printer.lpSetupTemplateName = 0;
454 printer.hPrintTemplate = 0;
455 printer.hSetupTemplate = 0;
457 if (PrintDlg(&printer)) {
463 VOID DIALOG_FileExit(VOID)
470 VOID DIALOG_EditUndo(VOID)
472 MessageBox(Globals.hMainWnd, "Undo", "Debug", MB_ICONEXCLAMATION);
476 VOID DIALOG_EditCut(VOID)
480 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
482 OpenClipboard(Globals.hMainWnd);
485 /* FIXME: Get text */
486 lstrcpy((CHAR *)hMem, "Hello World");
488 SetClipboardData(CF_TEXT, hMem);
494 VOID DIALOG_EditCopy(VOID)
498 hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
500 OpenClipboard(Globals.hMainWnd);
503 /* FIXME: Get text */
504 lstrcpy((CHAR *)hMem, "Hello World");
506 SetClipboardData(CF_TEXT, hMem);
512 VOID DIALOG_EditPaste(VOID)
516 if (IsClipboardFormatAvailable(CF_TEXT)) {
517 OpenClipboard(Globals.hMainWnd);
518 hClipText = GetClipboardData(CF_TEXT);
520 MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
524 VOID DIALOG_EditDelete(VOID)
529 VOID DIALOG_EditSelectAll(VOID)
534 VOID DIALOG_EditTimeDate(VOID)
537 LPSYSTEMTIME lpst = &st;
538 CHAR szDate[MAX_STRING_LEN];
542 GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
543 GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
547 VOID DIALOG_EditWrap(VOID)
549 Globals.bWrapLongLines = !Globals.bWrapLongLines;
550 CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND |
551 (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
554 VOID DIALOG_Search(VOID)
556 Globals.find.lStructSize = sizeof(Globals.find);
557 Globals.find.hwndOwner = Globals.hMainWnd;
558 Globals.find.hInstance = Globals.hInstance;
559 Globals.find.lpstrFindWhat = (CHAR *) &Globals.szFindText;
560 Globals.find.wFindWhatLen = sizeof(Globals.szFindText);
561 Globals.find.lpstrReplaceWith = 0;
562 Globals.find.wReplaceWithLen = 0;
563 Globals.find.Flags = FR_DOWN;
564 Globals.find.lCustData = 0;
565 Globals.find.lpfnHook = 0;
566 Globals.find.lpTemplateName = 0;
568 /* We only need to create the modal FindReplace dialog which will */
569 /* notify us of incoming events using hMainWnd Window Messages */
571 Globals.hFindReplaceDlg = FindText(&Globals.find);
572 assert(Globals.hFindReplaceDlg !=0);
575 VOID DIALOG_SearchNext(VOID)
580 VOID DIALOG_HelpContents(VOID)
582 WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
585 VOID DIALOG_HelpSearch(VOID)
590 VOID DIALOG_HelpHelp(VOID)
592 WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
595 VOID DIALOG_HelpLicense(VOID)
597 WineLicense(Globals.hMainWnd);
600 VOID DIALOG_HelpNoWarranty(VOID)
602 WineWarranty(Globals.hMainWnd);
605 VOID DIALOG_HelpAboutWine(VOID)
607 CHAR szNotepad[MAX_STRING_LEN];
609 LoadString(Globals.hInstance, IDS_NOTEPAD, szNotepad, sizeof(szNotepad));
610 ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
613 /***********************************************************************
618 VOID DIALOG_PageSetup(VOID)
622 lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
623 DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, (DLGPROC)lpfnDlg);
624 FreeProcInstance(lpfnDlg);
628 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
630 * DIALOG_PAGESETUP_DlgProc
633 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
642 /* save user input and close dialog */
643 GetDlgItemText(hDlg, NP_PAGESETUP_HEAD, Globals.szHeader, sizeof(Globals.szHeader));
644 GetDlgItemText(hDlg, NP_PAGESETUP_TAIL, Globals.szFooter, sizeof(Globals.szFooter));
645 GetDlgItemText(hDlg, NP_PAGESETUP_TOP, Globals.szMarginTop, sizeof(Globals.szMarginTop));
646 GetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
647 GetDlgItemText(hDlg, NP_PAGESETUP_LEFT, Globals.szMarginLeft, sizeof(Globals.szMarginLeft));
648 GetDlgItemText(hDlg, NP_PAGESETUP_RIGHT, Globals.szMarginRight, sizeof(Globals.szMarginRight));
649 EndDialog(hDlg, IDOK);
653 /* discard user input and close dialog */
654 EndDialog(hDlg, IDCANCEL);
658 /* FIXME: Bring this to work */
659 MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
665 /* fetch last user input prior to display dialog */
666 SetDlgItemText(hDlg, NP_PAGESETUP_HEAD, Globals.szHeader);
667 SetDlgItemText(hDlg, NP_PAGESETUP_TAIL, Globals.szFooter);
668 SetDlgItemText(hDlg, NP_PAGESETUP_TOP, Globals.szMarginTop);
669 SetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom);
670 SetDlgItemText(hDlg, NP_PAGESETUP_LEFT, Globals.szMarginLeft);
671 SetDlgItemText(hDlg, NP_PAGESETUP_RIGHT, Globals.szMarginRight);