2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2007-2008 by Alexander N. Sørnes <alex@thehandofagony.com>
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define _WIN32_IE 0x0400
39 #include "wine/unicode.h"
42 #ifdef NONAMELESSUNION
53 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
55 static const WCHAR wszRichEditClass
[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
56 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
58 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
61 static HWND hEditorWnd
;
63 static HMENU hPopupMenu
;
65 static UINT ID_FINDMSGSTRING
;
67 static DWORD wordWrap
[2];
68 static DWORD barState
[2];
69 static WPARAM fileFormat
= SF_RTF
;
71 static WCHAR wszFileName
[MAX_PATH
];
72 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
73 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
74 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
75 static WCHAR units_cmW
[MAX_STRING_LEN
];
77 static char units_cmA
[MAX_STRING_LEN
];
79 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
81 /* Load string resources */
82 static void DoLoadStrings(void)
85 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
86 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
87 static const WCHAR files_all
[] = {'*','.','*','\0'};
89 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
91 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
93 lstrcpyW(p
, files_rtf
);
95 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
97 lstrcpyW(p
, files_txt
);
99 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
100 p
+= lstrlenW(p
) + 1;
101 lstrcpyW(p
, files_txt
);
102 p
+= lstrlenW(p
) + 1;
103 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
104 p
+= lstrlenW(p
) + 1;
105 lstrcpyW(p
, files_all
);
106 p
+= lstrlenW(p
) + 1;
109 p
= wszDefaultFileName
;
110 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
113 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
115 LoadStringA(hInstance
, STRING_UNITS_CM
, units_cmA
, MAX_STRING_LEN
);
116 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
119 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
123 ZeroMemory(&button
, sizeof(button
));
124 button
.iBitmap
= nImage
;
125 button
.idCommand
= nCommand
;
126 button
.fsState
= TBSTATE_ENABLED
;
127 button
.fsStyle
= TBSTYLE_BUTTON
;
130 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
133 static void AddSeparator(HWND hwndToolBar
)
137 ZeroMemory(&button
, sizeof(button
));
139 button
.idCommand
= 0;
141 button
.fsStyle
= TBSTYLE_SEP
;
144 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
147 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
149 HANDLE hFile
= (HANDLE
)cookie
;
152 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
160 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
164 HANDLE hFile
= (HANDLE
)cookie
;
166 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
168 if(!ret
|| (cb
!= written
))
176 LPWSTR
file_basename(LPWSTR path
)
178 LPWSTR pos
= path
+ lstrlenW(path
);
182 if(*pos
== '\\' || *pos
== '/')
192 static void set_caption(LPCWSTR wszNewFileName
)
194 static const WCHAR wszSeparator
[] = {' ','-',' '};
199 wszNewFileName
= wszDefaultFileName
;
201 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
203 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
204 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
209 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
210 length
+= lstrlenW(wszNewFileName
);
211 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
212 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
213 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
215 SetWindowTextW(hMainWnd
, wszCaption
);
217 HeapFree(GetProcessHeap(), 0, wszCaption
);
220 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
227 while(*endptr
== ' ')
231 return *endptr
== '\0';
233 /* FIXME: Allow other units and convert between them */
234 if(!lstrcmpA(endptr
, units_cmA
))
237 return *endptr
== '\0';
240 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
243 char buffer
[MAX_STRING_LEN
];
244 char *endptr
= buffer
;
246 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
249 ret
= strtod(buffer
, &endptr
);
251 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| !validate_endptr(endptr
, units
))
261 static void set_size(float size
)
265 ZeroMemory(&fmt
, sizeof(fmt
));
266 fmt
.cbSize
= sizeof(fmt
);
267 fmt
.dwMask
= CFM_SIZE
;
268 fmt
.yHeight
= (int)(size
* 20.0);
269 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
272 static void on_sizelist_modified(HWND hwndSizeList
, LPWSTR wszNewFontSize
)
274 WCHAR sizeBuffer
[MAX_STRING_LEN
];
277 ZeroMemory(&format
, sizeof(format
));
278 format
.cbSize
= sizeof(format
);
279 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
281 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
282 if(lstrcmpW(sizeBuffer
, wszNewFontSize
))
285 if(number_from_string((LPCWSTR
) wszNewFontSize
, &size
, FALSE
)
291 SetWindowTextW(hwndSizeList
, sizeBuffer
);
292 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
293 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
298 static void add_size(HWND hSizeListWnd
, unsigned size
)
301 COMBOBOXEXITEMW cbItem
;
302 cbItem
.mask
= CBEIF_TEXT
;
305 wsprintfW(buffer
, stringFormat
, size
);
306 cbItem
.pszText
= (LPWSTR
)buffer
;
307 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
310 static void populate_size_list(HWND hSizeListWnd
)
312 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
313 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
314 COMBOBOXEXITEMW cbFontItem
;
316 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
317 HDC hdc
= GetDC(hMainWnd
);
318 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
323 ZeroMemory(&fmt
, sizeof(fmt
));
324 fmt
.cbSize
= sizeof(fmt
);
325 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
327 cbFontItem
.mask
= CBEIF_LPARAM
;
328 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
329 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
331 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
333 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
335 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
337 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
338 GetDeviceCaps(hdc
, LOGPIXELSY
)));
341 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
342 add_size(hSizeListWnd
, choices
[i
]);
345 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
346 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
349 static void update_size_list(void)
351 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
352 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
353 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
354 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
357 ZeroMemory(&fmt
, sizeof(fmt
));
358 fmt
.cbSize
= sizeof(fmt
);
360 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
362 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
363 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
365 if(lstrcmpW(fontSize
, sizeBuffer
))
366 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
369 static void update_font_list(void)
371 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
372 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
373 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
374 WCHAR fontName
[MAX_STRING_LEN
];
377 ZeroMemory(&fmt
, sizeof(fmt
));
378 fmt
.cbSize
= sizeof(fmt
);
380 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
381 if (!SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
)) return;
383 if(lstrcmpW(fontName
, fmt
.szFaceName
))
385 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
386 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
393 static void clear_formatting(void)
397 pf
.cbSize
= sizeof(pf
);
398 pf
.dwMask
= PFM_ALIGNMENT
;
399 pf
.wAlignment
= PFA_LEFT
;
400 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
403 static int fileformat_number(WPARAM format
)
407 if(format
== SF_TEXT
)
410 } else if (format
== (SF_TEXT
| SF_UNICODE
))
417 static WPARAM
fileformat_flags(int format
)
419 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
421 return flags
[format
];
424 static void set_font(LPCWSTR wszFaceName
)
426 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
427 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
428 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
429 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
432 ZeroMemory(&fmt
, sizeof(fmt
));
434 fmt
.cbSize
= sizeof(fmt
);
435 fmt
.dwMask
= CFM_FACE
;
437 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
439 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
441 populate_size_list(hSizeListWnd
);
443 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)wszFaceName
);
446 static void set_default_font(void)
448 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
449 'R','o','m','a','n',0};
450 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
454 ZeroMemory(&fmt
, sizeof(fmt
));
456 fmt
.cbSize
= sizeof(fmt
);
457 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
460 if(fileFormat
& SF_RTF
)
463 font
= plainTextFont
;
465 lstrcpyW(fmt
.szFaceName
, font
);
467 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
470 static void on_fontlist_modified(LPWSTR wszNewFaceName
)
473 ZeroMemory(&format
, sizeof(format
));
474 format
.cbSize
= sizeof(format
);
475 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
477 if(lstrcmpW(format
.szFaceName
, wszNewFaceName
))
478 set_font((LPCWSTR
) wszNewFaceName
);
481 static void add_font(LPCWSTR fontName
, DWORD fontType
, HWND hListWnd
, const NEWTEXTMETRICEXW
*ntmc
)
483 COMBOBOXEXITEMW cbItem
;
484 WCHAR buffer
[MAX_PATH
];
487 cbItem
.mask
= CBEIF_TEXT
;
488 cbItem
.pszText
= buffer
;
489 cbItem
.cchTextMax
= MAX_STRING_LEN
;
492 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
494 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
499 cbItem
.pszText
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName
) + 1)*sizeof(WCHAR
) );
500 lstrcpyW( cbItem
.pszText
, fontName
);
502 cbItem
.mask
|= CBEIF_LPARAM
;
503 if(fontType
& RASTER_FONTTYPE
)
504 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
506 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
507 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
508 HeapFree( GetProcessHeap(), 0, cbItem
.pszText
);
511 static void dialog_choose_font(void)
516 HDC hDC
= GetDC(hMainWnd
);
518 ZeroMemory(&cf
, sizeof(cf
));
519 cf
.lStructSize
= sizeof(cf
);
520 cf
.hwndOwner
= hMainWnd
;
522 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
524 ZeroMemory(&fmt
, sizeof(fmt
));
525 fmt
.cbSize
= sizeof(fmt
);
527 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
528 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
529 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
530 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
531 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
532 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
533 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
534 cf
.rgbColors
= fmt
.crTextColor
;
538 ZeroMemory(&fmt
, sizeof(fmt
));
539 fmt
.cbSize
= sizeof(fmt
);
540 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
541 fmt
.yHeight
= cf
.iPointSize
* 2;
543 if(cf
.nFontType
& BOLD_FONTTYPE
)
544 fmt
.dwEffects
|= CFE_BOLD
;
545 if(cf
.nFontType
& ITALIC_FONTTYPE
)
546 fmt
.dwEffects
|= CFE_ITALIC
;
547 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
548 fmt
.dwEffects
|= CFE_UNDERLINE
;
549 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
550 fmt
.dwEffects
|= CFE_STRIKEOUT
;
552 fmt
.crTextColor
= cf
.rgbColors
;
554 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
555 set_font(cf
.lpLogFont
->lfFaceName
);
560 static int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
561 DWORD FontType
, LPARAM lParam
)
563 HWND hListWnd
= (HWND
) lParam
;
565 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
568 add_font(lpelfe
->lfFaceName
, FontType
, hListWnd
, (const NEWTEXTMETRICEXW
*)lpntme
);
574 static void populate_font_list(HWND hListWnd
)
576 HDC hdc
= GetDC(hMainWnd
);
578 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
581 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
582 *fontinfo
.lfFaceName
= '\0';
583 fontinfo
.lfPitchAndFamily
= 0;
585 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
586 (LPARAM
)hListWnd
, 0);
588 ZeroMemory(&fmt
, sizeof(fmt
));
589 fmt
.cbSize
= sizeof(fmt
);
590 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
591 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
594 static void update_window(void)
598 GetClientRect(hMainWnd
, &rect
);
600 OnSize(hMainWnd
, SIZE_RESTORED
, MAKELPARAM(rect
.right
, rect
.bottom
));
603 static BOOL
is_bar_visible(int bandId
)
605 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
608 static void store_bar_state(int bandId
, BOOL show
)
610 int formatIndex
= reg_formatindex(fileFormat
);
613 barState
[formatIndex
] |= (1 << bandId
);
615 barState
[formatIndex
] &= ~(1 << bandId
);
618 static void set_toolbar_state(int bandId
, BOOL show
)
620 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
622 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
624 if(bandId
== BANDID_TOOLBAR
)
626 REBARBANDINFOW rbbinfo
;
627 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
629 rbbinfo
.cbSize
= sizeof(rbbinfo
);
630 rbbinfo
.fMask
= RBBIM_STYLE
;
632 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
635 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
637 rbbinfo
.fStyle
|= RBBS_BREAK
;
639 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
642 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
|| bandId
== BANDID_RULER
)
643 store_bar_state(bandId
, show
);
646 static void set_statusbar_state(BOOL show
)
648 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
650 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
651 store_bar_state(BANDID_STATUSBAR
, show
);
654 static void set_bar_states(void)
656 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
657 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
658 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
659 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
660 set_toolbar_state(BANDID_RULER
, is_bar_visible(BANDID_RULER
));
661 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
666 static void preview_exit(HWND hMainWnd
)
668 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
669 HMENU hMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_MAINMENU
));
670 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
673 ShowWindow(hEditorWnd
, TRUE
);
675 close_preview(hMainWnd
);
677 SetMenu(hMainWnd
, hMenu
);
678 registry_read_filelist(hMainWnd
);
683 static void set_fileformat(WPARAM format
)
686 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
690 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
692 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
694 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
698 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
701 static void ShowOpenError(DWORD Code
)
707 case ERROR_ACCESS_DENIED
:
708 Message
= MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED
);
712 Message
= MAKEINTRESOURCEW(STRING_OPEN_FAILED
);
714 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
717 static void DoOpenFile(LPCWSTR szOpenFileName
)
723 WPARAM format
= SF_TEXT
;
725 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
726 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
727 if (hFile
== INVALID_HANDLE_VALUE
)
729 ShowOpenError(GetLastError());
733 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
734 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
736 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
738 format
= SF_TEXT
| SF_UNICODE
;
739 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
740 } else if(readOut
>= 5)
742 static const char header
[] = "{\\rtf";
743 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
745 if(!memcmp(header
, fileStart
, 5))
747 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
750 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
), wszAppTitle
,
751 MB_OK
| MB_ICONEXCLAMATION
);
756 es
.dwCookie
= (DWORD_PTR
)hFile
;
757 es
.pfnCallback
= stream_in
;
760 set_fileformat(format
);
761 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
765 SetFocus(hEditorWnd
);
767 set_caption(szOpenFileName
);
769 lstrcpyW(wszFileName
, szOpenFileName
);
770 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
771 registry_set_filelist(szOpenFileName
, hMainWnd
);
775 static void ShowWriteError(DWORD Code
)
781 case ERROR_ACCESS_DENIED
:
782 Message
= MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED
);
786 Message
= MAKEINTRESOURCEW(STRING_WRITE_FAILED
);
788 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
791 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
797 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
798 FILE_ATTRIBUTE_NORMAL
, NULL
);
800 if(hFile
== INVALID_HANDLE_VALUE
)
802 ShowWriteError(GetLastError());
806 if(format
== (SF_TEXT
| SF_UNICODE
))
808 static const BYTE unicode
[] = {0xff,0xfe};
810 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
812 if(writeOut
!= sizeof(unicode
))
816 stream
.dwCookie
= (DWORD_PTR
)hFile
;
817 stream
.pfnCallback
= stream_out
;
819 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
823 SetFocus(hEditorWnd
);
828 gt
.flags
= GTL_DEFAULT
;
831 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
835 lstrcpyW(wszFileName
, wszSaveFileName
);
836 set_caption(wszFileName
);
837 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
838 set_fileformat(format
);
841 static void DialogSaveFile(void)
845 WCHAR wszFile
[MAX_PATH
] = {'\0'};
846 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
848 ZeroMemory(&sfn
, sizeof(sfn
));
850 sfn
.lStructSize
= sizeof(sfn
);
851 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
852 sfn
.hwndOwner
= hMainWnd
;
853 sfn
.lpstrFilter
= wszFilter
;
854 sfn
.lpstrFile
= wszFile
;
855 sfn
.nMaxFile
= MAX_PATH
;
856 sfn
.lpstrDefExt
= wszDefExt
;
857 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
859 while(GetSaveFileNameW(&sfn
))
861 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
863 if(MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
864 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
869 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
874 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
880 static BOOL
prompt_save_changes(void)
885 gt
.flags
= GTL_NUMCHARS
;
887 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
891 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
896 LPWSTR displayFileName
;
901 displayFileName
= wszDefaultFileName
;
903 displayFileName
= file_basename(wszFileName
);
905 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
906 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
911 wsprintfW(text
, wszSaveChanges
, displayFileName
);
913 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
915 HeapFree(GetProcessHeap(), 0, text
);
924 DoSaveFile(wszFileName
, fileFormat
);
935 static void DialogOpenFile(void)
939 WCHAR wszFile
[MAX_PATH
] = {'\0'};
940 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
942 ZeroMemory(&ofn
, sizeof(ofn
));
944 ofn
.lStructSize
= sizeof(ofn
);
945 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
946 ofn
.hwndOwner
= hMainWnd
;
947 ofn
.lpstrFilter
= wszFilter
;
948 ofn
.lpstrFile
= wszFile
;
949 ofn
.nMaxFile
= MAX_PATH
;
950 ofn
.lpstrDefExt
= wszDefExt
;
951 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
953 if(GetOpenFileNameW(&ofn
))
955 if(prompt_save_changes())
956 DoOpenFile(ofn
.lpstrFile
);
960 static void dialog_about(void)
962 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
963 HICON icon
= LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
, 48, 48, LR_SHARED
);
964 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
967 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
973 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
976 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
978 sprintf(id
, "%d\n", (int)ps
->lParam
);
979 SetWindowTextA(hIdWnd
, id
);
980 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
981 wrap
= IDC_PAGEFMT_WW
;
982 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
983 wrap
= IDC_PAGEFMT_WM
;
986 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
,
987 IDC_PAGEFMT_WM
, wrap
);
989 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
990 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
991 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
992 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
993 if(barState
[ps
->lParam
] & (1 << BANDID_RULER
))
994 CheckDlgButton(hWnd
, IDC_PAGEFMT_RU
, TRUE
);
995 if(barState
[ps
->lParam
] & (1 << BANDID_STATUSBAR
))
996 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1001 switch(LOWORD(wParam
))
1003 case IDC_PAGEFMT_WW
:
1004 case IDC_PAGEFMT_WM
:
1005 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
, IDC_PAGEFMT_WM
,
1009 case IDC_PAGEFMT_TB
:
1010 case IDC_PAGEFMT_FB
:
1011 case IDC_PAGEFMT_RU
:
1012 case IDC_PAGEFMT_SB
:
1013 CheckDlgButton(hWnd
, LOWORD(wParam
),
1014 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1020 LPNMHDR header
= (LPNMHDR
)lParam
;
1021 if(header
->code
== PSN_APPLY
)
1023 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1027 GetWindowTextA(hIdWnd
, sid
, 4);
1029 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1030 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1031 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1032 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1034 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1035 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1037 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1039 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1040 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1042 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1044 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_RU
))
1045 barState
[id
] |= (1 << BANDID_RULER
);
1047 barState
[id
] &= ~(1 << BANDID_RULER
);
1049 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1050 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1052 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1060 static void dialog_viewproperties(void)
1062 PROPSHEETPAGEW psp
[2];
1063 PROPSHEETHEADERW psh
;
1065 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1066 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1068 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1069 psp
[0].dwFlags
= PSP_USETITLE
;
1070 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1071 psp
[0].pfnDlgProc
= formatopts_proc
;
1072 psp
[0].hInstance
= hInstance
;
1073 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1074 psp
[0].pfnCallback
= NULL
;
1075 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1076 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1078 psp
[i
].dwSize
= psp
[0].dwSize
;
1079 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1080 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1081 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1082 psp
[i
].hInstance
= psp
[0].hInstance
;
1083 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1084 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1085 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1088 psh
.dwSize
= sizeof(psh
);
1089 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1090 psh
.hwndParent
= hMainWnd
;
1091 psh
.hInstance
= hInstance
;
1092 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1093 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1094 U3(psh
).ppsp
= ppsp
;
1095 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1097 if(fileFormat
& SF_RTF
)
1098 U2(psh
).nStartPage
= 1;
1100 U2(psh
).nStartPage
= 0;
1101 PropertySheetW(&psh
);
1103 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1106 static void HandleCommandLine(LPWSTR cmdline
)
1111 /* skip white space */
1112 while (*cmdline
== ' ') cmdline
++;
1114 /* skip executable name */
1115 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1117 if (*cmdline
== delimiter
) cmdline
++;
1118 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1119 if (*cmdline
== delimiter
) cmdline
++;
1123 while (isspace(*cmdline
)) cmdline
++;
1125 if (*cmdline
== '-' || *cmdline
== '/')
1127 if (!cmdline
[2] || isspace(cmdline
[2]))
1138 /* a filename starting by / */
1145 /* file name is passed on the command line */
1146 if (cmdline
[0] == '"')
1149 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1151 DoOpenFile(cmdline
);
1152 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1156 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED
), wszAppTitle
, MB_OK
);
1159 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1161 if(pFr
->Flags
& FR_DIALOGTERM
)
1164 pFr
->Flags
= FR_FINDNEXT
;
1168 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1170 DWORD flags
= FR_DOWN
;
1172 static CHARRANGE cr
;
1177 HMENU hMenu
= GetMenu(hMainWnd
);
1180 mi
.cbSize
= sizeof(mi
);
1181 mi
.fMask
= MIIM_DATA
;
1183 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1185 gt
.flags
= GTL_NUMCHARS
;
1188 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1190 if(pFr
->lCustData
== -1)
1192 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1193 cr
.cpMin
= startPos
;
1194 pFr
->lCustData
= startPos
;
1196 if(cr
.cpMin
== length
)
1200 startPos
= pFr
->lCustData
;
1203 if(cr
.cpMax
> length
)
1211 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1213 if(pFr
->Flags
& FR_MATCHCASE
)
1214 flags
|= FR_MATCHCASE
;
1215 if(pFr
->Flags
& FR_WHOLEWORD
)
1216 flags
|= FR_WHOLEWORD
;
1218 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1222 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1224 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1225 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1227 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1233 pFr
->lCustData
= -1;
1234 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1235 MB_OK
| MB_ICONASTERISK
);
1238 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1240 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1241 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1243 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1244 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1246 if(pFr
->Flags
& FR_REPLACEALL
)
1247 handle_findmsg(pFr
);
1254 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1256 static WCHAR findBuffer
[MAX_STRING_LEN
];
1258 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1259 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1260 fr
->hwndOwner
= hMainWnd
;
1261 fr
->Flags
= FR_HIDEUPDOWN
;
1262 fr
->lpstrFindWhat
= findBuffer
;
1264 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1267 hFindWnd
= ReplaceTextW(fr
);
1269 hFindWnd
= FindTextW(fr
);
1272 static int current_units_to_twips(float number
)
1274 int twips
= (int)(number
* TWIPS_PER_CM
);
1278 static void append_current_units(LPWSTR buffer
)
1280 static const WCHAR space
[] = {' ', 0};
1281 lstrcatW(buffer
, space
);
1282 lstrcatW(buffer
, units_cmW
);
1285 static void number_with_units(LPWSTR buffer
, int number
)
1287 float converted
= (float)number
/ TWIPS_PER_CM
;
1288 static const WCHAR fmt
[] = {'%','.','2','f',' ','%','s','\0'};
1290 sprintfW(buffer
, fmt
, converted
, units_cmW
);
1293 static BOOL
get_comboexlist_selection(HWND hComboEx
, LPWSTR wszBuffer
, UINT bufferLength
)
1295 COMBOBOXEXITEMW cbItem
;
1296 COMBOBOXINFO cbInfo
;
1300 hCombo
= (HWND
)SendMessage(hComboEx
, CBEM_GETCOMBOCONTROL
, 0, 0);
1303 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
1304 result
= SendMessage(hCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)&cbInfo
);
1307 hList
= cbInfo
.hwndList
;
1308 idx
= SendMessage(hList
, LB_GETCURSEL
, 0, 0);
1312 ZeroMemory(&cbItem
, sizeof(cbItem
));
1313 cbItem
.mask
= CBEIF_TEXT
;
1315 cbItem
.pszText
= wszBuffer
;
1316 cbItem
.cchTextMax
= bufferLength
-1;
1317 result
= SendMessageW(hComboEx
, CBEM_GETITEM
, 0, (LPARAM
)&cbItem
);
1322 static INT_PTR CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1328 WCHAR buffer
[MAX_STRING_LEN
];
1330 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1333 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1335 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1336 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1338 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1339 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1340 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1342 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1347 switch(LOWORD(wParam
))
1352 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1354 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1358 WCHAR buffer
[MAX_STRING_LEN
];
1359 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1360 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1366 EndDialog(hWnd
, wParam
);
1373 static INT_PTR CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1379 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1380 WCHAR buffer
[MAX_STRING_LEN
];
1381 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1383 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1384 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1385 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1386 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1387 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1388 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1390 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1395 switch(LOWORD(wParam
))
1400 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1401 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1404 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1409 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1416 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1418 static const WORD ALIGNMENT_VALUES
[] = {PFA_LEFT
, PFA_RIGHT
, PFA_CENTER
};
1424 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
1426 WCHAR buffer
[MAX_STRING_LEN
];
1427 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1428 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1429 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1430 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1434 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1436 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1437 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1439 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1440 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1442 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1444 pf
.cbSize
= sizeof(pf
);
1445 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1447 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1449 if(pf
.wAlignment
== PFA_RIGHT
)
1451 else if(pf
.wAlignment
== PFA_CENTER
)
1454 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1456 number_with_units(buffer
, pf
.dxStartIndent
+ pf
.dxOffset
);
1457 SetWindowTextW(hLeftWnd
, buffer
);
1458 number_with_units(buffer
, pf
.dxRightIndent
);
1459 SetWindowTextW(hRightWnd
, buffer
);
1460 number_with_units(buffer
, -pf
.dxOffset
);
1461 SetWindowTextW(hFirstWnd
, buffer
);
1466 switch(LOWORD(wParam
))
1470 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1471 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1472 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1473 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1474 WCHAR buffer
[MAX_STRING_LEN
];
1480 index
= SendMessageW(hListWnd
, CB_GETCURSEL
, 0, 0);
1481 pf
.wAlignment
= ALIGNMENT_VALUES
[index
];
1483 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1484 if(number_from_string(buffer
, &num
, TRUE
))
1486 pf
.dxOffset
= current_units_to_twips(num
);
1487 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1488 if(number_from_string(buffer
, &num
, TRUE
))
1490 pf
.dxRightIndent
= current_units_to_twips(num
);
1491 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1492 if(number_from_string(buffer
, &num
, TRUE
))
1494 pf
.dxStartIndent
= current_units_to_twips(num
);
1498 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1499 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1503 if (pf
.dxOffset
+ pf
.dxStartIndent
< 0
1504 && pf
.dxStartIndent
< 0)
1506 /* The first line is before the left edge, so
1507 * make sure it is at the left edge. */
1508 pf
.dxOffset
= -pf
.dxStartIndent
;
1509 } else if (pf
.dxOffset
< 0) {
1510 /* The second and following lines are before
1511 * the left edge, so set it to be at the left
1512 * edge, and adjust the first line since it
1513 * is relative to it. */
1514 pf
.dxStartIndent
= max(pf
.dxStartIndent
+ pf
.dxOffset
, 0);
1517 /* Internally the dxStartIndent is the absolute
1518 * offset for the first line and dxOffset is
1519 * to it value as opposed how it is displayed with
1520 * the first line being the relative value.
1521 * These two lines make the adjustments. */
1522 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1523 pf
.dxOffset
= pf
.dxOffset
- pf
.dxStartIndent
;
1525 pf
.cbSize
= sizeof(pf
);
1526 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1528 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1534 EndDialog(hWnd
, wParam
);
1541 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1547 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1549 WCHAR buffer
[MAX_STRING_LEN
];
1552 pf
.cbSize
= sizeof(pf
);
1553 pf
.dwMask
= PFM_TABSTOPS
;
1554 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1555 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1557 for(i
= 0; i
< pf
.cTabCount
; i
++)
1559 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1560 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1567 switch(LOWORD(wParam
))
1571 HWND hTabWnd
= (HWND
)lParam
;
1572 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1573 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1574 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1576 if(GetWindowTextLengthW(hTabWnd
))
1577 EnableWindow(hAddWnd
, TRUE
);
1579 EnableWindow(hAddWnd
, FALSE
);
1581 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1583 EnableWindow(hEmptyWnd
, TRUE
);
1585 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1586 EnableWindow(hDelWnd
, FALSE
);
1588 EnableWindow(hDelWnd
, TRUE
);
1591 EnableWindow(hEmptyWnd
, FALSE
);
1598 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1599 WCHAR buffer
[MAX_STRING_LEN
];
1601 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1602 append_current_units(buffer
);
1604 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1608 if(!number_from_string(buffer
, &number
, TRUE
))
1610 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1611 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1614 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1615 SetWindowTextW(hTabWnd
, 0);
1624 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1626 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1628 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1634 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1635 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1642 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1644 WCHAR buffer
[MAX_STRING_LEN
];
1648 pf
.cbSize
= sizeof(pf
);
1649 pf
.dwMask
= PFM_TABSTOPS
;
1651 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1652 (LPARAM
)&buffer
) != CB_ERR
&&
1653 i
< MAX_TAB_STOPS
; i
++)
1655 number_from_string(buffer
, &number
, TRUE
);
1656 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
1659 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1663 EndDialog(hWnd
, wParam
);
1670 static int context_menu(LPARAM lParam
)
1672 int x
= (int)(short)LOWORD(lParam
);
1673 int y
= (int)(short)HIWORD(lParam
);
1674 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1678 int from
= 0, to
= 0;
1680 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1681 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
1682 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1687 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1688 x
, y
, 0, hMainWnd
, 0);
1693 static LRESULT
OnCreate( HWND hWnd
)
1695 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
, hRulerWnd
;
1696 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1699 int nStdBitmaps
= 0;
1702 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1703 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1705 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1707 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1708 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1709 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1711 rbi
.cbSize
= sizeof(rbi
);
1714 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1717 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1719 1, hInstance
, IDB_TOOLBAR
,
1721 24, 24, 16, 16, sizeof(TBBUTTON
));
1723 ab
.hInst
= HINST_COMMCTRL
;
1724 ab
.nID
= IDB_STD_SMALL_COLOR
;
1725 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1727 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1728 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1729 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1730 AddSeparator(hToolBarWnd
);
1731 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1732 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1733 AddSeparator(hToolBarWnd
);
1734 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1735 AddSeparator(hToolBarWnd
);
1736 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1737 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1738 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1739 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1740 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1741 AddSeparator(hToolBarWnd
);
1742 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1744 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1746 rbb
.cbSize
= sizeof(rbb
);
1747 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1748 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1750 rbb
.hwndChild
= hToolBarWnd
;
1752 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1753 rbb
.wID
= BANDID_TOOLBAR
;
1755 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1757 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1758 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1759 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1761 rbb
.hwndChild
= hFontListWnd
;
1763 rbb
.wID
= BANDID_FONTLIST
;
1765 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1767 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1768 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1769 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1771 rbb
.hwndChild
= hSizeListWnd
;
1773 rbb
.fStyle
^= RBBS_BREAK
;
1774 rbb
.wID
= BANDID_SIZELIST
;
1776 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1778 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1779 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1780 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1782 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1783 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1784 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1785 AddSeparator(hFormatBarWnd
);
1786 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
1787 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
1788 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
1789 AddSeparator(hFormatBarWnd
);
1790 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
1792 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
1794 rbb
.hwndChild
= hFormatBarWnd
;
1795 rbb
.wID
= BANDID_FORMATBAR
;
1797 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1799 hRulerWnd
= CreateWindowExW(0, WC_STATICW
, NULL
, WS_VISIBLE
| WS_CHILD
,
1800 0, 0, 200, 10, hReBarWnd
, (HMENU
)IDC_RULER
, hInstance
, NULL
);
1803 rbb
.hwndChild
= hRulerWnd
;
1804 rbb
.wID
= BANDID_RULER
;
1805 rbb
.fStyle
|= RBBS_BREAK
;
1807 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1809 hDLL
= LoadLibraryW(wszRichEditDll
);
1812 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
1813 MB_OK
| MB_ICONEXCLAMATION
);
1817 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
1818 WS_CHILD
|WS_VISIBLE
|ES_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
1819 |ES_WANTRETURN
|WS_VSCROLL
|ES_NOHIDESEL
,
1820 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
1824 fprintf(stderr
, "Error code %u\n", GetLastError());
1829 SetFocus(hEditorWnd
);
1830 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
1834 populate_font_list(hFontListWnd
);
1835 populate_size_list(hSizeListWnd
);
1837 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1839 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
1841 registry_read_filelist(hWnd
);
1842 registry_read_formatopts_all(barState
, wordWrap
);
1843 registry_read_options();
1844 DragAcceptFiles(hWnd
, TRUE
);
1849 static LRESULT
OnUser( HWND hWnd
)
1851 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1852 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1853 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
1854 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
1860 ZeroMemory(&fmt
, sizeof(fmt
));
1861 fmt
.cbSize
= sizeof(fmt
);
1863 ZeroMemory(&pf
, sizeof(pf
));
1864 pf
.cbSize
= sizeof(pf
);
1866 gt
.flags
= GTL_NUMCHARS
;
1869 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
1870 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
1872 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
1874 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1875 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
1876 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
1877 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
1878 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
1879 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
1880 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
1882 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
1883 (fmt
.dwEffects
& CFE_BOLD
));
1884 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
1885 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
1886 (fmt
.dwEffects
& CFE_ITALIC
));
1887 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
1888 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
1889 (fmt
.dwEffects
& CFE_UNDERLINE
));
1890 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
1892 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1893 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
1894 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
1895 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
1897 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
1901 static LRESULT
OnNotify( HWND hWnd
, LPARAM lParam
)
1903 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1904 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1905 NMHDR
*pHdr
= (NMHDR
*)lParam
;
1906 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
1907 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
1909 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
1911 if (pHdr
->code
== CBEN_ENDEDITW
)
1913 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
1914 if(pHdr
->hwndFrom
== hwndFontList
)
1916 on_fontlist_modified((LPWSTR
)endEdit
->szText
);
1917 } else if (pHdr
->hwndFrom
== hwndSizeList
)
1919 on_sizelist_modified(hwndFontList
,(LPWSTR
)endEdit
->szText
);
1925 if (pHdr
->hwndFrom
!= hwndEditor
)
1928 if (pHdr
->code
== EN_SELCHANGE
)
1930 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
1935 sprintf( buf
,"selection = %d..%d, line count=%ld",
1936 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
1937 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
1938 SetWindowTextA(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
1939 SendMessage(hWnd
, WM_USER
, 0, 0);
1945 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1947 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1948 static FINDREPLACEW findreplace
;
1950 if ((HWND
)lParam
== hwndEditor
)
1953 switch(LOWORD(wParam
))
1957 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
1962 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1963 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
1966 if(ret
!= ID_NEWFILE_ABORT
)
1968 if(prompt_save_changes())
1973 wszFileName
[0] = '\0';
1977 st
.flags
= ST_DEFAULT
;
1979 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
1981 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1982 set_fileformat(ret
);
1996 DoSaveFile(wszFileName
, fileFormat
);
2001 case ID_FILE_SAVEAS
:
2005 case ID_FILE_RECENT1
:
2006 case ID_FILE_RECENT2
:
2007 case ID_FILE_RECENT3
:
2008 case ID_FILE_RECENT4
:
2010 HMENU hMenu
= GetMenu(hWnd
);
2013 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2014 mi
.fMask
= MIIM_DATA
;
2015 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2016 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2021 dialog_find(&findreplace
, FALSE
);
2025 handle_findmsg(&findreplace
);
2029 dialog_find(&findreplace
, TRUE
);
2032 case ID_FONTSETTINGS
:
2033 dialog_choose_font();
2037 dialog_print(hWnd
, wszFileName
);
2038 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2041 case ID_PRINT_QUICK
:
2042 print_quick(wszFileName
);
2043 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2048 int index
= reg_formatindex(fileFormat
);
2049 DWORD tmp
= barState
[index
];
2050 barState
[index
] = 0;
2052 barState
[index
] = tmp
;
2053 ShowWindow(hEditorWnd
, FALSE
);
2055 init_preview(hWnd
, wszFileName
);
2057 SetMenu(hWnd
, NULL
);
2058 InvalidateRect(0, 0, TRUE
);
2063 dialog_printsetup(hWnd
);
2064 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2067 case ID_FORMAT_BOLD
:
2068 case ID_FORMAT_ITALIC
:
2069 case ID_FORMAT_UNDERLINE
:
2072 int effects
= CFE_BOLD
;
2074 ZeroMemory(&fmt
, sizeof(fmt
));
2075 fmt
.cbSize
= sizeof(fmt
);
2076 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2078 fmt
.dwMask
= CFM_BOLD
;
2080 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2082 effects
= CFE_ITALIC
;
2083 fmt
.dwMask
= CFM_ITALIC
;
2084 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2086 effects
= CFE_UNDERLINE
;
2087 fmt
.dwMask
= CFM_UNDERLINE
;
2090 fmt
.dwEffects
^= effects
;
2092 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2097 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2101 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2105 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2109 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2112 case ID_EDIT_SELECTALL
:
2114 CHARRANGE range
= {0, -1};
2115 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2116 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2120 case ID_EDIT_GETTEXT
:
2122 int nLen
= GetWindowTextLengthW(hwndEditor
);
2123 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2126 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2127 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2129 HeapFree( GetProcessHeap(), 0, data
);
2130 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2132 tr
.chrg
.cpMax
= nLen
;
2133 tr
.lpstrText
= data
;
2134 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2135 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2136 HeapFree( GetProcessHeap(), 0, data
);
2138 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2142 case ID_EDIT_CHARFORMAT
:
2143 case ID_EDIT_DEFCHARFORMAT
:
2147 ZeroMemory(&cf
, sizeof(cf
));
2148 cf
.cbSize
= sizeof(cf
);
2150 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2151 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2155 case ID_EDIT_PARAFORMAT
:
2158 ZeroMemory(&pf
, sizeof(pf
));
2159 pf
.cbSize
= sizeof(pf
);
2160 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2164 case ID_EDIT_SELECTIONINFO
:
2166 CHARRANGE range
= {0, -1};
2170 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2171 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2172 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2173 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2174 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2175 MessageBoxW(hWnd
, data
, wszAppTitle
, MB_OK
);
2176 HeapFree( GetProcessHeap(), 0, data
);
2177 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2181 case ID_EDIT_READONLY
:
2183 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2184 if (nStyle
& ES_READONLY
)
2185 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2187 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2191 case ID_EDIT_MODIFIED
:
2192 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2193 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2195 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2199 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2203 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2210 pf
.cbSize
= sizeof(pf
);
2211 pf
.dwMask
= PFM_NUMBERING
;
2212 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2214 pf
.dwMask
|= PFM_OFFSET
;
2216 if(pf
.wNumbering
== PFN_BULLET
)
2222 pf
.wNumbering
= PFN_BULLET
;
2226 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2231 case ID_ALIGN_CENTER
:
2232 case ID_ALIGN_RIGHT
:
2236 pf
.cbSize
= sizeof(pf
);
2237 pf
.dwMask
= PFM_ALIGNMENT
;
2238 switch(LOWORD(wParam
)) {
2239 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2240 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2241 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2243 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2248 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2252 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2255 case ID_TOGGLE_TOOLBAR
:
2256 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2260 case ID_TOGGLE_FORMATBAR
:
2261 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2262 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2263 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2267 case ID_TOGGLE_STATUSBAR
:
2268 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2272 case ID_TOGGLE_RULER
:
2273 set_toolbar_state(BANDID_RULER
, !is_bar_visible(BANDID_RULER
));
2279 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2280 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, datetime_proc
);
2286 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2287 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
2294 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2295 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2303 case ID_VIEWPROPERTIES
:
2304 dialog_viewproperties();
2308 if (HIWORD(wParam
) == CBN_SELENDOK
)
2310 WCHAR buffer
[LF_FACESIZE
];
2311 HWND hwndFontList
= (HWND
)lParam
;
2312 get_comboexlist_selection(hwndFontList
, buffer
, LF_FACESIZE
);
2313 on_fontlist_modified(buffer
);
2318 if (HIWORD(wParam
) == CBN_SELENDOK
)
2320 WCHAR buffer
[MAX_STRING_LEN
+1];
2321 HWND hwndSizeList
= (HWND
)lParam
;
2322 get_comboexlist_selection(hwndSizeList
, buffer
, MAX_STRING_LEN
+1);
2323 on_sizelist_modified(hwndSizeList
, buffer
);
2328 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2334 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
)
2336 HMENU hMenu
= (HMENU
)wParam
;
2337 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2338 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2340 int nAlignment
= -1;
2346 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2347 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2348 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2350 pf
.cbSize
= sizeof(PARAFORMAT
);
2351 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2352 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2353 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2354 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2355 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2356 if (pf
.dwMask
& PFM_ALIGNMENT
)
2357 nAlignment
= pf
.wAlignment
;
2358 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2359 MF_CHECKED
: MF_UNCHECKED
);
2360 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2361 MF_CHECKED
: MF_UNCHECKED
);
2362 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2363 MF_CHECKED
: MF_UNCHECKED
);
2364 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2365 MF_CHECKED
: MF_UNCHECKED
));
2366 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2367 MF_ENABLED
: MF_GRAYED
);
2368 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2369 MF_ENABLED
: MF_GRAYED
);
2371 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2372 MF_CHECKED
: MF_UNCHECKED
);
2374 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2375 MF_CHECKED
: MF_UNCHECKED
);
2377 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2378 MF_CHECKED
: MF_UNCHECKED
);
2380 CheckMenuItem(hMenu
, ID_TOGGLE_RULER
, MF_BYCOMMAND
|(is_bar_visible(BANDID_RULER
)) ? MF_CHECKED
: MF_UNCHECKED
);
2382 gt
.flags
= GTL_NUMCHARS
;
2384 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2385 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2387 mi
.cbSize
= sizeof(mi
);
2388 mi
.fMask
= MIIM_DATA
;
2390 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2392 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2393 MF_ENABLED
: MF_GRAYED
));
2395 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2400 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2402 int nStatusSize
= 0;
2404 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2405 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2406 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2407 HWND hRulerWnd
= GetDlgItem(hWnd
, IDC_RULER
);
2408 int rebarHeight
= 0;
2412 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2413 if (IsWindowVisible(hwndStatusBar
))
2415 GetClientRect(hwndStatusBar
, &rc
);
2416 nStatusSize
= rc
.bottom
- rc
.top
;
2424 rebarHeight
= SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
2426 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2430 GetClientRect(hWnd
, &rc
);
2431 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2434 redraw_ruler(hRulerWnd
);
2436 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2439 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2441 if(msg
== ID_FINDMSGSTRING
)
2442 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2447 return OnCreate( hWnd
);
2450 return OnUser( hWnd
);
2453 return OnNotify( hWnd
, lParam
);
2456 if(preview_isactive())
2458 return preview_command( hWnd
, wParam
);
2461 return OnCommand( hWnd
, wParam
, lParam
);
2468 if(preview_isactive())
2471 } else if(prompt_save_changes())
2473 registry_set_options(hMainWnd
);
2474 registry_set_formatopts_all(barState
);
2481 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2484 case WM_INITMENUPOPUP
:
2485 return OnInitPopupMenu( hWnd
, wParam
);
2488 return OnSize( hWnd
, wParam
, lParam
);
2490 case WM_CONTEXTMENU
:
2491 if((HWND
)wParam
== hEditorWnd
)
2492 return context_menu(lParam
);
2494 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2498 WCHAR file
[MAX_PATH
];
2499 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2500 DragFinish((HDROP
)wParam
);
2502 if(prompt_save_changes())
2507 if(preview_isactive())
2508 return print_preview(hWnd
);
2510 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2513 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2519 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int nCmdShow
)
2521 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2526 UINT_PTR hPrevRulerProc
;
2530 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2531 'T','A','B','L','E','\0'};
2533 InitCommonControlsEx(&classes
);
2535 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2537 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2538 wc
.lpfnWndProc
= WndProc
;
2541 wc
.hInstance
= hInstance
;
2542 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2543 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2544 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2545 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2546 wc
.lpszClassName
= wszMainWndClass
;
2547 RegisterClassW(&wc
);
2549 registry_read_winrect(&rc
);
2550 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2551 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2552 registry_read_maximized(&bMaximized
);
2553 if ((nCmdShow
== SW_SHOWNORMAL
|| nCmdShow
== SW_SHOWDEFAULT
)
2555 nCmdShow
= SW_SHOWMAXIMIZED
;
2556 ShowWindow(hMainWnd
, nCmdShow
);
2560 set_fileformat(SF_RTF
);
2561 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2562 get_default_printer_opts();
2563 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2565 hRulerWnd
= GetDlgItem(GetDlgItem(hMainWnd
, IDC_REBAR
), IDC_RULER
);
2566 SendMessageW(GetDlgItem(hMainWnd
, IDC_EDITOR
), EM_POSFROMCHAR
, (WPARAM
)&EditPoint
, 0);
2567 hPrevRulerProc
= SetWindowLongPtrW(hRulerWnd
, GWLP_WNDPROC
, (UINT_PTR
)ruler_proc
);
2568 SendMessageW(hRulerWnd
, WM_USER
, (WPARAM
)&EditPoint
, hPrevRulerProc
);
2570 HandleCommandLine(GetCommandLineW());
2572 while(GetMessageW(&msg
,0,0,0))
2574 if (IsDialogMessage(hFindWnd
, &msg
))
2577 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2579 TranslateMessage(&msg
);
2580 DispatchMessageW(&msg
);
2581 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2582 SendMessageW(hMainWnd
, WM_USER
, 0, 0);