2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2007 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
41 #ifdef NONAMELESSUNION
52 static const WCHAR xszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
54 static const WCHAR wszRichEditClass
[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
55 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
56 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
58 static const WCHAR key_recentfiles
[] = {'R','e','c','e','n','t',' ','f','i','l','e',
59 ' ','l','i','s','t',0};
60 static const WCHAR key_options
[] = {'O','p','t','i','o','n','s',0};
61 static const WCHAR key_rtf
[] = {'R','T','F',0};
62 static const WCHAR key_text
[] = {'T','e','x','t',0};
64 static const WCHAR var_file
[] = {'F','i','l','e','%','d',0};
65 static const WCHAR var_framerect
[] = {'F','r','a','m','e','R','e','c','t',0};
66 static const WCHAR var_barstate0
[] = {'B','a','r','S','t','a','t','e','0',0};
68 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
71 static HWND hEditorWnd
;
73 static HMENU hPopupMenu
;
75 static UINT ID_FINDMSGSTRING
;
77 static DWORD wordWrap
[2];
78 static WPARAM fileFormat
= SF_RTF
;
80 static WCHAR wszFileName
[MAX_PATH
];
81 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
82 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
83 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
84 static WCHAR units_cmW
[MAX_STRING_LEN
];
86 static char units_cmA
[MAX_STRING_LEN
];
88 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
90 /* Load string resources */
91 static void DoLoadStrings(void)
94 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
95 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
96 static const WCHAR files_all
[] = {'*','.','*','\0'};
98 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
100 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
101 p
+= lstrlenW(p
) + 1;
102 lstrcpyW(p
, files_rtf
);
103 p
+= lstrlenW(p
) + 1;
104 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
105 p
+= lstrlenW(p
) + 1;
106 lstrcpyW(p
, files_txt
);
107 p
+= lstrlenW(p
) + 1;
108 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
109 p
+= lstrlenW(p
) + 1;
110 lstrcpyW(p
, files_txt
);
111 p
+= lstrlenW(p
) + 1;
112 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
113 p
+= lstrlenW(p
) + 1;
114 lstrcpyW(p
, files_all
);
115 p
+= lstrlenW(p
) + 1;
118 p
= wszDefaultFileName
;
119 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
122 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
124 LoadStringA(hInstance
, STRING_UNITS_CM
, units_cmA
, MAX_STRING_LEN
);
125 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
128 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
132 ZeroMemory(&button
, sizeof(button
));
133 button
.iBitmap
= nImage
;
134 button
.idCommand
= nCommand
;
135 button
.fsState
= TBSTATE_ENABLED
;
136 button
.fsStyle
= TBSTYLE_BUTTON
;
139 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
142 static void AddSeparator(HWND hwndToolBar
)
146 ZeroMemory(&button
, sizeof(button
));
148 button
.idCommand
= 0;
150 button
.fsStyle
= TBSTYLE_SEP
;
153 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
156 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
158 HANDLE hFile
= (HANDLE
)cookie
;
161 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
169 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
173 HANDLE hFile
= (HANDLE
)cookie
;
175 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
177 if(!ret
|| (cb
!= written
))
186 static LPWSTR
file_basename(LPWSTR path
)
188 LPWSTR pos
= path
+ lstrlenW(path
);
192 if(*pos
== '\\' || *pos
== '/')
202 static void set_caption(LPCWSTR wszNewFileName
)
204 static const WCHAR wszSeparator
[] = {' ','-',' '};
209 wszNewFileName
= wszDefaultFileName
;
211 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
213 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
214 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
219 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
220 length
+= lstrlenW(wszNewFileName
);
221 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
222 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
223 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
225 SetWindowTextW(hMainWnd
, wszCaption
);
227 HeapFree(GetProcessHeap(), 0, wszCaption
);
230 static LRESULT
registry_get_handle(HKEY
*hKey
, LPDWORD action
, LPCWSTR subKey
)
233 static const WCHAR wszProgramKey
[] = {'S','o','f','t','w','a','r','e','\\',
234 'M','i','c','r','o','s','o','f','t','\\',
235 'W','i','n','d','o','w','s','\\',
236 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
237 'A','p','p','l','e','t','s','\\',
238 'W','o','r','d','p','a','d',0};
239 LPWSTR key
= (LPWSTR
)wszProgramKey
;
243 WCHAR backslash
[] = {'\\',0};
244 key
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
245 (lstrlenW(wszProgramKey
)+lstrlenW(subKey
)+lstrlenW(backslash
)+1)
251 lstrcpyW(key
, wszProgramKey
);
252 lstrcatW(key
, backslash
);
253 lstrcatW(key
, subKey
);
258 ret
= RegCreateKeyExW(HKEY_CURRENT_USER
, key
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
259 KEY_READ
| KEY_WRITE
, NULL
, hKey
, action
);
262 ret
= RegOpenKeyExW(HKEY_CURRENT_USER
, key
, 0, KEY_READ
| KEY_WRITE
, hKey
);
266 HeapFree(GetProcessHeap(), 0, key
);
271 static void registry_set_options(void)
276 if(registry_get_handle(&hKey
, &action
, (LPWSTR
)key_options
) == ERROR_SUCCESS
)
280 GetWindowRect(hMainWnd
, &rc
);
282 RegSetValueExW(hKey
, var_framerect
, 0, REG_BINARY
, (LPBYTE
)&rc
, sizeof(RECT
));
284 registry_set_pagemargins(hKey
);
288 static RECT
registry_read_winrect(void)
292 DWORD size
= sizeof(RECT
);
294 ZeroMemory(&rc
, sizeof(RECT
));
295 if(registry_get_handle(&hKey
, 0, (LPWSTR
)key_options
) != ERROR_SUCCESS
||
296 RegQueryValueExW(hKey
, var_framerect
, 0, NULL
, (LPBYTE
)&rc
, &size
) !=
297 ERROR_SUCCESS
|| size
!= sizeof(RECT
))
309 static void truncate_path(LPWSTR file
, LPWSTR out
, LPWSTR pos1
, LPWSTR pos2
)
311 static const WCHAR dots
[] = {'.','.','.',0};
320 static void format_filelist_filename(LPWSTR file
, LPWSTR out
)
323 LPWSTR truncpos1
, truncpos2
;
324 WCHAR myDocs
[MAX_STRING_LEN
];
326 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, (LPWSTR
)&myDocs
);
327 pos_basename
= file_basename(file
);
331 *(pos_basename
-1) = 0;
332 if(!lstrcmpiW(file
, myDocs
) || (lstrlenW(pos_basename
) > FILELIST_ENTRY_LENGTH
))
334 truncpos1
= pos_basename
;
335 *(pos_basename
-1) = '\\';
339 BOOL morespace
= FALSE
;
341 *(pos_basename
-1) = '\\';
343 for(pos
= file
; pos
< pos_basename
; pos
++)
345 if(*pos
== '\\' || *pos
== '/')
349 if((pos
- file
+ lstrlenW(pos_basename
)) > FILELIST_ENTRY_LENGTH
)
357 if((pos
- file
+ lstrlenW(pos_basename
)) > FILELIST_ENTRY_LENGTH
)
366 for(pos
= pos_basename
; pos
>= truncpos1
; pos
--)
368 if(*pos
== '\\' || *pos
== '/')
370 if((truncpos1
- file
+ lstrlenW(pos_basename
) + pos_basename
- pos
) > FILELIST_ENTRY_LENGTH
)
379 if(truncpos1
== pos_basename
)
380 lstrcatW(out
, pos_basename
);
381 else if(truncpos1
== truncpos2
|| !truncpos2
)
384 truncate_path(file
, out
, truncpos1
, truncpos2
? truncpos2
: (pos_basename
-1));
387 static void registry_read_filelist(HWND hMainWnd
)
391 if(registry_get_handle(&hFileKey
, 0, key_recentfiles
) == ERROR_SUCCESS
)
393 WCHAR itemText
[MAX_PATH
+3], buffer
[MAX_PATH
];
394 /* The menu item name is not the same as the file name, so we need to store
395 the file name here */
396 static WCHAR file1
[MAX_PATH
], file2
[MAX_PATH
], file3
[MAX_PATH
], file4
[MAX_PATH
];
397 WCHAR numFormat
[] = {'&','%','d',' ',0};
398 LPWSTR pFile
[] = {file1
, file2
, file3
, file4
};
399 DWORD pathSize
= MAX_PATH
*sizeof(WCHAR
);
403 HMENU hMenu
= GetMenu(hMainWnd
);
405 mi
.cbSize
= sizeof(MENUITEMINFOW
);
406 mi
.fMask
= MIIM_ID
| MIIM_DATA
| MIIM_STRING
| MIIM_FTYPE
;
407 mi
.fType
= MFT_STRING
;
408 mi
.dwTypeData
= itemText
;
409 mi
.wID
= ID_FILE_RECENT1
;
411 RemoveMenu(hMenu
, ID_FILE_RECENT_SEPARATOR
, MF_BYCOMMAND
);
412 for(i
= 0; i
< FILELIST_ENTRIES
; i
++)
414 wsprintfW(key
, var_file
, i
+1);
415 RemoveMenu(hMenu
, ID_FILE_RECENT1
+i
, MF_BYCOMMAND
);
416 if(RegQueryValueExW(hFileKey
, (LPWSTR
)key
, 0, NULL
, (LPBYTE
)pFile
[i
], &pathSize
)
420 mi
.dwItemData
= (DWORD
)pFile
[i
];
421 wsprintfW(itemText
, numFormat
, i
+1);
423 lstrcpyW(buffer
, pFile
[i
]);
425 format_filelist_filename(buffer
, itemText
);
427 InsertMenuItemW(hMenu
, ID_FILE_EXIT
, FALSE
, &mi
);
429 pathSize
= MAX_PATH
*sizeof(WCHAR
);
431 mi
.fType
= MFT_SEPARATOR
;
432 mi
.fMask
= MIIM_FTYPE
| MIIM_ID
;
433 InsertMenuItemW(hMenu
, ID_FILE_EXIT
, FALSE
, &mi
);
435 RegCloseKey(hFileKey
);
439 static void registry_set_filelist(LPCWSTR newFile
)
444 if(registry_get_handle(&hKey
, &action
, key_recentfiles
) == ERROR_SUCCESS
)
446 LPCWSTR pFiles
[FILELIST_ENTRIES
];
448 HMENU hMenu
= GetMenu(hMainWnd
);
452 mi
.cbSize
= sizeof(MENUITEMINFOW
);
453 mi
.fMask
= MIIM_DATA
;
455 for(i
= 0; i
< FILELIST_ENTRIES
; i
++)
458 for(i
= 0; GetMenuItemInfoW(hMenu
, ID_FILE_RECENT1
+i
, FALSE
, &mi
); i
++)
459 pFiles
[i
] = (LPWSTR
)mi
.dwItemData
;
461 if(lstrcmpiW(newFile
, pFiles
[0]))
463 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
; i
++)
465 if(!lstrcmpiW(pFiles
[i
], newFile
))
468 for(j
= 0; pFiles
[j
] && j
< i
; j
++)
470 pFiles
[i
-j
] = pFiles
[i
-j
-1];
482 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
-1; i
++)
483 pFiles
[FILELIST_ENTRIES
-1-i
] = pFiles
[FILELIST_ENTRIES
-2-i
];
488 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
; i
++)
490 wsprintfW(buffer
, var_file
, i
+1);
491 RegSetValueExW(hKey
, (LPWSTR
)&buffer
, 0, REG_SZ
, (LPBYTE
)pFiles
[i
],
492 (lstrlenW(pFiles
[i
])+1)*sizeof(WCHAR
));
497 registry_read_filelist(hMainWnd
);
500 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
502 if(!endptr
|| !*endptr
)
505 while(*endptr
== ' ')
509 return *endptr
!= '\0';
511 /* FIXME: Allow other units and convert between them */
512 if(!lstrcmpA(endptr
, units_cmA
))
515 return *endptr
!= '\0';
518 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
521 char buffer
[MAX_STRING_LEN
];
522 char *endptr
= buffer
;
524 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
527 ret
= strtod(buffer
, &endptr
);
529 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| validate_endptr(endptr
, units
))
539 static void set_size(float size
)
543 ZeroMemory(&fmt
, sizeof(fmt
));
544 fmt
.cbSize
= sizeof(fmt
);
545 fmt
.dwMask
= CFM_SIZE
;
546 fmt
.yHeight
= (int)(size
* 20.0);
547 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
550 static void add_size(HWND hSizeListWnd
, unsigned size
)
553 COMBOBOXEXITEMW cbItem
;
554 cbItem
.mask
= CBEIF_TEXT
;
557 wsprintfW(buffer
, stringFormat
, size
);
558 cbItem
.pszText
= (LPWSTR
)buffer
;
559 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
562 static void populate_size_list(HWND hSizeListWnd
)
564 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
565 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
566 COMBOBOXEXITEMW cbFontItem
;
568 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
569 HDC hdc
= GetDC(hMainWnd
);
570 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
575 ZeroMemory(&fmt
, sizeof(fmt
));
576 fmt
.cbSize
= sizeof(fmt
);
577 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
579 cbFontItem
.mask
= CBEIF_LPARAM
;
580 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
581 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
583 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
585 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
587 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
589 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
590 GetDeviceCaps(hdc
, LOGPIXELSY
)));
593 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
594 add_size(hSizeListWnd
, choices
[i
]);
597 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
598 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
601 static void update_size_list(void)
603 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
604 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
605 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
606 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
609 ZeroMemory(&fmt
, sizeof(fmt
));
610 fmt
.cbSize
= sizeof(fmt
);
612 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
614 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
615 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
617 if(lstrcmpW(fontSize
, sizeBuffer
))
618 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
621 static void update_font_list(void)
623 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
624 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
625 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
626 WCHAR fontName
[MAX_STRING_LEN
];
629 ZeroMemory(&fmt
, sizeof(fmt
));
630 fmt
.cbSize
= sizeof(fmt
);
632 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
633 SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
);
635 if(lstrcmpW(fontName
, fmt
.szFaceName
))
637 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
638 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
645 static void clear_formatting(void)
649 pf
.cbSize
= sizeof(pf
);
650 pf
.dwMask
= PFM_ALIGNMENT
;
651 pf
.wAlignment
= PFA_LEFT
;
652 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
655 static int reg_formatindex(WPARAM format
)
657 return (format
& SF_TEXT
) ? 1 : 0;
660 static int fileformat_number(WPARAM format
)
664 if(format
== SF_TEXT
)
667 } else if (format
== (SF_TEXT
| SF_UNICODE
))
674 static WPARAM
fileformat_flags(int format
)
676 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
678 return flags
[format
];
681 static void set_font(LPCWSTR wszFaceName
)
683 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
684 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
685 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
686 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
689 ZeroMemory(&fmt
, sizeof(fmt
));
691 fmt
.cbSize
= sizeof(fmt
);
692 fmt
.dwMask
= CFM_FACE
;
694 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
696 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
698 populate_size_list(hSizeListWnd
);
700 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)(LPWSTR
)wszFaceName
);
703 static void set_default_font(void)
705 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
706 'R','o','m','a','n',0};
707 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
711 ZeroMemory(&fmt
, sizeof(fmt
));
713 fmt
.cbSize
= sizeof(fmt
);
714 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
717 if(fileFormat
& SF_RTF
)
720 font
= plainTextFont
;
722 lstrcpyW(fmt
.szFaceName
, font
);
724 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
727 static void add_font(LPWSTR fontName
, DWORD fontType
, HWND hListWnd
, NEWTEXTMETRICEXW
*ntmc
)
729 COMBOBOXEXITEMW cbItem
;
730 WCHAR buffer
[MAX_PATH
];
733 cbItem
.mask
= CBEIF_TEXT
;
734 cbItem
.pszText
= buffer
;
735 cbItem
.cchTextMax
= MAX_STRING_LEN
;
738 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
740 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
745 cbItem
.pszText
= fontName
;
747 cbItem
.mask
|= CBEIF_LPARAM
;
748 if(fontType
& RASTER_FONTTYPE
)
749 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
751 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
752 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
755 static void dialog_choose_font(void)
760 HDC hDC
= GetDC(hMainWnd
);
762 ZeroMemory(&cf
, sizeof(cf
));
763 cf
.lStructSize
= sizeof(cf
);
764 cf
.hwndOwner
= hMainWnd
;
766 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
768 ZeroMemory(&fmt
, sizeof(fmt
));
769 fmt
.cbSize
= sizeof(fmt
);
771 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
772 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
773 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
774 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
775 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
776 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
777 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
778 cf
.rgbColors
= fmt
.crTextColor
;
782 ZeroMemory(&fmt
, sizeof(fmt
));
783 fmt
.cbSize
= sizeof(fmt
);
784 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
785 fmt
.yHeight
= cf
.iPointSize
* 2;
787 if(cf
.nFontType
& BOLD_FONTTYPE
)
788 fmt
.dwEffects
|= CFE_BOLD
;
789 if(cf
.nFontType
& ITALIC_FONTTYPE
)
790 fmt
.dwEffects
|= CFE_ITALIC
;
791 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
792 fmt
.dwEffects
|= CFE_UNDERLINE
;
793 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
794 fmt
.dwEffects
|= CFE_STRIKEOUT
;
796 fmt
.crTextColor
= cf
.rgbColors
;
798 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
799 set_font(cf
.lpLogFont
->lfFaceName
);
804 int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
805 DWORD FontType
, LPARAM lParam
)
807 HWND hListWnd
= (HWND
) lParam
;
809 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
812 add_font((LPWSTR
)lpelfe
->lfFaceName
, FontType
, hListWnd
, (NEWTEXTMETRICEXW
*)lpntme
);
818 static void populate_font_list(HWND hListWnd
)
820 HDC hdc
= GetDC(hMainWnd
);
822 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
825 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
826 *fontinfo
.lfFaceName
= '\0';
827 fontinfo
.lfPitchAndFamily
= 0;
829 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
830 (LPARAM
)hListWnd
, 0);
832 ZeroMemory(&fmt
, sizeof(fmt
));
833 fmt
.cbSize
= sizeof(fmt
);
834 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
835 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
838 static void update_window(void)
842 GetWindowRect(hMainWnd
, &rect
);
844 (void) OnSize(hMainWnd
, SIZE_RESTORED
, MAKELONG(rect
.bottom
, rect
.right
));
847 static DWORD barState
[2];
849 static BOOL
is_bar_visible(int bandId
)
851 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
854 static void store_bar_state(int bandId
, BOOL show
)
856 int formatIndex
= reg_formatindex(fileFormat
);
859 barState
[formatIndex
] |= (1 << bandId
);
861 barState
[formatIndex
] &= ~(1 << bandId
);
864 static void set_toolbar_state(int bandId
, BOOL show
)
866 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
868 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
870 if(bandId
== BANDID_TOOLBAR
)
872 REBARBANDINFOW rbbinfo
;
873 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
875 rbbinfo
.cbSize
= sizeof(rbbinfo
);
876 rbbinfo
.fMask
= RBBIM_STYLE
;
878 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
881 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
883 rbbinfo
.fStyle
|= RBBS_BREAK
;
885 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
888 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
)
889 store_bar_state(bandId
, show
);
892 static void set_statusbar_state(BOOL show
)
894 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
896 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
897 store_bar_state(BANDID_STATUSBAR
, show
);
900 static void set_bar_states(void)
902 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
903 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
904 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
905 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
906 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
911 static void preview_exit(HWND hMainWnd
)
913 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
914 HMENU hMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_MAINMENU
));
915 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
918 ShowWindow(hEditorWnd
, TRUE
);
920 close_preview(hMainWnd
);
922 SetMenu(hMainWnd
, hMenu
);
923 registry_read_filelist(hMainWnd
);
928 static void set_fileformat(WPARAM format
)
931 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
935 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
937 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
939 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
943 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
946 static void DoOpenFile(LPCWSTR szOpenFileName
)
952 WPARAM format
= SF_TEXT
;
954 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
955 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
956 if (hFile
== INVALID_HANDLE_VALUE
)
959 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
960 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
962 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
964 format
= SF_TEXT
| SF_UNICODE
;
965 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
966 } else if(readOut
>= 5)
968 static const char header
[] = "{\\rtf";
969 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
971 if(!memcmp(header
, fileStart
, 5))
973 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
976 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
), wszAppTitle
,
977 MB_OK
| MB_ICONEXCLAMATION
);
982 es
.dwCookie
= (DWORD_PTR
)hFile
;
983 es
.pfnCallback
= stream_in
;
986 set_fileformat(format
);
987 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
991 SetFocus(hEditorWnd
);
993 set_caption(szOpenFileName
);
995 lstrcpyW(wszFileName
, szOpenFileName
);
996 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
997 registry_set_filelist(szOpenFileName
);
1001 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
1007 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1008 FILE_ATTRIBUTE_NORMAL
, NULL
);
1010 if(hFile
== INVALID_HANDLE_VALUE
)
1013 if(format
== (SF_TEXT
| SF_UNICODE
))
1015 static const BYTE unicode
[] = {0xff,0xfe};
1017 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
1019 if(writeOut
!= sizeof(unicode
))
1023 stream
.dwCookie
= (DWORD_PTR
)hFile
;
1024 stream
.pfnCallback
= stream_out
;
1026 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
1030 SetFocus(hEditorWnd
);
1035 gt
.flags
= GTL_DEFAULT
;
1038 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
1042 lstrcpyW(wszFileName
, wszSaveFileName
);
1043 set_caption(wszFileName
);
1044 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1045 set_fileformat(format
);
1048 static void DialogSaveFile(void)
1052 WCHAR wszFile
[MAX_PATH
] = {'\0'};
1053 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
1055 ZeroMemory(&sfn
, sizeof(sfn
));
1057 sfn
.lStructSize
= sizeof(sfn
);
1058 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
1059 sfn
.hwndOwner
= hMainWnd
;
1060 sfn
.lpstrFilter
= wszFilter
;
1061 sfn
.lpstrFile
= wszFile
;
1062 sfn
.nMaxFile
= MAX_PATH
;
1063 sfn
.lpstrDefExt
= wszDefExt
;
1064 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
1066 while(GetSaveFileNameW(&sfn
))
1068 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
1070 if(MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
1071 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
1076 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
1081 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
1087 static BOOL
prompt_save_changes(void)
1092 gt
.flags
= GTL_NUMCHARS
;
1094 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
1098 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
1103 LPWSTR displayFileName
;
1108 displayFileName
= wszDefaultFileName
;
1110 displayFileName
= file_basename(wszFileName
);
1112 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1113 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
1118 wsprintfW(text
, wszSaveChanges
, displayFileName
);
1120 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
1122 HeapFree(GetProcessHeap(), 0, text
);
1131 DoSaveFile(wszFileName
, fileFormat
);
1142 static void DialogOpenFile(void)
1146 WCHAR wszFile
[MAX_PATH
] = {'\0'};
1147 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
1149 ZeroMemory(&ofn
, sizeof(ofn
));
1151 ofn
.lStructSize
= sizeof(ofn
);
1152 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
1153 ofn
.hwndOwner
= hMainWnd
;
1154 ofn
.lpstrFilter
= wszFilter
;
1155 ofn
.lpstrFile
= wszFile
;
1156 ofn
.nMaxFile
= MAX_PATH
;
1157 ofn
.lpstrDefExt
= wszDefExt
;
1158 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
1160 if(GetOpenFileNameW(&ofn
))
1162 if(prompt_save_changes())
1163 DoOpenFile(ofn
.lpstrFile
);
1167 static void dialog_about(void)
1169 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1170 HICON icon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
1171 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
1174 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1180 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
1183 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1185 sprintf(id
, "%d\n", (int)ps
->lParam
);
1186 SetWindowTextA(hIdWnd
, id
);
1187 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
1188 wrap
= IDC_PAGEFMT_WW
;
1189 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
1190 wrap
= IDC_PAGEFMT_WM
;
1193 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
,
1194 IDC_PAGEFMT_WM
, wrap
);
1196 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
1197 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
1198 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
1199 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
1200 if(barState
[ps
->lParam
] & (BANDID_STATUSBAR
))
1201 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1206 switch(LOWORD(wParam
))
1208 case IDC_PAGEFMT_WW
:
1209 case IDC_PAGEFMT_WM
:
1210 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
, IDC_PAGEFMT_WM
,
1214 case IDC_PAGEFMT_TB
:
1215 case IDC_PAGEFMT_FB
:
1216 case IDC_PAGEFMT_SB
:
1217 CheckDlgButton(hWnd
, LOWORD(wParam
),
1218 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1224 LPNMHDR header
= (LPNMHDR
)lParam
;
1225 if(header
->code
== PSN_APPLY
)
1227 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1231 GetWindowTextA(hIdWnd
, sid
, 4);
1233 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1234 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1235 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1236 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1238 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1239 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1241 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1243 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1244 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1246 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1248 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1249 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1251 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1259 static void dialog_viewproperties(void)
1261 PROPSHEETPAGEW psp
[2];
1262 PROPSHEETHEADERW psh
;
1264 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1265 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1267 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1268 psp
[0].dwFlags
= PSP_USETITLE
;
1269 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1270 psp
[0].pfnDlgProc
= formatopts_proc
;
1271 psp
[0].hInstance
= hInstance
;
1272 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1273 psp
[0].pfnCallback
= NULL
;
1274 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1275 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1277 psp
[i
].dwSize
= psp
[0].dwSize
;
1278 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1279 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1280 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1281 psp
[i
].hInstance
= psp
[0].hInstance
;
1282 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1283 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1284 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1287 psh
.dwSize
= sizeof(psh
);
1288 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1289 psh
.hwndParent
= hMainWnd
;
1290 psh
.hInstance
= hInstance
;
1291 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1292 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1293 U3(psh
).ppsp
= ppsp
;
1294 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1296 if(fileFormat
& SF_RTF
)
1297 U2(psh
).nStartPage
= 1;
1299 U2(psh
).nStartPage
= 0;
1300 PropertySheetW(&psh
);
1302 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1305 static void HandleCommandLine(LPWSTR cmdline
)
1310 /* skip white space */
1311 while (*cmdline
== ' ') cmdline
++;
1313 /* skip executable name */
1314 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1316 if (*cmdline
== delimiter
) cmdline
++;
1317 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1318 if (*cmdline
== delimiter
) cmdline
++;
1320 while (*cmdline
== ' ' || *cmdline
== '-' || *cmdline
== '/')
1324 if (*cmdline
++ == ' ') continue;
1327 if (option
) cmdline
++;
1328 while (*cmdline
== ' ') cmdline
++;
1341 /* file name is passed on the command line */
1342 if (cmdline
[0] == '"')
1345 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1347 DoOpenFile(cmdline
);
1348 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1352 MessageBox(hMainWnd
, "Printing not implemented", "WordPad", MB_OK
);
1355 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1357 if(pFr
->Flags
& FR_DIALOGTERM
)
1360 pFr
->Flags
= FR_FINDNEXT
;
1364 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1366 DWORD flags
= FR_DOWN
;
1368 static CHARRANGE cr
;
1373 HMENU hMenu
= GetMenu(hMainWnd
);
1376 mi
.cbSize
= sizeof(mi
);
1377 mi
.fMask
= MIIM_DATA
;
1379 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1381 gt
.flags
= GTL_NUMCHARS
;
1384 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1386 if(pFr
->lCustData
== -1)
1388 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1389 cr
.cpMin
= startPos
;
1390 pFr
->lCustData
= startPos
;
1392 if(cr
.cpMin
== length
)
1396 startPos
= pFr
->lCustData
;
1399 if(cr
.cpMax
> length
)
1407 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1409 if(pFr
->Flags
& FR_MATCHCASE
)
1410 flags
|= FR_MATCHCASE
;
1411 if(pFr
->Flags
& FR_WHOLEWORD
)
1412 flags
|= FR_WHOLEWORD
;
1414 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1418 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1420 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1421 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1423 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1429 pFr
->lCustData
= -1;
1430 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1431 MB_OK
| MB_ICONASTERISK
);
1434 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1436 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1437 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1439 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1440 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1442 if(pFr
->Flags
& FR_REPLACEALL
)
1443 handle_findmsg(pFr
);
1450 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1452 static WCHAR findBuffer
[MAX_STRING_LEN
];
1454 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1455 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1456 fr
->hwndOwner
= hMainWnd
;
1457 fr
->Flags
= FR_HIDEUPDOWN
;
1458 fr
->lpstrFindWhat
= findBuffer
;
1460 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1463 hFindWnd
= ReplaceTextW(fr
);
1465 hFindWnd
= FindTextW(fr
);
1468 static void registry_read_options(void)
1472 if(registry_get_handle(&hKey
, 0, key_options
) != ERROR_SUCCESS
)
1473 registry_read_pagemargins(NULL
);
1475 registry_read_pagemargins(hKey
);
1480 static void registry_read_formatopts(int index
, LPCWSTR key
)
1484 BOOL fetched
= FALSE
;
1485 barState
[index
] = 0;
1486 wordWrap
[index
] = 0;
1488 if(registry_get_handle(&hKey
, &action
, key
) != ERROR_SUCCESS
)
1491 if(action
== REG_OPENED_EXISTING_KEY
)
1493 DWORD size
= sizeof(DWORD
);
1495 if(RegQueryValueExW(hKey
, var_barstate0
, 0, NULL
, (LPBYTE
)&barState
[index
],
1496 &size
) == ERROR_SUCCESS
)
1501 barState
[index
] = (1 << BANDID_TOOLBAR
) | (1 << BANDID_FORMATBAR
) | (1 << BANDID_RULER
) | (1 << BANDID_STATUSBAR
);
1503 if(index
== reg_formatindex(SF_RTF
))
1504 wordWrap
[index
] = ID_WORDWRAP_WINDOW
;
1505 else if(index
== reg_formatindex(SF_TEXT
))
1506 wordWrap
[index
] = ID_WORDWRAP_WINDOW
; /* FIXME: should be ID_WORDWRAP_NONE once we support it */
1511 static void registry_read_formatopts_all(void)
1513 registry_read_formatopts(reg_formatindex(SF_RTF
), key_rtf
);
1514 registry_read_formatopts(reg_formatindex(SF_TEXT
), key_text
);
1517 static void registry_set_formatopts(int index
, LPCWSTR key
)
1522 if(registry_get_handle(&hKey
, &action
, key
) == ERROR_SUCCESS
)
1524 RegSetValueExW(hKey
, var_barstate0
, 0, REG_DWORD
, (LPBYTE
)&barState
[index
],
1531 static void registry_set_formatopts_all(void)
1533 registry_set_formatopts(reg_formatindex(SF_RTF
), key_rtf
);
1534 registry_set_formatopts(reg_formatindex(SF_TEXT
), key_text
);
1537 static int current_units_to_twips(float number
)
1539 int twips
= (int)(number
* 567);
1543 static void append_current_units(LPWSTR buffer
)
1545 static const WCHAR space
[] = {' '};
1546 lstrcatW(buffer
, space
);
1547 lstrcatW(buffer
, units_cmW
);
1550 static void number_with_units(LPWSTR buffer
, int number
)
1552 float converted
= (float)number
/ 567;
1553 char string
[MAX_STRING_LEN
];
1555 sprintf(string
, "%.2f ", converted
);
1556 lstrcatA(string
, units_cmA
);
1557 MultiByteToWideChar(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
);
1560 BOOL CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1566 WCHAR buffer
[MAX_STRING_LEN
];
1568 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1571 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1573 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1574 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1576 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1577 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1578 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1580 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1585 switch(LOWORD(wParam
))
1590 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1592 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1596 WCHAR buffer
[MAX_STRING_LEN
];
1597 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1598 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1604 EndDialog(hWnd
, wParam
);
1611 BOOL CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1617 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1618 WCHAR buffer
[MAX_STRING_LEN
];
1619 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1621 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1622 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1623 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1624 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1625 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1626 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1628 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1633 switch(LOWORD(wParam
))
1638 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1639 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1642 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1647 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1654 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1660 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
1662 WCHAR buffer
[MAX_STRING_LEN
];
1663 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1664 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1665 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1666 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1670 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1672 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1673 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1675 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1676 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1678 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1680 pf
.cbSize
= sizeof(pf
);
1681 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1683 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1685 if(pf
.wAlignment
== PFA_RIGHT
)
1687 else if(pf
.wAlignment
== PFA_CENTER
)
1690 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1692 number_with_units(buffer
, pf
.dxOffset
);
1693 SetWindowTextW(hLeftWnd
, buffer
);
1694 number_with_units(buffer
, pf
.dxRightIndent
);
1695 SetWindowTextW(hRightWnd
, buffer
);
1696 number_with_units(buffer
, pf
.dxStartIndent
- pf
.dxOffset
);
1697 SetWindowTextW(hFirstWnd
, buffer
);
1702 switch(LOWORD(wParam
))
1706 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1707 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1708 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1709 WCHAR buffer
[MAX_STRING_LEN
];
1714 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1715 if(number_from_string(buffer
, &num
, TRUE
))
1717 pf
.dxOffset
= current_units_to_twips(num
);
1718 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1719 if(number_from_string(buffer
, &num
, TRUE
))
1721 pf
.dxRightIndent
= current_units_to_twips(num
);
1722 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1723 if(number_from_string(buffer
, &num
, TRUE
))
1725 pf
.dxStartIndent
= current_units_to_twips(num
);
1729 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1730 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1734 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1735 pf
.cbSize
= sizeof(pf
);
1736 pf
.dwMask
= PFM_OFFSET
| PFM_OFFSETINDENT
| PFM_RIGHTINDENT
;
1737 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1743 EndDialog(hWnd
, wParam
);
1750 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1756 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1758 WCHAR buffer
[MAX_STRING_LEN
];
1761 pf
.cbSize
= sizeof(pf
);
1762 pf
.dwMask
= PFM_TABSTOPS
;
1763 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1764 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1766 for(i
= 0; i
< pf
.cTabCount
; i
++)
1768 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1769 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1776 switch(LOWORD(wParam
))
1780 HWND hTabWnd
= (HWND
)lParam
;
1781 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1782 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1783 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1785 if(GetWindowTextLengthW(hTabWnd
))
1786 EnableWindow(hAddWnd
, TRUE
);
1788 EnableWindow(hAddWnd
, FALSE
);
1790 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1792 EnableWindow(hEmptyWnd
, TRUE
);
1794 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1795 EnableWindow(hDelWnd
, FALSE
);
1797 EnableWindow(hDelWnd
, TRUE
);
1800 EnableWindow(hEmptyWnd
, FALSE
);
1807 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1808 WCHAR buffer
[MAX_STRING_LEN
];
1810 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1811 append_current_units(buffer
);
1813 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1817 if(!number_from_string(buffer
, &number
, TRUE
))
1819 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1820 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1823 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1824 SetWindowTextW(hTabWnd
, 0);
1833 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1835 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1837 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1843 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1844 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1851 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1853 WCHAR buffer
[MAX_STRING_LEN
];
1857 pf
.cbSize
= sizeof(pf
);
1858 pf
.dwMask
= PFM_TABSTOPS
;
1860 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1861 (LPARAM
)&buffer
) != CB_ERR
&&
1862 i
< MAX_TAB_STOPS
; i
++)
1864 number_from_string(buffer
, &number
, TRUE
);
1865 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
1868 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1872 EndDialog(hWnd
, wParam
);
1879 static int context_menu(LPARAM lParam
)
1881 int x
= (int)(short)LOWORD(lParam
);
1882 int y
= (int)(short)HIWORD(lParam
);
1883 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1887 int from
= 0, to
= 0;
1889 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1890 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
1891 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1896 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1897 x
, y
, 0, hMainWnd
, 0);
1902 static LRESULT
OnCreate( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1904 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
;
1905 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1908 int nStdBitmaps
= 0;
1911 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1912 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1914 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1916 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1917 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1918 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1920 rbi
.cbSize
= sizeof(rbi
);
1923 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1926 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1928 1, hInstance
, IDB_TOOLBAR
,
1930 24, 24, 16, 16, sizeof(TBBUTTON
));
1932 ab
.hInst
= HINST_COMMCTRL
;
1933 ab
.nID
= IDB_STD_SMALL_COLOR
;
1934 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1936 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1937 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1938 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1939 AddSeparator(hToolBarWnd
);
1940 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1941 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1942 AddSeparator(hToolBarWnd
);
1943 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1944 AddSeparator(hToolBarWnd
);
1945 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1946 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1947 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1948 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1949 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1950 AddSeparator(hToolBarWnd
);
1951 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1953 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1955 rbb
.cbSize
= sizeof(rbb
);
1956 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1957 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1959 rbb
.hwndChild
= hToolBarWnd
;
1961 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1962 rbb
.wID
= BANDID_TOOLBAR
;
1964 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1966 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1967 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1968 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1970 rbb
.hwndChild
= hFontListWnd
;
1972 rbb
.wID
= BANDID_FONTLIST
;
1974 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1976 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1977 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1978 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1980 rbb
.hwndChild
= hSizeListWnd
;
1982 rbb
.fStyle
^= RBBS_BREAK
;
1983 rbb
.wID
= BANDID_SIZELIST
;
1985 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1987 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1988 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1989 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1991 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1992 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1993 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1994 AddSeparator(hFormatBarWnd
);
1995 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
1996 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
1997 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
1998 AddSeparator(hFormatBarWnd
);
1999 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
2001 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
2003 rbb
.hwndChild
= hFormatBarWnd
;
2004 rbb
.wID
= BANDID_FORMATBAR
;
2006 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
2008 hDLL
= LoadLibraryW(wszRichEditDll
);
2011 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
2012 MB_OK
| MB_ICONEXCLAMATION
);
2016 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
2017 WS_CHILD
|WS_VISIBLE
|ECO_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
|ES_WANTRETURN
|WS_VSCROLL
,
2018 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
2022 fprintf(stderr
, "Error code %u\n", GetLastError());
2027 SetFocus(hEditorWnd
);
2028 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
2032 populate_font_list(hFontListWnd
);
2033 populate_size_list(hSizeListWnd
);
2035 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2037 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
2039 registry_read_filelist(hWnd
);
2040 registry_read_formatopts_all();
2041 registry_read_options();
2042 DragAcceptFiles(hWnd
, TRUE
);
2047 static LRESULT
OnUser( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2049 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2050 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2051 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
2052 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
2058 ZeroMemory(&fmt
, sizeof(fmt
));
2059 fmt
.cbSize
= sizeof(fmt
);
2061 ZeroMemory(&pf
, sizeof(pf
));
2062 pf
.cbSize
= sizeof(pf
);
2064 gt
.flags
= GTL_NUMCHARS
;
2067 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
2068 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
2070 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
2072 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
2073 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
2074 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
2075 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
2076 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
2077 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
2078 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
2080 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
2081 (fmt
.dwEffects
& CFE_BOLD
));
2082 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
2083 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
2084 (fmt
.dwEffects
& CFE_ITALIC
));
2085 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
2086 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
2087 (fmt
.dwEffects
& CFE_UNDERLINE
));
2088 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
2090 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2091 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
2092 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
2093 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
2095 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
2099 static LRESULT
OnNotify( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2101 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2102 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2103 NMHDR
*pHdr
= (NMHDR
*)lParam
;
2104 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
2105 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
2106 WCHAR sizeBuffer
[MAX_PATH
];
2108 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
2110 if (pHdr
->code
== CBEN_ENDEDITW
)
2112 CHARFORMAT2W format
;
2113 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
2115 ZeroMemory(&format
, sizeof(format
));
2116 format
.cbSize
= sizeof(format
);
2117 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
2119 if(pHdr
->hwndFrom
== hwndFontList
)
2121 if(lstrcmpW(format
.szFaceName
, (LPWSTR
)endEdit
->szText
))
2122 set_font((LPCWSTR
) endEdit
->szText
);
2123 } else if (pHdr
->hwndFrom
== hwndSizeList
)
2125 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
2126 if(lstrcmpW(sizeBuffer
, (LPWSTR
)endEdit
->szText
))
2129 if(number_from_string((LPWSTR
)endEdit
->szText
, &size
, FALSE
))
2134 SetWindowTextW(hwndSizeList
, sizeBuffer
);
2135 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
), wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
2143 if (pHdr
->hwndFrom
!= hwndEditor
)
2146 if (pHdr
->code
== EN_SELCHANGE
)
2148 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
2153 sprintf( buf
,"selection = %d..%d, line count=%ld",
2154 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
2155 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
2156 SetWindowText(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
2157 SendMessage(hWnd
, WM_USER
, 0, 0);
2163 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2165 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2166 static FINDREPLACEW findreplace
;
2168 if ((HWND
)lParam
== hwndEditor
)
2171 switch(LOWORD(wParam
))
2175 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
2180 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2181 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
2182 (DLGPROC
)newfile_proc
);
2184 if(ret
!= ID_NEWFILE_ABORT
)
2186 if(prompt_save_changes())
2191 wszFileName
[0] = '\0';
2195 st
.flags
= ST_DEFAULT
;
2197 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
2199 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2200 set_fileformat(ret
);
2214 DoSaveFile(wszFileName
, fileFormat
);
2219 case ID_FILE_SAVEAS
:
2223 case ID_FILE_RECENT1
:
2224 case ID_FILE_RECENT2
:
2225 case ID_FILE_RECENT3
:
2226 case ID_FILE_RECENT4
:
2228 HMENU hMenu
= GetMenu(hWnd
);
2231 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2232 mi
.fMask
= MIIM_DATA
;
2233 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2234 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2239 dialog_find(&findreplace
, FALSE
);
2243 handle_findmsg(&findreplace
);
2247 dialog_find(&findreplace
, TRUE
);
2250 case ID_FONTSETTINGS
:
2251 dialog_choose_font();
2255 dialog_print(hWnd
, wszFileName
);
2256 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2259 case ID_PRINT_QUICK
:
2260 print_quick(wszFileName
);
2261 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2266 int index
= reg_formatindex(fileFormat
);
2267 DWORD tmp
= barState
[index
];
2268 barState
[index
] = 0;
2270 barState
[index
] = tmp
;
2271 ShowWindow(hEditorWnd
, FALSE
);
2273 init_preview(hWnd
, wszFileName
);
2275 SetMenu(hWnd
, NULL
);
2276 InvalidateRect(0, 0, TRUE
);
2281 dialog_printsetup(hWnd
);
2282 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2285 case ID_FORMAT_BOLD
:
2286 case ID_FORMAT_ITALIC
:
2287 case ID_FORMAT_UNDERLINE
:
2290 int effects
= CFE_BOLD
;
2292 ZeroMemory(&fmt
, sizeof(fmt
));
2293 fmt
.cbSize
= sizeof(fmt
);
2294 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2296 fmt
.dwMask
= CFM_BOLD
;
2298 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2300 effects
= CFE_ITALIC
;
2301 fmt
.dwMask
= CFM_ITALIC
;
2302 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2304 effects
= CFE_UNDERLINE
;
2305 fmt
.dwMask
= CFM_UNDERLINE
;
2308 fmt
.dwEffects
^= effects
;
2310 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2315 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2319 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2323 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2327 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2330 case ID_EDIT_SELECTALL
:
2332 CHARRANGE range
= {0, -1};
2333 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2334 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2338 case ID_EDIT_GETTEXT
:
2340 int nLen
= GetWindowTextLengthW(hwndEditor
);
2341 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2344 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2345 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
2347 HeapFree( GetProcessHeap(), 0, data
);
2348 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2350 tr
.chrg
.cpMax
= nLen
;
2351 tr
.lpstrText
= data
;
2352 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2353 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
2354 HeapFree( GetProcessHeap(), 0, data
);
2356 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2360 case ID_EDIT_CHARFORMAT
:
2361 case ID_EDIT_DEFCHARFORMAT
:
2365 ZeroMemory(&cf
, sizeof(cf
));
2366 cf
.cbSize
= sizeof(cf
);
2368 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2369 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2373 case ID_EDIT_PARAFORMAT
:
2376 ZeroMemory(&pf
, sizeof(pf
));
2377 pf
.cbSize
= sizeof(pf
);
2378 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2382 case ID_EDIT_SELECTIONINFO
:
2384 CHARRANGE range
= {0, -1};
2388 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2389 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2390 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2391 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2392 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2393 MessageBoxW(hWnd
, data
, xszAppTitle
, MB_OK
);
2394 HeapFree( GetProcessHeap(), 0, data
);
2395 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2399 case ID_EDIT_READONLY
:
2401 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2402 if (nStyle
& ES_READONLY
)
2403 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2405 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2409 case ID_EDIT_MODIFIED
:
2410 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2411 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2413 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2417 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2421 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2428 pf
.cbSize
= sizeof(pf
);
2429 pf
.dwMask
= PFM_NUMBERING
;
2430 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2432 pf
.dwMask
|= PFM_OFFSET
;
2434 if(pf
.wNumbering
== PFN_BULLET
)
2440 pf
.wNumbering
= PFN_BULLET
;
2444 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2449 case ID_ALIGN_CENTER
:
2450 case ID_ALIGN_RIGHT
:
2454 pf
.cbSize
= sizeof(pf
);
2455 pf
.dwMask
= PFM_ALIGNMENT
;
2456 switch(LOWORD(wParam
)) {
2457 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2458 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2459 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2461 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2466 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2470 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2473 case ID_TOGGLE_TOOLBAR
:
2474 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2478 case ID_TOGGLE_FORMATBAR
:
2479 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2480 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2481 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2485 case ID_TOGGLE_STATUSBAR
:
2486 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2492 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2493 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, (DLGPROC
)datetime_proc
);
2499 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2500 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
2507 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2508 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2516 case ID_VIEWPROPERTIES
:
2517 dialog_viewproperties();
2521 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2527 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2529 HMENU hMenu
= (HMENU
)wParam
;
2530 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2531 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2533 int nAlignment
= -1;
2539 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2540 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2541 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2543 pf
.cbSize
= sizeof(PARAFORMAT
);
2544 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2545 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2546 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2547 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2548 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2549 if (pf
.dwMask
& PFM_ALIGNMENT
)
2550 nAlignment
= pf
.wAlignment
;
2551 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2552 MF_CHECKED
: MF_UNCHECKED
);
2553 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2554 MF_CHECKED
: MF_UNCHECKED
);
2555 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2556 MF_CHECKED
: MF_UNCHECKED
);
2557 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2558 MF_CHECKED
: MF_UNCHECKED
));
2559 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2560 MF_ENABLED
: MF_GRAYED
);
2561 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2562 MF_ENABLED
: MF_GRAYED
);
2564 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2565 MF_CHECKED
: MF_UNCHECKED
);
2567 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2568 MF_CHECKED
: MF_UNCHECKED
);
2570 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2571 MF_CHECKED
: MF_UNCHECKED
);
2573 gt
.flags
= GTL_NUMCHARS
;
2575 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2576 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2578 mi
.cbSize
= sizeof(mi
);
2579 mi
.fMask
= MIIM_DATA
;
2581 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2583 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2584 MF_ENABLED
: MF_GRAYED
));
2586 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2591 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2593 int nStatusSize
= 0;
2595 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2596 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2597 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2598 int rebarHeight
= 0;
2603 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2604 if (IsWindowVisible(hwndStatusBar
))
2606 GetClientRect(hwndStatusBar
, &rc
);
2607 nStatusSize
= rc
.bottom
- rc
.top
;
2615 if(!is_bar_visible(BANDID_TOOLBAR
))
2618 if(!is_bar_visible(BANDID_FORMATBAR
))
2621 rebarHeight
= rebarRows
? SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0) : 0;
2623 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2627 GetClientRect(hWnd
, &rc
);
2628 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2631 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2634 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2636 if(msg
== ID_FINDMSGSTRING
)
2637 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2642 return OnCreate( hWnd
, wParam
, lParam
);
2645 return OnUser( hWnd
, wParam
, lParam
);
2648 return OnNotify( hWnd
, wParam
, lParam
);
2651 if(preview_isactive())
2653 return preview_command( hWnd
, wParam
, lParam
);
2656 return OnCommand( hWnd
, wParam
, lParam
);
2663 if(preview_isactive())
2666 } else if(prompt_save_changes())
2668 registry_set_options();
2669 registry_set_formatopts_all();
2676 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2679 case WM_INITMENUPOPUP
:
2680 return OnInitPopupMenu( hWnd
, wParam
, lParam
);
2683 return OnSize( hWnd
, wParam
, lParam
);
2685 case WM_CONTEXTMENU
:
2686 if((HWND
)wParam
== hEditorWnd
)
2687 return context_menu(lParam
);
2689 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2693 WCHAR file
[MAX_PATH
];
2694 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2695 DragFinish((HDROP
)wParam
);
2697 if(prompt_save_changes())
2702 if(preview_isactive())
2703 return print_preview(hWnd
);
2705 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2708 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2714 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int res
)
2716 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2721 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2722 'T','A','B','L','E','\0'};
2724 InitCommonControlsEx(&classes
);
2726 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2728 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2729 wc
.lpfnWndProc
= WndProc
;
2732 wc
.hInstance
= hInstance
;
2733 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2734 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2735 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2736 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2737 wc
.lpszClassName
= wszMainWndClass
;
2738 RegisterClassW(&wc
);
2740 rc
= registry_read_winrect();
2741 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2742 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2743 ShowWindow(hMainWnd
, SW_SHOWDEFAULT
);
2747 set_fileformat(SF_RTF
);
2748 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2749 get_default_printer_opts();
2750 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2752 HandleCommandLine(GetCommandLineW());
2754 while(GetMessageW(&msg
,0,0,0))
2756 if (IsDialogMessage(hFindWnd
, &msg
))
2759 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2761 TranslateMessage(&msg
);
2762 DispatchMessageW(&msg
);
2763 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2764 SendMessageW(hMainWnd
, WM_USER
, 0, 0);