4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * Copyright 2002 Andriy Palamarchuk
7 * Copyright 2007 Rolf Kalbermatter
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #define SPACES_IN_TAB 8
36 #define PRINT_LEN_MAX 500
38 static const WCHAR helpfileW
[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
40 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
42 VOID
ShowLastError(void)
44 DWORD error
= GetLastError();
45 if (error
!= NO_ERROR
)
48 WCHAR szTitle
[MAX_STRING_LEN
];
50 LoadString(Globals
.hInstance
, STRING_ERROR
, szTitle
, SIZEOF(szTitle
));
52 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
54 (LPTSTR
) &lpMsgBuf
, 0, NULL
);
55 MessageBox(NULL
, lpMsgBuf
, szTitle
, MB_OK
| MB_ICONERROR
);
61 * Sets the caption of the main window according to Globals.szFileTitle:
62 * Untitled - Notepad if no file is open
63 * filename - Notepad if a file is given
65 static void UpdateWindowCaption(void)
67 WCHAR szCaption
[MAX_STRING_LEN
];
68 WCHAR szNotepad
[MAX_STRING_LEN
];
69 static const WCHAR hyphenW
[] = { ' ','-',' ',0 };
71 if (Globals
.szFileTitle
[0] != '\0')
72 lstrcpy(szCaption
, Globals
.szFileTitle
);
74 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szCaption
, SIZEOF(szCaption
));
76 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
77 lstrcat(szCaption
, hyphenW
);
78 lstrcat(szCaption
, szNotepad
);
80 SetWindowText(Globals
.hMainWnd
, szCaption
);
83 int DIALOG_StringMsgBox(HWND hParent
, int formatId
, LPCWSTR szString
, DWORD dwFlags
)
85 WCHAR szMessage
[MAX_STRING_LEN
];
86 WCHAR szResource
[MAX_STRING_LEN
];
88 /* Load and format szMessage */
89 LoadString(Globals
.hInstance
, formatId
, szResource
, SIZEOF(szResource
));
90 wnsprintf(szMessage
, SIZEOF(szMessage
), szResource
, szString
);
93 if ((dwFlags
& MB_ICONMASK
) == MB_ICONEXCLAMATION
)
94 LoadString(Globals
.hInstance
, STRING_ERROR
, szResource
, SIZEOF(szResource
));
96 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
98 /* Display Modal Dialog */
100 hParent
= Globals
.hMainWnd
;
101 return MessageBox(hParent
, szMessage
, szResource
, dwFlags
);
104 static void AlertFileNotFound(LPCWSTR szFileName
)
106 DIALOG_StringMsgBox(NULL
, STRING_NOTFOUND
, szFileName
, MB_ICONEXCLAMATION
|MB_OK
);
109 static int AlertFileNotSaved(LPCWSTR szFileName
)
111 WCHAR szUntitled
[MAX_STRING_LEN
];
113 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
114 return DIALOG_StringMsgBox(NULL
, STRING_NOTSAVED
, szFileName
[0] ? szFileName
: szUntitled
,
115 MB_ICONQUESTION
|MB_YESNOCANCEL
);
120 * TRUE - if file exists
121 * FALSE - if file does not exist
123 BOOL
FileExists(LPCWSTR szFilename
)
125 WIN32_FIND_DATA entry
;
128 hFile
= FindFirstFile(szFilename
, &entry
);
131 return (hFile
!= INVALID_HANDLE_VALUE
);
135 static VOID
DoSaveFile(VOID
)
142 hFile
= CreateFile(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
143 NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
144 if(hFile
== INVALID_HANDLE_VALUE
)
150 size
= GetWindowTextLengthA(Globals
.hEdit
) + 1;
151 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
);
158 size
= GetWindowTextA(Globals
.hEdit
, pTemp
, size
);
160 if (!WriteFile(hFile
, pTemp
, size
, &dwNumWrite
, NULL
))
163 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
167 HeapFree(GetProcessHeap(), 0, pTemp
);
172 * TRUE - User agreed to close (both save/don't save)
173 * FALSE - User cancelled close by selecting "Cancel"
175 BOOL
DoCloseFile(void)
178 static const WCHAR empty_strW
[] = { 0 };
180 if (SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
182 /* prompt user to save changes */
183 nResult
= AlertFileNotSaved(Globals
.szFileName
);
185 case IDYES
: return DIALOG_FileSave();
189 case IDCANCEL
: return(FALSE
);
191 default: return(FALSE
);
195 SetFileName(empty_strW
);
197 UpdateWindowCaption();
202 void DoOpenFile(LPCWSTR szFileName
)
204 static const WCHAR dotlog
[] = { '.','L','O','G',0 };
211 /* Close any files and prompt to save changes */
215 hFile
= CreateFile(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
216 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
217 if(hFile
== INVALID_HANDLE_VALUE
)
219 AlertFileNotFound(szFileName
);
223 size
= GetFileSize(hFile
, NULL
);
224 if (size
== INVALID_FILE_SIZE
)
232 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
);
240 if (!ReadFile(hFile
, pTemp
, size
, &dwNumRead
, NULL
))
243 HeapFree(GetProcessHeap(), 0, pTemp
);
249 pTemp
[dwNumRead
] = 0;
251 if((size
-1) >= 2 && (BYTE
)pTemp
[0] == 0xff && (BYTE
)pTemp
[1] == 0xfe)
252 SetWindowTextW(Globals
.hEdit
, (LPWSTR
)pTemp
+ 1);
254 SetWindowTextA(Globals
.hEdit
, pTemp
);
256 HeapFree(GetProcessHeap(), 0, pTemp
);
258 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
259 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
260 SetFocus(Globals
.hEdit
);
262 /* If the file starts with .LOG, add a time/date at the end and set cursor after */
263 if (GetWindowTextW(Globals
.hEdit
, log
, sizeof(log
)/sizeof(log
[0])) && !lstrcmp(log
, dotlog
))
265 static const WCHAR lfW
[] = { '\r','\n',0 };
266 SendMessage(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLength(Globals
.hEdit
), -1);
267 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
268 DIALOG_EditTimeDate();
269 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
272 SetFileName(szFileName
);
273 UpdateWindowCaption();
276 VOID
DIALOG_FileNew(VOID
)
278 static const WCHAR empty_strW
[] = { 0 };
280 /* Close any files and prompt to save changes */
282 SetWindowText(Globals
.hEdit
, empty_strW
);
283 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
284 SetFocus(Globals
.hEdit
);
288 VOID
DIALOG_FileOpen(VOID
)
290 OPENFILENAME openfilename
;
291 WCHAR szPath
[MAX_PATH
];
292 WCHAR szDir
[MAX_PATH
];
293 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
294 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
296 ZeroMemory(&openfilename
, sizeof(openfilename
));
298 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
299 lstrcpy(szPath
, txt_files
);
301 openfilename
.lStructSize
= sizeof(openfilename
);
302 openfilename
.hwndOwner
= Globals
.hMainWnd
;
303 openfilename
.hInstance
= Globals
.hInstance
;
304 openfilename
.lpstrFilter
= Globals
.szFilter
;
305 openfilename
.lpstrFile
= szPath
;
306 openfilename
.nMaxFile
= SIZEOF(szPath
);
307 openfilename
.lpstrInitialDir
= szDir
;
308 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
310 openfilename
.lpstrDefExt
= szDefaultExt
;
313 if (GetOpenFileName(&openfilename
))
314 DoOpenFile(openfilename
.lpstrFile
);
318 BOOL
DIALOG_FileSave(VOID
)
320 if (Globals
.szFileName
[0] == '\0')
321 return DIALOG_FileSaveAs();
327 BOOL
DIALOG_FileSaveAs(VOID
)
330 WCHAR szPath
[MAX_PATH
];
331 WCHAR szDir
[MAX_PATH
];
332 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
333 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
335 ZeroMemory(&saveas
, sizeof(saveas
));
337 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
338 lstrcpy(szPath
, txt_files
);
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();
365 } TEXTINFO
, *LPTEXTINFO
;
367 static int notepad_print_header(HDC hdc
, RECT
*rc
, BOOL dopage
, BOOL header
, int page
, LPWSTR text
)
373 /* Write the header or footer */
374 GetTextExtentPoint32(hdc
, text
, lstrlen(text
), &szMetric
);
376 ExtTextOut(hdc
, (rc
->left
+ rc
->right
- szMetric
.cx
) / 2,
377 header
? rc
->top
: rc
->bottom
- szMetric
.cy
,
378 ETO_CLIPPED
, rc
, text
, lstrlen(text
), NULL
);
384 static BOOL
notepad_print_page(HDC hdc
, RECT
*rc
, BOOL dopage
, int page
, LPTEXTINFO tInfo
)
392 if (StartPage(hdc
) <= 0)
394 static const WCHAR failedW
[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
395 static const WCHAR errorW
[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
396 MessageBox(Globals
.hMainWnd
, failedW
, errorW
, MB_ICONEXCLAMATION
);
401 GetTextMetrics(hdc
, &tm
);
402 y
= rc
->top
+ notepad_print_header(hdc
, rc
, dopage
, TRUE
, page
, Globals
.szFileName
) * tm
.tmHeight
;
403 b
= rc
->bottom
- 2 * notepad_print_header(hdc
, rc
, FALSE
, FALSE
, page
, Globals
.szFooter
) * tm
.tmHeight
;
410 /* find the end of the line */
411 while (tInfo
->mptr
< tInfo
->mend
&& *tInfo
->mptr
!= '\n' && *tInfo
->mptr
!= '\r')
413 if (*tInfo
->mptr
== '\t')
415 /* replace tabs with spaces */
416 for (m
= 0; m
< SPACES_IN_TAB
; m
++)
418 if (tInfo
->len
< PRINT_LEN_MAX
)
419 tInfo
->lptr
[tInfo
->len
++] = ' ';
420 else if (Globals
.bWrapLongLines
)
424 else if (tInfo
->len
< PRINT_LEN_MAX
)
425 tInfo
->lptr
[tInfo
->len
++] = *tInfo
->mptr
;
427 if (tInfo
->len
>= PRINT_LEN_MAX
&& Globals
.bWrapLongLines
)
434 /* Find out how much we should print if line wrapping is enabled */
435 if (Globals
.bWrapLongLines
)
437 GetTextExtentExPoint(hdc
, tInfo
->lptr
, tInfo
->len
, rc
->right
- rc
->left
, &n
, NULL
, &szMetrics
);
438 if (n
< tInfo
->len
&& tInfo
->lptr
[n
] != ' ')
441 /* Don't wrap words unless it's a single word over the entire line */
442 while (m
&& tInfo
->lptr
[m
] != ' ') m
--;
443 if (m
> 0) n
= m
+ 1;
450 ExtTextOut(hdc
, rc
->left
, y
, ETO_CLIPPED
, rc
, tInfo
->lptr
, n
, NULL
);
456 memcpy(tInfo
->lptr
, tInfo
->lptr
+ n
, tInfo
->len
* sizeof(WCHAR
));
457 y
+= tm
.tmHeight
+ tm
.tmExternalLeading
;
461 /* find the next line */
462 while (tInfo
->mptr
< tInfo
->mend
&& y
< b
&& (*tInfo
->mptr
== '\n' || *tInfo
->mptr
== '\r'))
464 if (*tInfo
->mptr
== '\n')
465 y
+= tm
.tmHeight
+ tm
.tmExternalLeading
;
469 } while (tInfo
->mptr
< tInfo
->mend
&& y
< b
);
471 notepad_print_header(hdc
, rc
, dopage
, FALSE
, page
, Globals
.szFooter
);
479 VOID
DIALOG_FilePrint(VOID
)
483 int page
, dopage
, copy
;
485 HFONT hTextFont
, old_font
= 0;
491 WCHAR cTemp
[PRINT_LEN_MAX
];
493 /* Get Current Settings */
494 ZeroMemory(&printer
, sizeof(printer
));
495 printer
.lStructSize
= sizeof(printer
);
496 printer
.hwndOwner
= Globals
.hMainWnd
;
497 printer
.hDevMode
= Globals
.hDevMode
;
498 printer
.hDevNames
= Globals
.hDevNames
;
499 printer
.hInstance
= Globals
.hInstance
;
501 /* Set some default flags */
502 printer
.Flags
= PD_RETURNDC
| PD_NOSELECTION
;
503 printer
.nFromPage
= 0;
504 printer
.nMinPage
= 1;
505 /* we really need to calculate number of pages to set nMaxPage and nToPage */
507 printer
.nMaxPage
= -1;
508 /* Let commdlg manage copy settings */
509 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
511 if (!PrintDlg(&printer
)) return;
513 Globals
.hDevMode
= printer
.hDevMode
;
514 Globals
.hDevNames
= printer
.hDevNames
;
516 SetMapMode(printer
.hDC
, MM_TEXT
);
518 /* initialize DOCINFO */
519 di
.cbSize
= sizeof(DOCINFO
);
520 di
.lpszDocName
= Globals
.szFileTitle
;
521 di
.lpszOutput
= NULL
;
522 di
.lpszDatatype
= NULL
;
525 /* Get the file text */
526 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
527 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
530 DeleteDC(printer
.hDC
);
534 size
= GetWindowText(Globals
.hEdit
, pTemp
, size
);
536 if (StartDoc(printer
.hDC
, &di
) > 0)
538 /* Get the page margins in pixels. */
539 rc
.top
= MulDiv(Globals
.iMarginTop
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), 2540) -
540 GetDeviceCaps(printer
.hDC
, PHYSICALOFFSETY
);
541 rc
.bottom
= GetDeviceCaps(printer
.hDC
, PHYSICALHEIGHT
) -
542 MulDiv(Globals
.iMarginBottom
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), 2540);
543 rc
.left
= MulDiv(Globals
.iMarginLeft
, GetDeviceCaps(printer
.hDC
, LOGPIXELSX
), 2540) -
544 GetDeviceCaps(printer
.hDC
, PHYSICALOFFSETX
);
545 rc
.right
= GetDeviceCaps(printer
.hDC
, PHYSICALWIDTH
) -
546 MulDiv(Globals
.iMarginRight
, GetDeviceCaps(printer
.hDC
, LOGPIXELSX
), 2540);
548 /* Create a font for the printer resolution */
549 lfFont
= Globals
.lfFont
;
550 lfFont
.lfHeight
= MulDiv(lfFont
.lfHeight
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), get_dpi());
551 /* Make the font a bit lighter */
552 lfFont
.lfWeight
-= 100;
553 hTextFont
= CreateFontIndirect(&lfFont
);
554 old_font
= SelectObject(printer
.hDC
, hTextFont
);
556 for (copy
= 1; copy
<= printer
.nCopies
; copy
++)
561 tInfo
.mend
= pTemp
+ size
;
566 if (printer
.Flags
& PD_PAGENUMS
)
568 /* a specific range of pages is selected, so
569 * skip pages that are not to be printed
571 if (page
> printer
.nToPage
)
573 else if (page
>= printer
.nFromPage
)
581 ret
= notepad_print_page(printer
.hDC
, &rc
, dopage
, page
, &tInfo
);
583 } while (ret
&& tInfo
.mptr
< tInfo
.mend
);
588 SelectObject(printer
.hDC
, old_font
);
589 DeleteObject(hTextFont
);
591 DeleteDC(printer
.hDC
);
592 HeapFree(GetProcessHeap(), 0, pTemp
);
595 VOID
DIALOG_FilePrinterSetup(VOID
)
599 ZeroMemory(&printer
, sizeof(printer
));
600 printer
.lStructSize
= sizeof(printer
);
601 printer
.hwndOwner
= Globals
.hMainWnd
;
602 printer
.hDevMode
= Globals
.hDevMode
;
603 printer
.hDevNames
= Globals
.hDevNames
;
604 printer
.hInstance
= Globals
.hInstance
;
605 printer
.Flags
= PD_PRINTSETUP
;
610 Globals
.hDevMode
= printer
.hDevMode
;
611 Globals
.hDevNames
= printer
.hDevNames
;
614 VOID
DIALOG_FileExit(VOID
)
616 PostMessage(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
619 VOID
DIALOG_EditUndo(VOID
)
621 SendMessage(Globals
.hEdit
, EM_UNDO
, 0, 0);
624 VOID
DIALOG_EditCut(VOID
)
626 SendMessage(Globals
.hEdit
, WM_CUT
, 0, 0);
629 VOID
DIALOG_EditCopy(VOID
)
631 SendMessage(Globals
.hEdit
, WM_COPY
, 0, 0);
634 VOID
DIALOG_EditPaste(VOID
)
636 SendMessage(Globals
.hEdit
, WM_PASTE
, 0, 0);
639 VOID
DIALOG_EditDelete(VOID
)
641 SendMessage(Globals
.hEdit
, WM_CLEAR
, 0, 0);
644 VOID
DIALOG_EditSelectAll(VOID
)
646 SendMessage(Globals
.hEdit
, EM_SETSEL
, 0, (LPARAM
)-1);
649 VOID
DIALOG_EditTimeDate(VOID
)
652 WCHAR szDate
[MAX_STRING_LEN
];
653 static const WCHAR spaceW
[] = { ' ',0 };
657 GetTimeFormat(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
658 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
660 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)spaceW
);
662 GetDateFormat(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
663 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
666 VOID
DIALOG_EditWrap(VOID
)
669 static const WCHAR editW
[] = { 'e','d','i','t',0 };
670 DWORD dwStyle
= WS_CHILD
| WS_VISIBLE
| WS_BORDER
| WS_VSCROLL
|
671 ES_AUTOVSCROLL
| ES_MULTILINE
;
676 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
677 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
683 GetWindowText(Globals
.hEdit
, pTemp
, size
);
684 modify
= SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0);
685 DestroyWindow(Globals
.hEdit
);
686 GetClientRect(Globals
.hMainWnd
, &rc
);
687 if( Globals
.bWrapLongLines
) dwStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
688 Globals
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, editW
, NULL
, dwStyle
,
689 0, 0, rc
.right
, rc
.bottom
, Globals
.hMainWnd
,
690 NULL
, Globals
.hInstance
, NULL
);
691 SendMessage(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)FALSE
);
692 SetWindowTextW(Globals
.hEdit
, pTemp
);
693 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, (WPARAM
)modify
, 0);
694 SetFocus(Globals
.hEdit
);
695 HeapFree(GetProcessHeap(), 0, pTemp
);
697 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
698 CheckMenuItem(GetMenu(Globals
.hMainWnd
), CMD_WRAP
,
699 MF_BYCOMMAND
| (Globals
.bWrapLongLines
? MF_CHECKED
: MF_UNCHECKED
));
702 VOID
DIALOG_SelectFont(VOID
)
705 LOGFONT lf
=Globals
.lfFont
;
707 ZeroMemory( &cf
, sizeof(cf
) );
708 cf
.lStructSize
=sizeof(cf
);
709 cf
.hwndOwner
=Globals
.hMainWnd
;
711 cf
.Flags
=CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
;
713 if( ChooseFont(&cf
) )
715 HFONT currfont
=Globals
.hFont
;
717 Globals
.hFont
=CreateFontIndirect( &lf
);
719 SendMessage( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)TRUE
);
721 DeleteObject( currfont
);
725 VOID
DIALOG_Search(VOID
)
727 /* Allow only one search/replace dialog to open */
728 if(Globals
.hFindReplaceDlg
!= NULL
)
730 SetActiveWindow(Globals
.hFindReplaceDlg
);
734 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
735 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
736 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
737 Globals
.find
.hInstance
= Globals
.hInstance
;
738 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
739 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
740 Globals
.find
.Flags
= FR_DOWN
|FR_HIDEWHOLEWORD
;
742 /* We only need to create the modal FindReplace dialog which will */
743 /* notify us of incoming events using hMainWnd Window Messages */
745 Globals
.hFindReplaceDlg
= FindText(&Globals
.find
);
746 assert(Globals
.hFindReplaceDlg
!=0);
749 VOID
DIALOG_SearchNext(VOID
)
751 if (Globals
.lastFind
.lpstrFindWhat
== NULL
)
753 else /* use the last find data */
754 NOTEPAD_DoFind(&Globals
.lastFind
);
757 VOID
DIALOG_Replace(VOID
)
759 /* Allow only one search/replace dialog to open */
760 if(Globals
.hFindReplaceDlg
!= NULL
)
762 SetActiveWindow(Globals
.hFindReplaceDlg
);
766 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
767 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
768 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
769 Globals
.find
.hInstance
= Globals
.hInstance
;
770 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
771 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
772 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
773 Globals
.find
.wReplaceWithLen
= SIZEOF(Globals
.szReplaceText
);
774 Globals
.find
.Flags
= FR_DOWN
|FR_HIDEWHOLEWORD
;
776 /* We only need to create the modal FindReplace dialog which will */
777 /* notify us of incoming events using hMainWnd Window Messages */
779 Globals
.hFindReplaceDlg
= ReplaceText(&Globals
.find
);
780 assert(Globals
.hFindReplaceDlg
!=0);
783 VOID
DIALOG_HelpContents(VOID
)
785 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_INDEX
, 0);
788 VOID
DIALOG_HelpSearch(VOID
)
793 VOID
DIALOG_HelpHelp(VOID
)
795 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_HELPONHELP
, 0);
798 VOID
DIALOG_HelpAboutNotepad(VOID
)
800 static const WCHAR notepadW
[] = { 'W','i','n','e',' ','N','o','t','e','p','a','d',0 };
801 WCHAR szNotepad
[MAX_STRING_LEN
];
802 HICON icon
= LoadImageW( Globals
.hInstance
, MAKEINTRESOURCE(IDI_NOTEPAD
),
803 IMAGE_ICON
, 48, 48, LR_SHARED
);
805 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
806 ShellAbout(Globals
.hMainWnd
, szNotepad
, notepadW
, icon
);
810 /***********************************************************************
812 * DIALOG_FilePageSetup
814 VOID
DIALOG_FilePageSetup(void)
816 DialogBox(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_PAGESETUP
),
817 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
821 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
823 * DIALOG_PAGESETUP_DlgProc
826 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
835 /* save user input and close dialog */
836 GetDlgItemText(hDlg
, IDC_PAGESETUP_HEADERVALUE
, Globals
.szHeader
, SIZEOF(Globals
.szHeader
));
837 GetDlgItemText(hDlg
, IDC_PAGESETUP_FOOTERVALUE
, Globals
.szFooter
, SIZEOF(Globals
.szFooter
));
839 Globals
.iMarginTop
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_TOPVALUE
, NULL
, FALSE
) * 100;
840 Globals
.iMarginBottom
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_BOTTOMVALUE
, NULL
, FALSE
) * 100;
841 Globals
.iMarginLeft
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_LEFTVALUE
, NULL
, FALSE
) * 100;
842 Globals
.iMarginRight
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_RIGHTVALUE
, NULL
, FALSE
) * 100;
843 EndDialog(hDlg
, IDOK
);
847 /* discard user input and close dialog */
848 EndDialog(hDlg
, IDCANCEL
);
853 /* FIXME: Bring this to work */
854 static const WCHAR sorryW
[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 };
855 static const WCHAR helpW
[] = { 'H','e','l','p',0 };
856 MessageBox(Globals
.hMainWnd
, sorryW
, helpW
, MB_ICONEXCLAMATION
);
866 /* fetch last user input prior to display dialog */
867 SetDlgItemText(hDlg
, IDC_PAGESETUP_HEADERVALUE
, Globals
.szHeader
);
868 SetDlgItemText(hDlg
, IDC_PAGESETUP_FOOTERVALUE
, Globals
.szFooter
);
869 SetDlgItemInt(hDlg
, IDC_PAGESETUP_TOPVALUE
, Globals
.iMarginTop
/ 100, FALSE
);
870 SetDlgItemInt(hDlg
, IDC_PAGESETUP_BOTTOMVALUE
, Globals
.iMarginBottom
/ 100, FALSE
);
871 SetDlgItemInt(hDlg
, IDC_PAGESETUP_LEFTVALUE
, Globals
.iMarginLeft
/ 100, FALSE
);
872 SetDlgItemInt(hDlg
, IDC_PAGESETUP_RIGHTVALUE
, Globals
.iMarginRight
/ 100, FALSE
);