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 wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
57 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
59 const WCHAR wszPreviewWndClass
[] = {'P','r','t','P','r','e','v','i','e','w',0};
60 LRESULT CALLBACK
preview_proc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
63 static HWND hEditorWnd
;
65 static HMENU hPopupMenu
;
66 static HMENU hColorPopupMenu
;
68 static UINT ID_FINDMSGSTRING
;
70 static DWORD wordWrap
[2];
71 static DWORD barState
[2];
72 static WPARAM fileFormat
= SF_RTF
;
74 static WCHAR wszFileName
[MAX_PATH
];
75 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
76 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
77 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
78 static WCHAR units_cmW
[MAX_STRING_LEN
];
79 static WCHAR units_inW
[MAX_STRING_LEN
];
80 static WCHAR units_inchW
[MAX_STRING_LEN
];
81 static WCHAR units_ptW
[MAX_STRING_LEN
];
83 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
96 WCHAR findBuffer
[128];
99 /* Load string resources */
100 static void DoLoadStrings(void)
102 LPWSTR p
= wszFilter
;
103 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
104 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
105 static const WCHAR files_all
[] = {'*','.','*','\0'};
107 HINSTANCE hInstance
= GetModuleHandleW(0);
109 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
110 p
+= lstrlenW(p
) + 1;
111 lstrcpyW(p
, files_rtf
);
112 p
+= lstrlenW(p
) + 1;
113 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
114 p
+= lstrlenW(p
) + 1;
115 lstrcpyW(p
, files_txt
);
116 p
+= lstrlenW(p
) + 1;
117 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
118 p
+= lstrlenW(p
) + 1;
119 lstrcpyW(p
, files_txt
);
120 p
+= lstrlenW(p
) + 1;
121 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
122 p
+= lstrlenW(p
) + 1;
123 lstrcpyW(p
, files_all
);
124 p
+= lstrlenW(p
) + 1;
127 p
= wszDefaultFileName
;
128 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
131 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
133 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
134 LoadStringW(hInstance
, STRING_UNITS_IN
, units_inW
, MAX_STRING_LEN
);
135 LoadStringW(hInstance
, STRING_UNITS_INCH
, units_inchW
, MAX_STRING_LEN
);
136 LoadStringW(hInstance
, STRING_UNITS_PT
, units_ptW
, MAX_STRING_LEN
);
139 /* Show a message box with resource strings */
140 static int MessageBoxWithResStringW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
)
142 MSGBOXPARAMSW params
;
144 params
.cbSize
= sizeof(params
);
145 params
.hwndOwner
= hWnd
;
146 params
.hInstance
= GetModuleHandleW(0);
147 params
.lpszText
= lpText
;
148 params
.lpszCaption
= lpCaption
;
149 params
.dwStyle
= uType
;
150 params
.lpszIcon
= NULL
;
151 params
.dwContextHelpId
= 0;
152 params
.lpfnMsgBoxCallback
= NULL
;
153 params
.dwLanguageId
= 0;
154 return MessageBoxIndirectW(¶ms
);
158 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
162 ZeroMemory(&button
, sizeof(button
));
163 button
.iBitmap
= nImage
;
164 button
.idCommand
= nCommand
;
165 button
.fsState
= TBSTATE_ENABLED
;
166 button
.fsStyle
= TBSTYLE_BUTTON
;
169 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
172 static void AddSeparator(HWND hwndToolBar
)
176 ZeroMemory(&button
, sizeof(button
));
178 button
.idCommand
= 0;
180 button
.fsStyle
= TBSTYLE_SEP
;
183 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
186 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
188 HANDLE hFile
= (HANDLE
)cookie
;
191 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
199 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
203 HANDLE hFile
= (HANDLE
)cookie
;
205 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
207 if(!ret
|| (cb
!= written
))
215 LPWSTR
file_basename(LPWSTR path
)
217 LPWSTR pos
= path
+ lstrlenW(path
);
221 if(*pos
== '\\' || *pos
== '/')
231 static void set_caption(LPCWSTR wszNewFileName
)
233 static const WCHAR wszSeparator
[] = {' ','-',' '};
238 wszNewFileName
= wszDefaultFileName
;
240 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
242 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
243 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
248 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
249 length
+= lstrlenW(wszNewFileName
);
250 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
251 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
252 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
254 SetWindowTextW(hMainWnd
, wszCaption
);
256 HeapFree(GetProcessHeap(), 0, wszCaption
);
259 static BOOL
validate_endptr(LPCWSTR endptr
, UNIT
*punit
)
268 while(*endptr
== ' ')
272 return *endptr
== '\0';
274 if(!lstrcmpW(endptr
, units_cmW
))
277 endptr
+= lstrlenW(units_cmW
);
279 else if (!lstrcmpW(endptr
, units_inW
))
282 endptr
+= lstrlenW(units_inW
);
284 else if (!lstrcmpW(endptr
, units_inchW
))
287 endptr
+= lstrlenW(units_inchW
);
289 else if (!lstrcmpW(endptr
, units_ptW
))
292 endptr
+= lstrlenW(units_ptW
);
295 return *endptr
== '\0';
298 static BOOL
number_from_string(LPCWSTR string
, float *num
, UNIT
*punit
)
305 ret
= wcstod(string
, &endptr
);
309 if((ret
== 0 && errno
!= 0) || endptr
== string
|| !validate_endptr(endptr
, punit
))
319 static void set_size(float size
)
323 ZeroMemory(&fmt
, sizeof(fmt
));
324 fmt
.cbSize
= sizeof(fmt
);
325 fmt
.dwMask
= CFM_SIZE
;
326 fmt
.yHeight
= (int)(size
* 20.0);
327 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
330 static void on_sizelist_modified(HWND hwndSizeList
, LPWSTR wszNewFontSize
)
332 WCHAR sizeBuffer
[MAX_STRING_LEN
];
335 ZeroMemory(&format
, sizeof(format
));
336 format
.cbSize
= sizeof(format
);
337 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
339 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
340 if(lstrcmpW(sizeBuffer
, wszNewFontSize
))
343 if(number_from_string(wszNewFontSize
, &size
, NULL
)
349 SetWindowTextW(hwndSizeList
, sizeBuffer
);
350 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
351 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
356 static void add_size(HWND hSizeListWnd
, unsigned size
)
359 COMBOBOXEXITEMW cbItem
;
360 cbItem
.mask
= CBEIF_TEXT
;
363 wsprintfW(buffer
, stringFormat
, size
);
364 cbItem
.pszText
= buffer
;
365 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
368 static void populate_size_list(HWND hSizeListWnd
)
370 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
371 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
372 COMBOBOXEXITEMW cbFontItem
;
374 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
375 HDC hdc
= GetDC(hMainWnd
);
376 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
381 ZeroMemory(&fmt
, sizeof(fmt
));
382 fmt
.cbSize
= sizeof(fmt
);
383 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
385 cbFontItem
.mask
= CBEIF_LPARAM
;
386 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
387 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
389 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
391 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
393 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
395 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
396 GetDeviceCaps(hdc
, LOGPIXELSY
)));
399 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
400 add_size(hSizeListWnd
, choices
[i
]);
403 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
404 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
407 static void update_size_list(void)
409 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
410 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
411 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
412 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
415 ZeroMemory(&fmt
, sizeof(fmt
));
416 fmt
.cbSize
= sizeof(fmt
);
418 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
420 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
421 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
423 if(lstrcmpW(fontSize
, sizeBuffer
))
424 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
427 static void update_font_list(void)
429 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
430 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
431 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
432 WCHAR fontName
[MAX_STRING_LEN
];
435 ZeroMemory(&fmt
, sizeof(fmt
));
436 fmt
.cbSize
= sizeof(fmt
);
438 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
439 if (!SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
)) return;
441 if(lstrcmpW(fontName
, fmt
.szFaceName
))
443 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
444 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
451 static void clear_formatting(void)
455 pf
.cbSize
= sizeof(pf
);
456 pf
.dwMask
= PFM_ALIGNMENT
;
457 pf
.wAlignment
= PFA_LEFT
;
458 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
461 static int fileformat_number(WPARAM format
)
465 if(format
== SF_TEXT
)
468 } else if (format
== (SF_TEXT
| SF_UNICODE
))
475 static WPARAM
fileformat_flags(int format
)
477 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
479 return flags
[format
];
482 static void set_font(LPCWSTR wszFaceName
)
484 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
485 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
486 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
487 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
490 ZeroMemory(&fmt
, sizeof(fmt
));
492 fmt
.cbSize
= sizeof(fmt
);
493 fmt
.dwMask
= CFM_FACE
;
495 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
497 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
499 populate_size_list(hSizeListWnd
);
501 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)wszFaceName
);
504 static void set_default_font(void)
506 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
507 'R','o','m','a','n',0};
508 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
512 ZeroMemory(&fmt
, sizeof(fmt
));
514 fmt
.cbSize
= sizeof(fmt
);
515 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
518 if(fileFormat
& SF_RTF
)
521 font
= plainTextFont
;
523 lstrcpyW(fmt
.szFaceName
, font
);
525 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
528 static void on_fontlist_modified(LPWSTR wszNewFaceName
)
531 ZeroMemory(&format
, sizeof(format
));
532 format
.cbSize
= sizeof(format
);
533 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
535 if(lstrcmpW(format
.szFaceName
, wszNewFaceName
))
536 set_font(wszNewFaceName
);
539 static void add_font(LPCWSTR fontName
, DWORD fontType
, HWND hListWnd
, const NEWTEXTMETRICEXW
*ntmc
)
541 COMBOBOXEXITEMW cbItem
;
542 WCHAR buffer
[MAX_PATH
];
545 cbItem
.mask
= CBEIF_TEXT
;
546 cbItem
.pszText
= buffer
;
547 cbItem
.cchTextMax
= MAX_STRING_LEN
;
550 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
552 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
557 cbItem
.pszText
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName
) + 1)*sizeof(WCHAR
) );
558 lstrcpyW( cbItem
.pszText
, fontName
);
560 cbItem
.mask
|= CBEIF_LPARAM
;
561 if(fontType
& RASTER_FONTTYPE
)
562 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
564 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
565 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
566 HeapFree( GetProcessHeap(), 0, cbItem
.pszText
);
569 static void dialog_choose_font(void)
574 HDC hDC
= GetDC(hMainWnd
);
576 ZeroMemory(&cf
, sizeof(cf
));
577 cf
.lStructSize
= sizeof(cf
);
578 cf
.hwndOwner
= hMainWnd
;
580 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
582 ZeroMemory(&fmt
, sizeof(fmt
));
583 fmt
.cbSize
= sizeof(fmt
);
585 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
586 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
587 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
588 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
589 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
590 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
591 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
592 cf
.rgbColors
= fmt
.crTextColor
;
596 ZeroMemory(&fmt
, sizeof(fmt
));
597 fmt
.cbSize
= sizeof(fmt
);
598 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
599 fmt
.yHeight
= cf
.iPointSize
* 2;
601 if(cf
.nFontType
& BOLD_FONTTYPE
)
602 fmt
.dwEffects
|= CFE_BOLD
;
603 if(cf
.nFontType
& ITALIC_FONTTYPE
)
604 fmt
.dwEffects
|= CFE_ITALIC
;
605 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
606 fmt
.dwEffects
|= CFE_UNDERLINE
;
607 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
608 fmt
.dwEffects
|= CFE_STRIKEOUT
;
610 fmt
.crTextColor
= cf
.rgbColors
;
612 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
613 set_font(cf
.lpLogFont
->lfFaceName
);
618 static int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
619 DWORD FontType
, LPARAM lParam
)
621 HWND hListWnd
= (HWND
) lParam
;
623 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
626 add_font(lpelfe
->lfFaceName
, FontType
, hListWnd
, (const NEWTEXTMETRICEXW
*)lpntme
);
632 static void populate_font_list(HWND hListWnd
)
634 HDC hdc
= GetDC(hMainWnd
);
636 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
639 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
640 *fontinfo
.lfFaceName
= '\0';
641 fontinfo
.lfPitchAndFamily
= 0;
643 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
644 (LPARAM
)hListWnd
, 0);
646 ZeroMemory(&fmt
, sizeof(fmt
));
647 fmt
.cbSize
= sizeof(fmt
);
648 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
649 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
652 static void update_window(void)
656 GetClientRect(hMainWnd
, &rect
);
658 OnSize(hMainWnd
, SIZE_RESTORED
, MAKELPARAM(rect
.right
, rect
.bottom
));
661 static BOOL
is_bar_visible(int bandId
)
663 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
666 static void store_bar_state(int bandId
, BOOL show
)
668 int formatIndex
= reg_formatindex(fileFormat
);
671 barState
[formatIndex
] |= (1 << bandId
);
673 barState
[formatIndex
] &= ~(1 << bandId
);
676 static void set_toolbar_state(int bandId
, BOOL show
)
678 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
680 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
682 if(bandId
== BANDID_TOOLBAR
)
684 REBARBANDINFOW rbbinfo
;
685 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
687 rbbinfo
.cbSize
= REBARBANDINFOW_V6_SIZE
;
688 rbbinfo
.fMask
= RBBIM_STYLE
;
690 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
693 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
695 rbbinfo
.fStyle
|= RBBS_BREAK
;
697 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
700 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
|| bandId
== BANDID_RULER
)
701 store_bar_state(bandId
, show
);
704 static void set_statusbar_state(BOOL show
)
706 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
708 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
709 store_bar_state(BANDID_STATUSBAR
, show
);
712 static void set_bar_states(void)
714 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
715 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
716 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
717 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
718 set_toolbar_state(BANDID_RULER
, is_bar_visible(BANDID_RULER
));
719 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
724 static void preview_exit(HWND hMainWnd
)
726 HMENU hMenu
= LoadMenuW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDM_MAINMENU
));
727 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
730 ShowWindow(hEditorWnd
, TRUE
);
732 close_preview(hMainWnd
);
734 SetMenu(hMainWnd
, hMenu
);
735 registry_read_filelist(hMainWnd
);
740 static void set_fileformat(WPARAM format
)
746 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
749 static void ShowOpenError(DWORD Code
)
755 case ERROR_ACCESS_DENIED
:
756 Message
= MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED
);
760 Message
= MAKEINTRESOURCEW(STRING_OPEN_FAILED
);
762 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
765 static void DoOpenFile(LPCWSTR szOpenFileName
)
771 WPARAM format
= SF_TEXT
;
773 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
774 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
775 if (hFile
== INVALID_HANDLE_VALUE
)
777 ShowOpenError(GetLastError());
781 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
782 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
784 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
786 format
= SF_TEXT
| SF_UNICODE
;
787 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
788 } else if(readOut
>= 5)
790 static const char header
[] = "{\\rtf";
791 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
793 if(!memcmp(header
, fileStart
, 5))
795 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
798 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
),
799 wszAppTitle
, MB_OK
| MB_ICONEXCLAMATION
);
804 es
.dwCookie
= (DWORD_PTR
)hFile
;
805 es
.pfnCallback
= stream_in
;
808 set_fileformat(format
);
809 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
813 SetFocus(hEditorWnd
);
815 set_caption(szOpenFileName
);
817 lstrcpyW(wszFileName
, szOpenFileName
);
818 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
819 registry_set_filelist(szOpenFileName
, hMainWnd
);
823 static void ShowWriteError(DWORD Code
)
829 case ERROR_ACCESS_DENIED
:
830 Message
= MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED
);
834 Message
= MAKEINTRESOURCEW(STRING_WRITE_FAILED
);
836 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
839 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
845 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
846 FILE_ATTRIBUTE_NORMAL
, NULL
);
848 if(hFile
== INVALID_HANDLE_VALUE
)
850 ShowWriteError(GetLastError());
854 if(format
== (SF_TEXT
| SF_UNICODE
))
856 static const BYTE unicode
[] = {0xff,0xfe};
858 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
860 if(writeOut
!= sizeof(unicode
))
867 stream
.dwCookie
= (DWORD_PTR
)hFile
;
868 stream
.pfnCallback
= stream_out
;
870 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
874 SetFocus(hEditorWnd
);
879 gt
.flags
= GTL_DEFAULT
;
882 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
886 lstrcpyW(wszFileName
, wszSaveFileName
);
887 set_caption(wszFileName
);
888 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
889 set_fileformat(format
);
892 static void DialogSaveFile(void)
896 WCHAR wszFile
[MAX_PATH
] = {'\0'};
897 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
899 ZeroMemory(&sfn
, sizeof(sfn
));
901 sfn
.lStructSize
= sizeof(sfn
);
902 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
| OFN_ENABLESIZING
;
903 sfn
.hwndOwner
= hMainWnd
;
904 sfn
.lpstrFilter
= wszFilter
;
905 sfn
.lpstrFile
= wszFile
;
906 sfn
.nMaxFile
= MAX_PATH
;
907 sfn
.lpstrDefExt
= wszDefExt
;
908 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
910 while(GetSaveFileNameW(&sfn
))
912 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
914 if(MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
915 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
920 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
925 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
931 static BOOL
prompt_save_changes(void)
936 gt
.flags
= GTL_NUMCHARS
;
938 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
942 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
947 LPWSTR displayFileName
;
952 displayFileName
= wszDefaultFileName
;
954 displayFileName
= file_basename(wszFileName
);
956 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
957 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
962 wsprintfW(text
, wszSaveChanges
, displayFileName
);
964 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
966 HeapFree(GetProcessHeap(), 0, text
);
975 DoSaveFile(wszFileName
, fileFormat
);
986 static void DialogOpenFile(void)
990 WCHAR wszFile
[MAX_PATH
] = {'\0'};
991 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
993 ZeroMemory(&ofn
, sizeof(ofn
));
995 ofn
.lStructSize
= sizeof(ofn
);
996 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
| OFN_ENABLESIZING
;
997 ofn
.hwndOwner
= hMainWnd
;
998 ofn
.lpstrFilter
= wszFilter
;
999 ofn
.lpstrFile
= wszFile
;
1000 ofn
.nMaxFile
= MAX_PATH
;
1001 ofn
.lpstrDefExt
= wszDefExt
;
1002 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
1004 if(GetOpenFileNameW(&ofn
))
1006 if(prompt_save_changes())
1007 DoOpenFile(ofn
.lpstrFile
);
1011 static void dialog_about(void)
1013 HICON icon
= LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
, 48, 48, LR_SHARED
);
1014 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
1017 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1023 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
1026 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1028 sprintf(id
, "%d\n", (int)ps
->lParam
);
1029 SetWindowTextA(hIdWnd
, id
);
1030 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_NONE
)
1031 wrap
= IDC_PAGEFMT_WN
;
1032 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
1033 wrap
= IDC_PAGEFMT_WW
;
1034 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
1035 wrap
= IDC_PAGEFMT_WM
;
1038 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
,
1039 IDC_PAGEFMT_WM
, wrap
);
1041 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
1042 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
1043 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
1044 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
1045 if(barState
[ps
->lParam
] & (1 << BANDID_RULER
))
1046 CheckDlgButton(hWnd
, IDC_PAGEFMT_RU
, TRUE
);
1047 if(barState
[ps
->lParam
] & (1 << BANDID_STATUSBAR
))
1048 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1053 switch(LOWORD(wParam
))
1055 case IDC_PAGEFMT_WN
:
1056 case IDC_PAGEFMT_WW
:
1057 case IDC_PAGEFMT_WM
:
1058 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
, IDC_PAGEFMT_WM
,
1062 case IDC_PAGEFMT_TB
:
1063 case IDC_PAGEFMT_FB
:
1064 case IDC_PAGEFMT_RU
:
1065 case IDC_PAGEFMT_SB
:
1066 CheckDlgButton(hWnd
, LOWORD(wParam
),
1067 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1073 LPNMHDR header
= (LPNMHDR
)lParam
;
1074 if(header
->code
== PSN_APPLY
)
1076 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1080 GetWindowTextA(hIdWnd
, sid
, 4);
1082 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WN
))
1083 wordWrap
[id
] = ID_WORDWRAP_NONE
;
1084 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1085 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1086 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1087 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1089 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1090 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1092 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1094 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1095 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1097 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1099 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_RU
))
1100 barState
[id
] |= (1 << BANDID_RULER
);
1102 barState
[id
] &= ~(1 << BANDID_RULER
);
1104 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1105 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1107 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1115 static void dialog_viewproperties(void)
1117 PROPSHEETPAGEW psp
[2];
1118 PROPSHEETHEADERW psh
;
1120 HINSTANCE hInstance
= GetModuleHandleW(0);
1121 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1123 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1124 psp
[0].dwFlags
= PSP_USETITLE
;
1125 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1126 psp
[0].pfnDlgProc
= formatopts_proc
;
1127 psp
[0].hInstance
= hInstance
;
1128 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1129 psp
[0].pfnCallback
= NULL
;
1130 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1131 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1133 psp
[i
].dwSize
= psp
[0].dwSize
;
1134 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1135 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1136 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1137 psp
[i
].hInstance
= psp
[0].hInstance
;
1138 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1139 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1140 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1143 psh
.dwSize
= sizeof(psh
);
1144 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1145 psh
.hwndParent
= hMainWnd
;
1146 psh
.hInstance
= hInstance
;
1147 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1148 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1149 U3(psh
).ppsp
= ppsp
;
1150 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1152 if(fileFormat
& SF_RTF
)
1153 U2(psh
).nStartPage
= 1;
1155 U2(psh
).nStartPage
= 0;
1156 PropertySheetW(&psh
);
1158 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1161 static void HandleCommandLine(LPWSTR cmdline
)
1166 /* skip white space */
1167 while (*cmdline
== ' ') cmdline
++;
1169 /* skip executable name */
1170 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1172 if (*cmdline
== delimiter
) cmdline
++;
1173 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1174 if (*cmdline
== delimiter
) cmdline
++;
1178 while (isspace(*cmdline
)) cmdline
++;
1180 if (*cmdline
== '-' || *cmdline
== '/')
1182 if (!cmdline
[2] || isspace(cmdline
[2]))
1193 /* a filename starting by / */
1200 /* file name is passed on the command line */
1201 if (cmdline
[0] == '"')
1204 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1206 DoOpenFile(cmdline
);
1207 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1211 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED
), wszAppTitle
, MB_OK
);
1214 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1216 if(pFr
->Flags
& FR_DIALOGTERM
)
1219 pFr
->Flags
= FR_FINDNEXT
;
1223 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1225 FINDREPLACE_custom
*custom_data
= (FINDREPLACE_custom
*)pFr
->lCustData
;
1230 HMENU hMenu
= GetMenu(hMainWnd
);
1233 mi
.cbSize
= sizeof(mi
);
1234 mi
.fMask
= MIIM_DATA
;
1236 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1238 /* Make sure find field is saved. */
1239 if (pFr
->lpstrFindWhat
!= custom_data
->findBuffer
)
1241 lstrcpynW(custom_data
->findBuffer
, pFr
->lpstrFindWhat
,
1242 sizeof(custom_data
->findBuffer
));
1243 pFr
->lpstrFindWhat
= custom_data
->findBuffer
;
1246 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&sel
.cpMin
, (LPARAM
)&sel
.cpMax
);
1247 if(custom_data
->endPos
== -1) {
1248 custom_data
->endPos
= sel
.cpMin
;
1249 custom_data
->wrapped
= FALSE
;
1252 flags
= FR_DOWN
| (pFr
->Flags
& (FR_MATCHCASE
| FR_WHOLEWORD
));
1253 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1255 /* Only replace existing selectino if it is an exact match. */
1256 if (sel
.cpMin
!= sel
.cpMax
&&
1257 (pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
))
1260 SendMessageW(hEditorWnd
, EM_FINDTEXTEXW
, flags
, (LPARAM
)&ft
);
1261 if (ft
.chrgText
.cpMin
== sel
.cpMin
&& ft
.chrgText
.cpMax
== sel
.cpMax
) {
1262 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1263 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&sel
.cpMin
, (LPARAM
)&sel
.cpMax
);
1267 /* Search from the start of the selection, but exclude the first character
1268 * from search if there is a selection. */
1269 ft
.chrg
.cpMin
= sel
.cpMin
;
1270 if (sel
.cpMin
!= sel
.cpMax
)
1273 /* Search to the end, then wrap around and search from the start. */
1274 if (!custom_data
->wrapped
) {
1276 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTEXW
, flags
, (LPARAM
)&ft
);
1278 custom_data
->wrapped
= TRUE
;
1284 ft
.chrg
.cpMax
= custom_data
->endPos
+ lstrlenW(pFr
->lpstrFindWhat
) - 1;
1285 if (ft
.chrg
.cpMax
> ft
.chrg
.cpMin
)
1286 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTEXW
, flags
, (LPARAM
)&ft
);
1290 custom_data
->endPos
= -1;
1291 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
),
1292 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1294 SendMessageW(hEditorWnd
, EM_SETSEL
, ft
.chrgText
.cpMin
, ft
.chrgText
.cpMax
);
1295 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1297 if (pFr
->Flags
& FR_REPLACEALL
)
1298 return handle_findmsg(pFr
);
1305 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1307 static WCHAR selBuffer
[128];
1308 static WCHAR replaceBuffer
[128];
1309 static FINDREPLACE_custom custom_data
;
1310 static const WCHAR endl
= '\r';
1313 /* Allow only one search/replace dialog to open */
1314 if(hFindWnd
!= NULL
)
1316 SetActiveWindow(hFindWnd
);
1320 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1321 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1322 fr
->hwndOwner
= hMainWnd
;
1323 fr
->Flags
= FR_HIDEUPDOWN
;
1324 /* Find field is filled with the selected text if it is non-empty
1325 * and stays within the same paragraph, otherwise the previous
1326 * find field is used. */
1327 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&ft
.chrg
.cpMin
,
1328 (LPARAM
)&ft
.chrg
.cpMax
);
1329 ft
.lpstrText
= &endl
;
1330 if (ft
.chrg
.cpMin
!= ft
.chrg
.cpMax
&&
1331 SendMessageW(hEditorWnd
, EM_FINDTEXTW
, FR_DOWN
, (LPARAM
)&ft
) == -1)
1333 /* Use a temporary buffer for the selected text so that the saved
1334 * find field is only overwritten when a find/replace is clicked. */
1335 GETTEXTEX gt
= {sizeof(selBuffer
), GT_SELECTION
, 1200, NULL
, NULL
};
1336 SendMessageW(hEditorWnd
, EM_GETTEXTEX
, (WPARAM
)>
, (LPARAM
)selBuffer
);
1337 fr
->lpstrFindWhat
= selBuffer
;
1339 fr
->lpstrFindWhat
= custom_data
.findBuffer
;
1341 fr
->lpstrReplaceWith
= replaceBuffer
;
1342 custom_data
.endPos
= -1;
1343 custom_data
.wrapped
= FALSE
;
1344 fr
->lCustData
= (LPARAM
)&custom_data
;
1345 fr
->wFindWhatLen
= sizeof(custom_data
.findBuffer
);
1346 fr
->wReplaceWithLen
= sizeof(replaceBuffer
);
1349 hFindWnd
= ReplaceTextW(fr
);
1351 hFindWnd
= FindTextW(fr
);
1354 static int units_to_twips(UNIT unit
, float number
)
1361 twips
= (int)(number
* 1000.0 / (float)CENTMM_PER_INCH
* (float)TWIPS_PER_INCH
);
1365 twips
= (int)(number
* (float)TWIPS_PER_INCH
);
1369 twips
= (int)(number
* (0.0138 * (float)TWIPS_PER_INCH
));
1376 static void append_current_units(LPWSTR buffer
)
1378 static const WCHAR space
[] = {' ', 0};
1379 lstrcatW(buffer
, space
);
1380 lstrcatW(buffer
, units_cmW
);
1383 static void number_with_units(LPWSTR buffer
, int number
)
1385 static const WCHAR fmt
[] = {'%','.','2','f',' ','%','s','\0'};
1386 float converted
= (float)number
/ (float)TWIPS_PER_INCH
*(float)CENTMM_PER_INCH
/ 1000.0;
1388 sprintfW(buffer
, fmt
, converted
, units_cmW
);
1391 static BOOL
get_comboexlist_selection(HWND hComboEx
, LPWSTR wszBuffer
, UINT bufferLength
)
1393 COMBOBOXEXITEMW cbItem
;
1394 COMBOBOXINFO cbInfo
;
1398 hCombo
= (HWND
)SendMessage(hComboEx
, CBEM_GETCOMBOCONTROL
, 0, 0);
1401 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
1402 result
= SendMessage(hCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)&cbInfo
);
1405 hList
= cbInfo
.hwndList
;
1406 idx
= SendMessage(hList
, LB_GETCURSEL
, 0, 0);
1410 ZeroMemory(&cbItem
, sizeof(cbItem
));
1411 cbItem
.mask
= CBEIF_TEXT
;
1413 cbItem
.pszText
= wszBuffer
;
1414 cbItem
.cchTextMax
= bufferLength
-1;
1415 result
= SendMessageW(hComboEx
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
);
1420 static INT_PTR CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1426 WCHAR buffer
[MAX_STRING_LEN
];
1428 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1431 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1433 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1434 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1436 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1437 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1438 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1440 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1445 switch(LOWORD(wParam
))
1448 if (HIWORD(wParam
) != LBN_DBLCLK
)
1455 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1457 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1461 WCHAR buffer
[MAX_STRING_LEN
];
1462 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1463 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1469 EndDialog(hWnd
, wParam
);
1476 static INT_PTR CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1482 HINSTANCE hInstance
= GetModuleHandleW(0);
1483 WCHAR buffer
[MAX_STRING_LEN
];
1484 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1486 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, buffer
, MAX_STRING_LEN
);
1487 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1488 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, buffer
, MAX_STRING_LEN
);
1489 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1490 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, buffer
, MAX_STRING_LEN
);
1491 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1493 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1498 switch(LOWORD(wParam
))
1503 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1504 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1507 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1512 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1519 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1521 static const WORD ALIGNMENT_VALUES
[] = {PFA_LEFT
, PFA_RIGHT
, PFA_CENTER
};
1527 HINSTANCE hInstance
= GetModuleHandleW(0);
1528 WCHAR buffer
[MAX_STRING_LEN
];
1529 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1530 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1531 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1532 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1536 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1538 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1539 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1541 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1542 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1544 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1546 pf
.cbSize
= sizeof(pf
);
1547 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1549 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1551 if(pf
.wAlignment
== PFA_RIGHT
)
1553 else if(pf
.wAlignment
== PFA_CENTER
)
1556 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1558 number_with_units(buffer
, pf
.dxStartIndent
+ pf
.dxOffset
);
1559 SetWindowTextW(hLeftWnd
, buffer
);
1560 number_with_units(buffer
, pf
.dxRightIndent
);
1561 SetWindowTextW(hRightWnd
, buffer
);
1562 number_with_units(buffer
, -pf
.dxOffset
);
1563 SetWindowTextW(hFirstWnd
, buffer
);
1568 switch(LOWORD(wParam
))
1572 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1573 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1574 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1575 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1576 WCHAR buffer
[MAX_STRING_LEN
];
1583 index
= SendMessageW(hListWnd
, CB_GETCURSEL
, 0, 0);
1584 pf
.wAlignment
= ALIGNMENT_VALUES
[index
];
1586 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1587 if(number_from_string(buffer
, &num
, &unit
))
1589 pf
.dxOffset
= units_to_twips(unit
, num
);
1590 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1591 if(number_from_string(buffer
, &num
, &unit
))
1593 pf
.dxRightIndent
= units_to_twips(unit
, num
);
1594 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1595 if(number_from_string(buffer
, &num
, &unit
))
1597 pf
.dxStartIndent
= units_to_twips(unit
, num
);
1601 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1602 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1606 if (pf
.dxOffset
+ pf
.dxStartIndent
< 0
1607 && pf
.dxStartIndent
< 0)
1609 /* The first line is before the left edge, so
1610 * make sure it is at the left edge. */
1611 pf
.dxOffset
= -pf
.dxStartIndent
;
1612 } else if (pf
.dxOffset
< 0) {
1613 /* The second and following lines are before
1614 * the left edge, so set it to be at the left
1615 * edge, and adjust the first line since it
1616 * is relative to it. */
1617 pf
.dxStartIndent
= max(pf
.dxStartIndent
+ pf
.dxOffset
, 0);
1620 /* Internally the dxStartIndent is the absolute
1621 * offset for the first line and dxOffset is
1622 * to it value as opposed how it is displayed with
1623 * the first line being the relative value.
1624 * These two lines make the adjustments. */
1625 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1626 pf
.dxOffset
= pf
.dxOffset
- pf
.dxStartIndent
;
1628 pf
.cbSize
= sizeof(pf
);
1629 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1631 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1637 EndDialog(hWnd
, wParam
);
1644 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1650 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1652 WCHAR buffer
[MAX_STRING_LEN
];
1655 pf
.cbSize
= sizeof(pf
);
1656 pf
.dwMask
= PFM_TABSTOPS
;
1657 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1658 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1660 for(i
= 0; i
< pf
.cTabCount
; i
++)
1662 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1663 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1670 switch(LOWORD(wParam
))
1674 HWND hTabWnd
= (HWND
)lParam
;
1675 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1676 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1677 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1679 if(GetWindowTextLengthW(hTabWnd
))
1680 EnableWindow(hAddWnd
, TRUE
);
1682 EnableWindow(hAddWnd
, FALSE
);
1684 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1686 EnableWindow(hEmptyWnd
, TRUE
);
1688 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1689 EnableWindow(hDelWnd
, FALSE
);
1691 EnableWindow(hDelWnd
, TRUE
);
1694 EnableWindow(hEmptyWnd
, FALSE
);
1701 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1702 WCHAR buffer
[MAX_STRING_LEN
];
1705 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1706 append_current_units(buffer
);
1708 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1711 int item_count
= SendMessage(hTabWnd
, CB_GETCOUNT
, 0, 0);
1713 if(!number_from_string(buffer
, &number
, &unit
))
1715 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1716 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1717 } else if (item_count
>= MAX_TAB_STOPS
) {
1718 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_MAX_TAB_STOPS
),
1719 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1722 float next_number
= -1;
1723 int next_number_in_twips
= -1;
1724 int insert_number
= units_to_twips(unit
, number
);
1726 /* linear search for position to insert the string */
1727 for(i
= 0; i
< item_count
; i
++)
1729 SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
, (LPARAM
)&buffer
);
1730 number_from_string(buffer
, &next_number
, &unit
);
1731 next_number_in_twips
= units_to_twips(unit
, next_number
);
1732 if (insert_number
<= next_number_in_twips
)
1735 if (insert_number
!= next_number_in_twips
)
1737 number_with_units(buffer
, insert_number
);
1738 SendMessageW(hTabWnd
, CB_INSERTSTRING
, i
, (LPARAM
)&buffer
);
1739 SetWindowTextW(hTabWnd
, 0);
1749 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1751 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1753 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1759 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1760 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1767 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1769 WCHAR buffer
[MAX_STRING_LEN
];
1774 pf
.cbSize
= sizeof(pf
);
1775 pf
.dwMask
= PFM_TABSTOPS
;
1777 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1778 (LPARAM
)&buffer
) != CB_ERR
&&
1779 i
< MAX_TAB_STOPS
; i
++)
1781 number_from_string(buffer
, &number
, &unit
);
1782 pf
.rgxTabs
[i
] = units_to_twips(unit
, number
);
1785 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1789 EndDialog(hWnd
, wParam
);
1796 static int context_menu(LPARAM lParam
)
1798 int x
= (int)(short)LOWORD(lParam
);
1799 int y
= (int)(short)HIWORD(lParam
);
1800 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1804 int from
= 0, to
= 0;
1806 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1807 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, to
);
1808 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1813 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1814 x
, y
, 0, hMainWnd
, 0);
1819 static LRESULT
OnCreate( HWND hWnd
)
1821 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
, hRulerWnd
;
1822 HINSTANCE hInstance
= GetModuleHandleW(0);
1825 int nStdBitmaps
= 0;
1828 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1829 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1831 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1833 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1834 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1835 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1837 rbi
.cbSize
= sizeof(rbi
);
1840 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1843 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1845 1, hInstance
, IDB_TOOLBAR
,
1847 24, 24, 16, 16, sizeof(TBBUTTON
));
1849 ab
.hInst
= HINST_COMMCTRL
;
1850 ab
.nID
= IDB_STD_SMALL_COLOR
;
1851 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1853 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1854 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1855 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1856 AddSeparator(hToolBarWnd
);
1857 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1858 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1859 AddSeparator(hToolBarWnd
);
1860 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1861 AddSeparator(hToolBarWnd
);
1862 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1863 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1864 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1865 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1866 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1867 AddSeparator(hToolBarWnd
);
1868 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1870 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1872 rbb
.cbSize
= REBARBANDINFOW_V6_SIZE
;
1873 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1874 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1876 rbb
.hwndChild
= hToolBarWnd
;
1878 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1879 rbb
.wID
= BANDID_TOOLBAR
;
1881 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1883 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1884 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1885 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1887 rbb
.hwndChild
= hFontListWnd
;
1889 rbb
.wID
= BANDID_FONTLIST
;
1891 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1893 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1894 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1895 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1897 rbb
.hwndChild
= hSizeListWnd
;
1899 rbb
.fStyle
^= RBBS_BREAK
;
1900 rbb
.wID
= BANDID_SIZELIST
;
1902 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1904 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1905 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1906 IDC_FORMATBAR
, 8, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1908 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1909 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1910 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1911 AddButton(hFormatBarWnd
, 3, ID_FORMAT_COLOR
);
1912 AddSeparator(hFormatBarWnd
);
1913 AddButton(hFormatBarWnd
, 4, ID_ALIGN_LEFT
);
1914 AddButton(hFormatBarWnd
, 5, ID_ALIGN_CENTER
);
1915 AddButton(hFormatBarWnd
, 6, ID_ALIGN_RIGHT
);
1916 AddSeparator(hFormatBarWnd
);
1917 AddButton(hFormatBarWnd
, 7, ID_BULLET
);
1919 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
1921 rbb
.hwndChild
= hFormatBarWnd
;
1922 rbb
.wID
= BANDID_FORMATBAR
;
1924 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1926 hRulerWnd
= CreateWindowExW(0, WC_STATICW
, NULL
, WS_VISIBLE
| WS_CHILD
,
1927 0, 0, 200, 10, hReBarWnd
, (HMENU
)IDC_RULER
, hInstance
, NULL
);
1930 rbb
.hwndChild
= hRulerWnd
;
1931 rbb
.wID
= BANDID_RULER
;
1932 rbb
.fStyle
|= RBBS_BREAK
;
1934 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1936 hDLL
= LoadLibraryW(wszRichEditDll
);
1939 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
1940 MB_OK
| MB_ICONEXCLAMATION
);
1944 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, RICHEDIT_CLASS20W
, NULL
,
1945 WS_CHILD
|WS_VISIBLE
|ES_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
1946 |ES_WANTRETURN
|WS_VSCROLL
|ES_NOHIDESEL
|WS_HSCROLL
,
1947 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
1951 fprintf(stderr
, "Error code %u\n", GetLastError());
1956 SetFocus(hEditorWnd
);
1957 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
1961 populate_font_list(hFontListWnd
);
1962 populate_size_list(hSizeListWnd
);
1964 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1966 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
1968 registry_read_filelist(hWnd
);
1969 registry_read_formatopts_all(barState
, wordWrap
);
1970 registry_read_options();
1971 DragAcceptFiles(hWnd
, TRUE
);
1976 static LRESULT
OnUser( HWND hWnd
)
1978 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1979 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1980 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
1981 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
1987 ZeroMemory(&fmt
, sizeof(fmt
));
1988 fmt
.cbSize
= sizeof(fmt
);
1990 ZeroMemory(&pf
, sizeof(pf
));
1991 pf
.cbSize
= sizeof(pf
);
1993 gt
.flags
= GTL_NUMCHARS
;
1996 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
1997 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
1999 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
2001 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
2002 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
2003 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
2004 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
2005 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
2006 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
2007 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
2009 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
2010 (fmt
.dwEffects
& CFE_BOLD
));
2011 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
2012 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
2013 (fmt
.dwEffects
& CFE_ITALIC
));
2014 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
2015 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
2016 (fmt
.dwEffects
& CFE_UNDERLINE
));
2017 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
2019 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2020 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
2021 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
2022 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
2024 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
2028 static LRESULT
OnNotify( HWND hWnd
, LPARAM lParam
)
2030 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2031 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2032 NMHDR
*pHdr
= (NMHDR
*)lParam
;
2033 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
2034 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
2036 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
2038 if (pHdr
->code
== CBEN_ENDEDITW
)
2040 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
2041 if(pHdr
->hwndFrom
== hwndFontList
)
2043 on_fontlist_modified((LPWSTR
)endEdit
->szText
);
2044 } else if (pHdr
->hwndFrom
== hwndSizeList
)
2046 on_sizelist_modified(hwndFontList
,(LPWSTR
)endEdit
->szText
);
2052 if (pHdr
->hwndFrom
!= hwndEditor
)
2055 if (pHdr
->code
== EN_SELCHANGE
)
2057 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
2062 sprintf( buf
,"selection = %d..%d, line count=%ld",
2063 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
2064 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
2065 SetWindowTextA(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
2066 SendMessage(hWnd
, WM_USER
, 0, 0);
2072 /* Copied from dlls/comdlg32/fontdlg.c */
2073 static const COLORREF textcolors
[]=
2075 0x00000000L
,0x00000080L
,0x00008000L
,0x00008080L
,
2076 0x00800000L
,0x00800080L
,0x00808000L
,0x00808080L
,
2077 0x00c0c0c0L
,0x000000ffL
,0x0000ff00L
,0x0000ffffL
,
2078 0x00ff0000L
,0x00ff00ffL
,0x00ffff00L
,0x00FFFFFFL
2081 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2083 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2084 static FINDREPLACEW findreplace
;
2086 if ((HWND
)lParam
== hwndEditor
)
2089 switch(LOWORD(wParam
))
2093 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
2098 HINSTANCE hInstance
= GetModuleHandleW(0);
2099 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
2102 if(ret
!= ID_NEWFILE_ABORT
)
2104 if(prompt_save_changes())
2109 wszFileName
[0] = '\0';
2113 st
.flags
= ST_DEFAULT
;
2115 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
2117 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2118 set_fileformat(ret
);
2132 DoSaveFile(wszFileName
, fileFormat
);
2137 case ID_FILE_SAVEAS
:
2141 case ID_FILE_RECENT1
:
2142 case ID_FILE_RECENT2
:
2143 case ID_FILE_RECENT3
:
2144 case ID_FILE_RECENT4
:
2146 HMENU hMenu
= GetMenu(hWnd
);
2149 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2150 mi
.fMask
= MIIM_DATA
;
2151 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2152 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2157 dialog_find(&findreplace
, FALSE
);
2161 handle_findmsg(&findreplace
);
2165 dialog_find(&findreplace
, TRUE
);
2168 case ID_FONTSETTINGS
:
2169 dialog_choose_font();
2173 dialog_print(hWnd
, wszFileName
);
2174 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2177 case ID_PRINT_QUICK
:
2178 print_quick(hMainWnd
, wszFileName
);
2179 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2184 int index
= reg_formatindex(fileFormat
);
2185 DWORD tmp
= barState
[index
];
2186 barState
[index
] = 1 << BANDID_STATUSBAR
;
2188 barState
[index
] = tmp
;
2189 ShowWindow(hEditorWnd
, FALSE
);
2191 init_preview(hWnd
, wszFileName
);
2193 SetMenu(hWnd
, NULL
);
2194 InvalidateRect(0, 0, TRUE
);
2199 dialog_printsetup(hWnd
);
2200 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2203 case ID_FORMAT_BOLD
:
2204 case ID_FORMAT_ITALIC
:
2205 case ID_FORMAT_UNDERLINE
:
2208 int effects
= CFE_BOLD
;
2210 ZeroMemory(&fmt
, sizeof(fmt
));
2211 fmt
.cbSize
= sizeof(fmt
);
2212 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2214 fmt
.dwMask
= CFM_BOLD
;
2216 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2218 effects
= CFE_ITALIC
;
2219 fmt
.dwMask
= CFM_ITALIC
;
2220 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2222 effects
= CFE_UNDERLINE
;
2223 fmt
.dwMask
= CFM_UNDERLINE
;
2226 fmt
.dwEffects
^= effects
;
2228 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2232 case ID_FORMAT_COLOR
:
2234 HWND hReBarWnd
= GetDlgItem(hWnd
, IDC_REBAR
);
2235 HWND hFormatBarWnd
= GetDlgItem(hReBarWnd
, IDC_FORMATBAR
);
2240 int itemidx
= SendMessage(hFormatBarWnd
, TB_COMMANDTOINDEX
, ID_FORMAT_COLOR
, 0);
2242 SendMessage(hFormatBarWnd
, TB_GETITEMRECT
, itemidx
, (LPARAM
)&itemrc
);
2244 pt
.y
= itemrc
.bottom
;
2245 ClientToScreen(hFormatBarWnd
, &pt
);
2246 hPop
= GetSubMenu(hColorPopupMenu
, 0);
2247 mid
= TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_LEFTBUTTON
|
2248 TPM_RETURNCMD
| TPM_NONOTIFY
,
2249 pt
.x
, pt
.y
, 0, hWnd
, 0);
2250 if (mid
>= ID_COLOR_FIRST
&& mid
<= ID_COLOR_AUTOMATIC
)
2254 ZeroMemory(&fmt
, sizeof(fmt
));
2255 fmt
.cbSize
= sizeof(fmt
);
2256 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2258 fmt
.dwMask
= CFM_COLOR
;
2260 if (mid
< ID_COLOR_AUTOMATIC
) {
2261 fmt
.crTextColor
= textcolors
[mid
- ID_COLOR_FIRST
];
2262 fmt
.dwEffects
&= ~CFE_AUTOCOLOR
;
2264 fmt
.dwEffects
|= CFE_AUTOCOLOR
;
2267 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2273 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2277 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2281 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2285 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2288 case ID_EDIT_SELECTALL
:
2290 CHARRANGE range
= {0, -1};
2291 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2292 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2296 case ID_EDIT_GETTEXT
:
2298 int nLen
= GetWindowTextLengthW(hwndEditor
);
2299 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2302 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2303 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2305 HeapFree( GetProcessHeap(), 0, data
);
2306 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2308 tr
.chrg
.cpMax
= nLen
;
2309 tr
.lpstrText
= data
;
2310 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2311 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2312 HeapFree( GetProcessHeap(), 0, data
);
2314 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2318 case ID_EDIT_CHARFORMAT
:
2319 case ID_EDIT_DEFCHARFORMAT
:
2323 ZeroMemory(&cf
, sizeof(cf
));
2324 cf
.cbSize
= sizeof(cf
);
2326 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2327 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2331 case ID_EDIT_PARAFORMAT
:
2334 ZeroMemory(&pf
, sizeof(pf
));
2335 pf
.cbSize
= sizeof(pf
);
2336 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2340 case ID_EDIT_SELECTIONINFO
:
2342 CHARRANGE range
= {0, -1};
2346 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2347 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2348 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2349 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2350 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2351 MessageBoxW(hWnd
, data
, wszAppTitle
, MB_OK
);
2352 HeapFree( GetProcessHeap(), 0, data
);
2353 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2357 case ID_EDIT_READONLY
:
2359 LONG nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2360 if (nStyle
& ES_READONLY
)
2361 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2363 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2367 case ID_EDIT_MODIFIED
:
2368 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2369 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2371 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2375 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2379 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2386 pf
.cbSize
= sizeof(pf
);
2387 pf
.dwMask
= PFM_NUMBERING
;
2388 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2390 pf
.dwMask
|= PFM_OFFSET
;
2392 if(pf
.wNumbering
== PFN_BULLET
)
2398 pf
.wNumbering
= PFN_BULLET
;
2402 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2407 case ID_ALIGN_CENTER
:
2408 case ID_ALIGN_RIGHT
:
2412 pf
.cbSize
= sizeof(pf
);
2413 pf
.dwMask
= PFM_ALIGNMENT
;
2414 switch(LOWORD(wParam
)) {
2415 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2416 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2417 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2419 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2424 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2428 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2431 case ID_TOGGLE_TOOLBAR
:
2432 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2436 case ID_TOGGLE_FORMATBAR
:
2437 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2438 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2439 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2443 case ID_TOGGLE_STATUSBAR
:
2444 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2448 case ID_TOGGLE_RULER
:
2449 set_toolbar_state(BANDID_RULER
, !is_bar_visible(BANDID_RULER
));
2454 DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, datetime_proc
);
2458 DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
, paraformat_proc
);
2462 DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2469 case ID_VIEWPROPERTIES
:
2470 dialog_viewproperties();
2474 if (HIWORD(wParam
) == CBN_SELENDOK
)
2476 WCHAR buffer
[LF_FACESIZE
];
2477 HWND hwndFontList
= (HWND
)lParam
;
2478 get_comboexlist_selection(hwndFontList
, buffer
, LF_FACESIZE
);
2479 on_fontlist_modified(buffer
);
2484 if (HIWORD(wParam
) == CBN_SELENDOK
)
2486 WCHAR buffer
[MAX_STRING_LEN
+1];
2487 HWND hwndSizeList
= (HWND
)lParam
;
2488 get_comboexlist_selection(hwndSizeList
, buffer
, MAX_STRING_LEN
+1);
2489 on_sizelist_modified(hwndSizeList
, buffer
);
2494 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2500 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
)
2502 HMENU hMenu
= (HMENU
)wParam
;
2503 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2504 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2506 int nAlignment
= -1;
2512 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2513 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2514 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2516 pf
.cbSize
= sizeof(PARAFORMAT
);
2517 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2518 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2519 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2520 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2521 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2522 if (pf
.dwMask
& PFM_ALIGNMENT
)
2523 nAlignment
= pf
.wAlignment
;
2524 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2525 MF_CHECKED
: MF_UNCHECKED
);
2526 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2527 MF_CHECKED
: MF_UNCHECKED
);
2528 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2529 MF_CHECKED
: MF_UNCHECKED
);
2530 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2531 MF_CHECKED
: MF_UNCHECKED
));
2532 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2533 MF_ENABLED
: MF_GRAYED
);
2534 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2535 MF_ENABLED
: MF_GRAYED
);
2537 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2538 MF_CHECKED
: MF_UNCHECKED
);
2540 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2541 MF_CHECKED
: MF_UNCHECKED
);
2543 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2544 MF_CHECKED
: MF_UNCHECKED
);
2546 CheckMenuItem(hMenu
, ID_TOGGLE_RULER
, MF_BYCOMMAND
|(is_bar_visible(BANDID_RULER
)) ? MF_CHECKED
: MF_UNCHECKED
);
2548 gt
.flags
= GTL_NUMCHARS
;
2550 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2551 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2553 mi
.cbSize
= sizeof(mi
);
2554 mi
.fMask
= MIIM_DATA
;
2556 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2558 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2559 MF_ENABLED
: MF_GRAYED
));
2561 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2566 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2568 int nStatusSize
= 0;
2570 HWND hwndEditor
= preview_isactive() ? GetDlgItem(hWnd
, IDC_PREVIEW
) : GetDlgItem(hWnd
, IDC_EDITOR
);
2571 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2572 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2573 HWND hRulerWnd
= GetDlgItem(hwndReBar
, IDC_RULER
);
2574 int rebarHeight
= 0;
2578 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2579 if (IsWindowVisible(hwndStatusBar
))
2581 GetClientRect(hwndStatusBar
, &rc
);
2582 nStatusSize
= rc
.bottom
- rc
.top
;
2590 rebarHeight
= SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
2592 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2596 GetClientRect(hWnd
, &rc
);
2597 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2600 redraw_ruler(hRulerWnd
);
2602 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2605 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2607 if(msg
== ID_FINDMSGSTRING
)
2608 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2613 return OnCreate( hWnd
);
2616 return OnUser( hWnd
);
2619 return OnNotify( hWnd
, lParam
);
2622 if(preview_isactive())
2624 return preview_command( hWnd
, wParam
);
2627 return OnCommand( hWnd
, wParam
, lParam
);
2634 if(preview_isactive())
2637 } else if(prompt_save_changes())
2639 registry_set_options(hMainWnd
);
2640 registry_set_formatopts_all(barState
);
2647 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2650 case WM_INITMENUPOPUP
:
2651 return OnInitPopupMenu( hWnd
, wParam
);
2654 return OnSize( hWnd
, wParam
, lParam
);
2656 case WM_CONTEXTMENU
:
2657 if((HWND
)wParam
== hEditorWnd
)
2658 return context_menu(lParam
);
2660 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2664 WCHAR file
[MAX_PATH
];
2665 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2666 DragFinish((HDROP
)wParam
);
2668 if(prompt_save_changes())
2673 if(!preview_isactive())
2674 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2677 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2683 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int nCmdShow
)
2685 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2690 UINT_PTR hPrevRulerProc
;
2694 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2695 'T','A','B','L','E','\0'};
2697 InitCommonControlsEx(&classes
);
2699 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2701 wc
.cbSize
= sizeof(wc
);
2702 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2703 wc
.lpfnWndProc
= WndProc
;
2706 wc
.hInstance
= hInstance
;
2707 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2708 wc
.hIconSm
= LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
,
2709 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
2710 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2711 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2712 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2713 wc
.lpszClassName
= wszMainWndClass
;
2714 RegisterClassExW(&wc
);
2716 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2717 wc
.lpfnWndProc
= preview_proc
;
2720 wc
.hInstance
= hInstance
;
2723 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2724 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2725 wc
.lpszMenuName
= NULL
;
2726 wc
.lpszClassName
= wszPreviewWndClass
;
2727 RegisterClassExW(&wc
);
2729 registry_read_winrect(&rc
);
2730 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2731 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2732 registry_read_maximized(&bMaximized
);
2733 if ((nCmdShow
== SW_SHOWNORMAL
|| nCmdShow
== SW_SHOWDEFAULT
)
2735 nCmdShow
= SW_SHOWMAXIMIZED
;
2736 ShowWindow(hMainWnd
, nCmdShow
);
2740 set_fileformat(SF_RTF
);
2741 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2742 hColorPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_COLOR_POPUP
));
2743 get_default_printer_opts();
2744 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2746 hRulerWnd
= GetDlgItem(GetDlgItem(hMainWnd
, IDC_REBAR
), IDC_RULER
);
2747 SendMessageW(GetDlgItem(hMainWnd
, IDC_EDITOR
), EM_POSFROMCHAR
, (WPARAM
)&EditPoint
, 0);
2748 hPrevRulerProc
= SetWindowLongPtrW(hRulerWnd
, GWLP_WNDPROC
, (UINT_PTR
)ruler_proc
);
2749 SendMessageW(hRulerWnd
, WM_USER
, (WPARAM
)&EditPoint
, hPrevRulerProc
);
2751 HandleCommandLine(GetCommandLineW());
2753 while(GetMessageW(&msg
,0,0,0))
2755 if (IsDialogMessage(hFindWnd
, &msg
))
2758 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2760 TranslateMessage(&msg
);
2761 DispatchMessageW(&msg
);
2762 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2763 SendMessageW(hMainWnd
, WM_USER
, 0, 0);