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
33 #define SPACES_IN_TAB 8
34 #define PRINT_LEN_MAX 500
36 static const WCHAR helpfileW
[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
38 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
40 VOID
ShowLastError(void)
42 DWORD error
= GetLastError();
43 if (error
!= NO_ERROR
)
46 WCHAR szTitle
[MAX_STRING_LEN
];
48 LoadStringW(Globals
.hInstance
, STRING_ERROR
, szTitle
, ARRAY_SIZE(szTitle
));
50 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
51 NULL
, error
, 0, (LPWSTR
)&lpMsgBuf
, 0, NULL
);
52 MessageBoxW(NULL
, lpMsgBuf
, szTitle
, MB_OK
| MB_ICONERROR
);
58 * Sets the caption of the main window according to Globals.szFileTitle:
59 * Untitled - Notepad if no file is open
60 * filename - Notepad if a file is given
62 static void UpdateWindowCaption(void)
64 WCHAR szCaption
[MAX_STRING_LEN
];
65 WCHAR szNotepad
[MAX_STRING_LEN
];
66 static const WCHAR hyphenW
[] = { ' ','-',' ',0 };
68 if (Globals
.szFileTitle
[0] != '\0')
69 lstrcpyW(szCaption
, Globals
.szFileTitle
);
71 LoadStringW(Globals
.hInstance
, STRING_UNTITLED
, szCaption
, ARRAY_SIZE(szCaption
));
73 LoadStringW(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, ARRAY_SIZE(szNotepad
));
74 lstrcatW(szCaption
, hyphenW
);
75 lstrcatW(szCaption
, szNotepad
);
77 SetWindowTextW(Globals
.hMainWnd
, szCaption
);
80 int DIALOG_StringMsgBox(HWND hParent
, int formatId
, LPCWSTR szString
, DWORD dwFlags
)
82 WCHAR szMessage
[MAX_STRING_LEN
];
83 WCHAR szResource
[MAX_STRING_LEN
];
85 /* Load and format szMessage */
86 LoadStringW(Globals
.hInstance
, formatId
, szResource
, ARRAY_SIZE(szResource
));
87 wnsprintfW(szMessage
, ARRAY_SIZE(szMessage
), szResource
, szString
);
90 if ((dwFlags
& MB_ICONMASK
) == MB_ICONEXCLAMATION
)
91 LoadStringW(Globals
.hInstance
, STRING_ERROR
, szResource
, ARRAY_SIZE(szResource
));
93 LoadStringW(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, ARRAY_SIZE(szResource
));
95 /* Display Modal Dialog */
97 hParent
= Globals
.hMainWnd
;
98 return MessageBoxW(hParent
, szMessage
, szResource
, dwFlags
);
101 static void AlertFileNotFound(LPCWSTR szFileName
)
103 DIALOG_StringMsgBox(NULL
, STRING_NOTFOUND
, szFileName
, MB_ICONEXCLAMATION
|MB_OK
);
106 static int AlertFileNotSaved(LPCWSTR szFileName
)
108 WCHAR szUntitled
[MAX_STRING_LEN
];
110 LoadStringW(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, ARRAY_SIZE(szUntitled
));
111 return DIALOG_StringMsgBox(NULL
, STRING_NOTSAVED
, szFileName
[0] ? szFileName
: szUntitled
,
112 MB_ICONQUESTION
|MB_YESNOCANCEL
);
117 * TRUE - if file exists
118 * FALSE - if file does not exist
120 BOOL
FileExists(LPCWSTR szFilename
)
122 WIN32_FIND_DATAW entry
;
125 hFile
= FindFirstFileW(szFilename
, &entry
);
128 return (hFile
!= INVALID_HANDLE_VALUE
);
132 static VOID
DoSaveFile(VOID
)
139 hFile
= CreateFileW(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
140 NULL
, OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
141 if(hFile
== INVALID_HANDLE_VALUE
)
147 size
= GetWindowTextLengthA(Globals
.hEdit
) + 1;
148 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
);
155 size
= GetWindowTextA(Globals
.hEdit
, pTemp
, size
);
157 if (!WriteFile(hFile
, pTemp
, size
, &dwNumWrite
, NULL
))
160 SendMessageW(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
164 HeapFree(GetProcessHeap(), 0, pTemp
);
169 * TRUE - User agreed to close (both save/don't save)
170 * FALSE - User cancelled close by selecting "Cancel"
172 BOOL
DoCloseFile(void)
175 static const WCHAR empty_strW
[] = { 0 };
177 if (SendMessageW(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
179 /* prompt user to save changes */
180 nResult
= AlertFileNotSaved(Globals
.szFileName
);
182 case IDYES
: return DIALOG_FileSave();
186 case IDCANCEL
: return(FALSE
);
188 default: return(FALSE
);
192 SetFileName(empty_strW
);
194 UpdateWindowCaption();
199 void DoOpenFile(LPCWSTR szFileName
)
201 static const WCHAR dotlog
[] = { '.','L','O','G',0 };
208 /* Close any files and prompt to save changes */
212 hFile
= CreateFileW(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
213 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
214 if(hFile
== INVALID_HANDLE_VALUE
)
216 AlertFileNotFound(szFileName
);
220 size
= GetFileSize(hFile
, NULL
);
221 if (size
== INVALID_FILE_SIZE
)
229 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
);
237 if (!ReadFile(hFile
, pTemp
, size
, &dwNumRead
, NULL
))
240 HeapFree(GetProcessHeap(), 0, pTemp
);
246 pTemp
[dwNumRead
] = 0;
248 if((size
-1) >= 2 && (BYTE
)pTemp
[0] == 0xff && (BYTE
)pTemp
[1] == 0xfe)
249 SetWindowTextW(Globals
.hEdit
, (LPWSTR
)pTemp
+ 1);
251 SetWindowTextA(Globals
.hEdit
, pTemp
);
253 HeapFree(GetProcessHeap(), 0, pTemp
);
255 SendMessageW(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
256 SendMessageW(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
257 SetFocus(Globals
.hEdit
);
259 /* If the file starts with .LOG, add a time/date at the end and set cursor after */
260 if (GetWindowTextW(Globals
.hEdit
, log
, ARRAY_SIZE(log
)) && !lstrcmpW(log
, dotlog
))
262 static const WCHAR lfW
[] = { '\r','\n',0 };
263 SendMessageW(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLengthW(Globals
.hEdit
), -1);
264 SendMessageW(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
265 DIALOG_EditTimeDate();
266 SendMessageW(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
269 SetFileName(szFileName
);
270 UpdateWindowCaption();
273 VOID
DIALOG_FileNew(VOID
)
275 static const WCHAR empty_strW
[] = { 0 };
277 /* Close any files and prompt to save changes */
279 SetWindowTextW(Globals
.hEdit
, empty_strW
);
280 SendMessageW(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
281 SetFocus(Globals
.hEdit
);
285 VOID
DIALOG_FileOpen(VOID
)
287 OPENFILENAMEW openfilename
;
288 WCHAR szPath
[MAX_PATH
];
289 WCHAR szDir
[MAX_PATH
];
290 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
291 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
293 ZeroMemory(&openfilename
, sizeof(openfilename
));
295 GetCurrentDirectoryW(ARRAY_SIZE(szDir
), szDir
);
296 lstrcpyW(szPath
, txt_files
);
298 openfilename
.lStructSize
= sizeof(openfilename
);
299 openfilename
.hwndOwner
= Globals
.hMainWnd
;
300 openfilename
.hInstance
= Globals
.hInstance
;
301 openfilename
.lpstrFilter
= Globals
.szFilter
;
302 openfilename
.lpstrFile
= szPath
;
303 openfilename
.nMaxFile
= ARRAY_SIZE(szPath
);
304 openfilename
.lpstrInitialDir
= szDir
;
305 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
306 OFN_HIDEREADONLY
| OFN_ENABLESIZING
;
307 openfilename
.lpstrDefExt
= szDefaultExt
;
310 if (GetOpenFileNameW(&openfilename
))
311 DoOpenFile(openfilename
.lpstrFile
);
315 BOOL
DIALOG_FileSave(VOID
)
317 if (Globals
.szFileName
[0] == '\0')
318 return DIALOG_FileSaveAs();
324 BOOL
DIALOG_FileSaveAs(VOID
)
326 OPENFILENAMEW saveas
;
327 WCHAR szPath
[MAX_PATH
];
328 WCHAR szDir
[MAX_PATH
];
329 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
330 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
332 ZeroMemory(&saveas
, sizeof(saveas
));
334 GetCurrentDirectoryW(ARRAY_SIZE(szDir
), szDir
);
335 lstrcpyW(szPath
, txt_files
);
337 saveas
.lStructSize
= sizeof(OPENFILENAMEW
);
338 saveas
.hwndOwner
= Globals
.hMainWnd
;
339 saveas
.hInstance
= Globals
.hInstance
;
340 saveas
.lpstrFilter
= Globals
.szFilter
;
341 saveas
.lpstrFile
= szPath
;
342 saveas
.nMaxFile
= ARRAY_SIZE(szPath
);
343 saveas
.lpstrInitialDir
= szDir
;
344 saveas
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
|
345 OFN_HIDEREADONLY
| OFN_ENABLESIZING
;
346 saveas
.lpstrDefExt
= szDefaultExt
;
348 if (GetSaveFileNameW(&saveas
)) {
350 UpdateWindowCaption();
362 } TEXTINFO
, *LPTEXTINFO
;
364 static int notepad_print_header(HDC hdc
, RECT
*rc
, BOOL dopage
, BOOL header
, int page
, LPWSTR text
)
370 /* Write the header or footer */
371 GetTextExtentPoint32W(hdc
, text
, lstrlenW(text
), &szMetric
);
373 ExtTextOutW(hdc
, (rc
->left
+ rc
->right
- szMetric
.cx
) / 2,
374 header
? rc
->top
: rc
->bottom
- szMetric
.cy
,
375 ETO_CLIPPED
, rc
, text
, lstrlenW(text
), NULL
);
381 static BOOL
notepad_print_page(HDC hdc
, RECT
*rc
, BOOL dopage
, int page
, LPTEXTINFO tInfo
)
389 if (StartPage(hdc
) <= 0)
391 static const WCHAR failedW
[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
392 static const WCHAR errorW
[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
393 MessageBoxW(Globals
.hMainWnd
, failedW
, errorW
, MB_ICONEXCLAMATION
);
398 GetTextMetricsW(hdc
, &tm
);
399 y
= rc
->top
+ notepad_print_header(hdc
, rc
, dopage
, TRUE
, page
, Globals
.szFileName
) * tm
.tmHeight
;
400 b
= rc
->bottom
- 2 * notepad_print_header(hdc
, rc
, FALSE
, FALSE
, page
, Globals
.szFooter
) * tm
.tmHeight
;
407 /* find the end of the line */
408 while (tInfo
->mptr
< tInfo
->mend
&& *tInfo
->mptr
!= '\n' && *tInfo
->mptr
!= '\r')
410 if (*tInfo
->mptr
== '\t')
412 /* replace tabs with spaces */
413 for (m
= 0; m
< SPACES_IN_TAB
; m
++)
415 if (tInfo
->len
< PRINT_LEN_MAX
)
416 tInfo
->lptr
[tInfo
->len
++] = ' ';
417 else if (Globals
.bWrapLongLines
)
421 else if (tInfo
->len
< PRINT_LEN_MAX
)
422 tInfo
->lptr
[tInfo
->len
++] = *tInfo
->mptr
;
424 if (tInfo
->len
>= PRINT_LEN_MAX
&& Globals
.bWrapLongLines
)
431 /* Find out how much we should print if line wrapping is enabled */
432 if (Globals
.bWrapLongLines
)
434 GetTextExtentExPointW(hdc
, tInfo
->lptr
, tInfo
->len
, rc
->right
- rc
->left
, &n
, NULL
, &szMetrics
);
435 if (n
< tInfo
->len
&& tInfo
->lptr
[n
] != ' ')
438 /* Don't wrap words unless it's a single word over the entire line */
439 while (m
&& tInfo
->lptr
[m
] != ' ') m
--;
440 if (m
> 0) n
= m
+ 1;
447 ExtTextOutW(hdc
, rc
->left
, y
, ETO_CLIPPED
, rc
, tInfo
->lptr
, n
, NULL
);
453 memcpy(tInfo
->lptr
, tInfo
->lptr
+ n
, tInfo
->len
* sizeof(WCHAR
));
454 y
+= tm
.tmHeight
+ tm
.tmExternalLeading
;
458 /* find the next line */
459 while (tInfo
->mptr
< tInfo
->mend
&& y
< b
&& (*tInfo
->mptr
== '\n' || *tInfo
->mptr
== '\r'))
461 if (*tInfo
->mptr
== '\n')
462 y
+= tm
.tmHeight
+ tm
.tmExternalLeading
;
466 } while (tInfo
->mptr
< tInfo
->mend
&& y
< b
);
468 notepad_print_header(hdc
, rc
, dopage
, FALSE
, page
, Globals
.szFooter
);
476 VOID
DIALOG_FilePrint(VOID
)
480 int page
, dopage
, copy
;
482 HFONT hTextFont
, old_font
= 0;
488 WCHAR cTemp
[PRINT_LEN_MAX
];
490 /* Get Current Settings */
491 ZeroMemory(&printer
, sizeof(printer
));
492 printer
.lStructSize
= sizeof(printer
);
493 printer
.hwndOwner
= Globals
.hMainWnd
;
494 printer
.hDevMode
= Globals
.hDevMode
;
495 printer
.hDevNames
= Globals
.hDevNames
;
496 printer
.hInstance
= Globals
.hInstance
;
498 /* Set some default flags */
499 printer
.Flags
= PD_RETURNDC
| PD_NOSELECTION
;
500 printer
.nFromPage
= 0;
501 printer
.nMinPage
= 1;
502 /* we really need to calculate number of pages to set nMaxPage and nToPage */
504 printer
.nMaxPage
= -1;
505 /* Let commdlg manage copy settings */
506 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
508 if (!PrintDlgW(&printer
)) return;
510 Globals
.hDevMode
= printer
.hDevMode
;
511 Globals
.hDevNames
= printer
.hDevNames
;
513 SetMapMode(printer
.hDC
, MM_TEXT
);
515 /* initialize DOCINFO */
516 di
.cbSize
= sizeof(DOCINFOW
);
517 di
.lpszDocName
= Globals
.szFileTitle
;
518 di
.lpszOutput
= NULL
;
519 di
.lpszDatatype
= NULL
;
522 /* Get the file text */
523 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
524 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
527 DeleteDC(printer
.hDC
);
531 size
= GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
533 if (StartDocW(printer
.hDC
, &di
) > 0)
535 /* Get the page margins in pixels. */
536 rc
.top
= MulDiv(Globals
.iMarginTop
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), 2540) -
537 GetDeviceCaps(printer
.hDC
, PHYSICALOFFSETY
);
538 rc
.bottom
= GetDeviceCaps(printer
.hDC
, PHYSICALHEIGHT
) -
539 MulDiv(Globals
.iMarginBottom
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), 2540);
540 rc
.left
= MulDiv(Globals
.iMarginLeft
, GetDeviceCaps(printer
.hDC
, LOGPIXELSX
), 2540) -
541 GetDeviceCaps(printer
.hDC
, PHYSICALOFFSETX
);
542 rc
.right
= GetDeviceCaps(printer
.hDC
, PHYSICALWIDTH
) -
543 MulDiv(Globals
.iMarginRight
, GetDeviceCaps(printer
.hDC
, LOGPIXELSX
), 2540);
545 /* Create a font for the printer resolution */
546 lfFont
= Globals
.lfFont
;
547 lfFont
.lfHeight
= MulDiv(lfFont
.lfHeight
, GetDeviceCaps(printer
.hDC
, LOGPIXELSY
), get_dpi());
548 /* Make the font a bit lighter */
549 lfFont
.lfWeight
-= 100;
550 hTextFont
= CreateFontIndirectW(&lfFont
);
551 old_font
= SelectObject(printer
.hDC
, hTextFont
);
553 for (copy
= 1; copy
<= printer
.nCopies
; copy
++)
558 tInfo
.mend
= pTemp
+ size
;
563 if (printer
.Flags
& PD_PAGENUMS
)
565 /* a specific range of pages is selected, so
566 * skip pages that are not to be printed
568 if (page
> printer
.nToPage
)
570 else if (page
>= printer
.nFromPage
)
578 ret
= notepad_print_page(printer
.hDC
, &rc
, dopage
, page
, &tInfo
);
580 } while (ret
&& tInfo
.mptr
< tInfo
.mend
);
585 SelectObject(printer
.hDC
, old_font
);
586 DeleteObject(hTextFont
);
588 DeleteDC(printer
.hDC
);
589 HeapFree(GetProcessHeap(), 0, pTemp
);
592 VOID
DIALOG_FilePrinterSetup(VOID
)
596 ZeroMemory(&printer
, sizeof(printer
));
597 printer
.lStructSize
= sizeof(printer
);
598 printer
.hwndOwner
= Globals
.hMainWnd
;
599 printer
.hDevMode
= Globals
.hDevMode
;
600 printer
.hDevNames
= Globals
.hDevNames
;
601 printer
.hInstance
= Globals
.hInstance
;
602 printer
.Flags
= PD_PRINTSETUP
;
607 Globals
.hDevMode
= printer
.hDevMode
;
608 Globals
.hDevNames
= printer
.hDevNames
;
611 VOID
DIALOG_FileExit(VOID
)
613 PostMessageW(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
616 VOID
DIALOG_EditUndo(VOID
)
618 SendMessageW(Globals
.hEdit
, EM_UNDO
, 0, 0);
621 VOID
DIALOG_EditCut(VOID
)
623 SendMessageW(Globals
.hEdit
, WM_CUT
, 0, 0);
626 VOID
DIALOG_EditCopy(VOID
)
628 SendMessageW(Globals
.hEdit
, WM_COPY
, 0, 0);
631 VOID
DIALOG_EditPaste(VOID
)
633 SendMessageW(Globals
.hEdit
, WM_PASTE
, 0, 0);
636 VOID
DIALOG_EditDelete(VOID
)
638 SendMessageW(Globals
.hEdit
, WM_CLEAR
, 0, 0);
641 VOID
DIALOG_EditSelectAll(VOID
)
643 SendMessageW(Globals
.hEdit
, EM_SETSEL
, 0, -1);
646 VOID
DIALOG_EditTimeDate(VOID
)
649 WCHAR szDate
[MAX_STRING_LEN
];
650 static const WCHAR spaceW
[] = { ' ',0 };
654 GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
655 SendMessageW(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
657 SendMessageW(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)spaceW
);
659 GetDateFormatW(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
660 SendMessageW(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
663 VOID
DIALOG_EditWrap(VOID
)
666 static const WCHAR editW
[] = { 'e','d','i','t',0 };
667 DWORD dwStyle
= WS_CHILD
| WS_VISIBLE
| WS_BORDER
| WS_VSCROLL
|
668 ES_AUTOVSCROLL
| ES_MULTILINE
;
673 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
674 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
680 GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
681 modify
= SendMessageW(Globals
.hEdit
, EM_GETMODIFY
, 0, 0);
682 DestroyWindow(Globals
.hEdit
);
683 GetClientRect(Globals
.hMainWnd
, &rc
);
684 if( Globals
.bWrapLongLines
) dwStyle
|= WS_HSCROLL
| ES_AUTOHSCROLL
;
685 Globals
.hEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, editW
, NULL
, dwStyle
,
686 0, 0, rc
.right
, rc
.bottom
, Globals
.hMainWnd
,
687 NULL
, Globals
.hInstance
, NULL
);
688 SendMessageW(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, FALSE
);
689 SetWindowTextW(Globals
.hEdit
, pTemp
);
690 SendMessageW(Globals
.hEdit
, EM_SETMODIFY
, modify
, 0);
691 SetFocus(Globals
.hEdit
);
692 HeapFree(GetProcessHeap(), 0, pTemp
);
694 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
695 CheckMenuItem(GetMenu(Globals
.hMainWnd
), CMD_WRAP
,
696 MF_BYCOMMAND
| (Globals
.bWrapLongLines
? MF_CHECKED
: MF_UNCHECKED
));
699 VOID
DIALOG_SelectFont(VOID
)
702 LOGFONTW lf
=Globals
.lfFont
;
704 ZeroMemory( &cf
, sizeof(cf
) );
705 cf
.lStructSize
=sizeof(cf
);
706 cf
.hwndOwner
=Globals
.hMainWnd
;
708 cf
.Flags
=CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
;
710 if( ChooseFontW(&cf
) )
712 HFONT currfont
=Globals
.hFont
;
714 Globals
.hFont
=CreateFontIndirectW( &lf
);
716 SendMessageW( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, TRUE
);
718 DeleteObject( currfont
);
722 VOID
DIALOG_Search(VOID
)
724 /* Allow only one search/replace dialog to open */
725 if(Globals
.hFindReplaceDlg
!= NULL
)
727 SetActiveWindow(Globals
.hFindReplaceDlg
);
731 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
732 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
733 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
734 Globals
.find
.hInstance
= Globals
.hInstance
;
735 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
736 Globals
.find
.wFindWhatLen
= ARRAY_SIZE(Globals
.szFindText
);
737 Globals
.find
.Flags
= FR_DOWN
|FR_HIDEWHOLEWORD
;
739 /* We only need to create the modal FindReplace dialog which will */
740 /* notify us of incoming events using hMainWnd Window Messages */
742 Globals
.hFindReplaceDlg
= FindTextW(&Globals
.find
);
743 assert(Globals
.hFindReplaceDlg
!=0);
746 VOID
DIALOG_SearchNext(VOID
)
748 if (Globals
.lastFind
.lpstrFindWhat
== NULL
)
750 else /* use the last find data */
751 NOTEPAD_DoFind(&Globals
.lastFind
);
754 VOID
DIALOG_Replace(VOID
)
756 /* Allow only one search/replace dialog to open */
757 if(Globals
.hFindReplaceDlg
!= NULL
)
759 SetActiveWindow(Globals
.hFindReplaceDlg
);
763 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
764 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
765 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
766 Globals
.find
.hInstance
= Globals
.hInstance
;
767 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
768 Globals
.find
.wFindWhatLen
= ARRAY_SIZE(Globals
.szFindText
);
769 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
770 Globals
.find
.wReplaceWithLen
= ARRAY_SIZE(Globals
.szReplaceText
);
771 Globals
.find
.Flags
= FR_DOWN
|FR_HIDEWHOLEWORD
;
773 /* We only need to create the modal FindReplace dialog which will */
774 /* notify us of incoming events using hMainWnd Window Messages */
776 Globals
.hFindReplaceDlg
= ReplaceTextW(&Globals
.find
);
777 assert(Globals
.hFindReplaceDlg
!=0);
780 VOID
DIALOG_HelpContents(VOID
)
782 WinHelpW(Globals
.hMainWnd
, helpfileW
, HELP_INDEX
, 0);
785 VOID
DIALOG_HelpSearch(VOID
)
790 VOID
DIALOG_HelpHelp(VOID
)
792 WinHelpW(Globals
.hMainWnd
, helpfileW
, HELP_HELPONHELP
, 0);
795 VOID
DIALOG_HelpAboutNotepad(VOID
)
797 static const WCHAR notepadW
[] = { 'W','i','n','e',' ','N','o','t','e','p','a','d',0 };
798 WCHAR szNotepad
[MAX_STRING_LEN
];
799 HICON icon
= LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_NOTEPAD
),
800 IMAGE_ICON
, 48, 48, LR_SHARED
);
802 LoadStringW(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, ARRAY_SIZE(szNotepad
));
803 ShellAboutW(Globals
.hMainWnd
, szNotepad
, notepadW
, icon
);
807 /***********************************************************************
809 * DIALOG_FilePageSetup
811 VOID
DIALOG_FilePageSetup(void)
813 DialogBoxW(Globals
.hInstance
, MAKEINTRESOURCEW(DIALOG_PAGESETUP
),
814 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
818 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
820 * DIALOG_PAGESETUP_DlgProc
823 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
832 /* save user input and close dialog */
833 GetDlgItemTextW(hDlg
, IDC_PAGESETUP_HEADERVALUE
, Globals
.szHeader
, ARRAY_SIZE(Globals
.szHeader
));
834 GetDlgItemTextW(hDlg
, IDC_PAGESETUP_FOOTERVALUE
, Globals
.szFooter
, ARRAY_SIZE(Globals
.szFooter
));
836 Globals
.iMarginTop
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_TOPVALUE
, NULL
, FALSE
) * 100;
837 Globals
.iMarginBottom
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_BOTTOMVALUE
, NULL
, FALSE
) * 100;
838 Globals
.iMarginLeft
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_LEFTVALUE
, NULL
, FALSE
) * 100;
839 Globals
.iMarginRight
= GetDlgItemInt(hDlg
, IDC_PAGESETUP_RIGHTVALUE
, NULL
, FALSE
) * 100;
840 EndDialog(hDlg
, IDOK
);
844 /* discard user input and close dialog */
845 EndDialog(hDlg
, IDCANCEL
);
850 /* FIXME: Bring this to work */
851 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 };
852 static const WCHAR helpW
[] = { 'H','e','l','p',0 };
853 MessageBoxW(Globals
.hMainWnd
, sorryW
, helpW
, MB_ICONEXCLAMATION
);
863 /* fetch last user input prior to display dialog */
864 SetDlgItemTextW(hDlg
, IDC_PAGESETUP_HEADERVALUE
, Globals
.szHeader
);
865 SetDlgItemTextW(hDlg
, IDC_PAGESETUP_FOOTERVALUE
, Globals
.szFooter
);
866 SetDlgItemInt(hDlg
, IDC_PAGESETUP_TOPVALUE
, Globals
.iMarginTop
/ 100, FALSE
);
867 SetDlgItemInt(hDlg
, IDC_PAGESETUP_BOTTOMVALUE
, Globals
.iMarginBottom
/ 100, FALSE
);
868 SetDlgItemInt(hDlg
, IDC_PAGESETUP_LEFTVALUE
, Globals
.iMarginLeft
/ 100, FALSE
);
869 SetDlgItemInt(hDlg
, IDC_PAGESETUP_RIGHTVALUE
, Globals
.iMarginRight
/ 100, FALSE
);