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
41 #ifdef NONAMELESSUNION
52 static const WCHAR wszAppTitle
[] = {'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};
57 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
60 static HWND hEditorWnd
;
62 static HMENU hPopupMenu
;
64 static UINT ID_FINDMSGSTRING
;
66 static DWORD wordWrap
[2];
67 static DWORD barState
[2];
68 static WPARAM fileFormat
= SF_RTF
;
70 static WCHAR wszFileName
[MAX_PATH
];
71 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
72 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
73 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
74 static WCHAR units_cmW
[MAX_STRING_LEN
];
76 static char units_cmA
[MAX_STRING_LEN
];
78 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
80 /* Load string resources */
81 static void DoLoadStrings(void)
84 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
85 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
86 static const WCHAR files_all
[] = {'*','.','*','\0'};
88 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
90 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
92 lstrcpyW(p
, files_rtf
);
94 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
96 lstrcpyW(p
, files_txt
);
98 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
100 lstrcpyW(p
, files_txt
);
101 p
+= lstrlenW(p
) + 1;
102 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
103 p
+= lstrlenW(p
) + 1;
104 lstrcpyW(p
, files_all
);
105 p
+= lstrlenW(p
) + 1;
108 p
= wszDefaultFileName
;
109 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
112 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
114 LoadStringA(hInstance
, STRING_UNITS_CM
, units_cmA
, MAX_STRING_LEN
);
115 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
118 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
122 ZeroMemory(&button
, sizeof(button
));
123 button
.iBitmap
= nImage
;
124 button
.idCommand
= nCommand
;
125 button
.fsState
= TBSTATE_ENABLED
;
126 button
.fsStyle
= TBSTYLE_BUTTON
;
129 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
132 static void AddSeparator(HWND hwndToolBar
)
136 ZeroMemory(&button
, sizeof(button
));
138 button
.idCommand
= 0;
140 button
.fsStyle
= TBSTYLE_SEP
;
143 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
146 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
148 HANDLE hFile
= (HANDLE
)cookie
;
151 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
159 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
163 HANDLE hFile
= (HANDLE
)cookie
;
165 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
167 if(!ret
|| (cb
!= written
))
175 LPWSTR
file_basename(LPWSTR path
)
177 LPWSTR pos
= path
+ lstrlenW(path
);
181 if(*pos
== '\\' || *pos
== '/')
191 static void set_caption(LPCWSTR wszNewFileName
)
193 static const WCHAR wszSeparator
[] = {' ','-',' '};
198 wszNewFileName
= wszDefaultFileName
;
200 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
202 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
203 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
208 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
209 length
+= lstrlenW(wszNewFileName
);
210 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
211 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
212 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
214 SetWindowTextW(hMainWnd
, wszCaption
);
216 HeapFree(GetProcessHeap(), 0, wszCaption
);
219 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
226 while(*endptr
== ' ')
230 return *endptr
== '\0';
232 /* FIXME: Allow other units and convert between them */
233 if(!lstrcmpA(endptr
, units_cmA
))
236 return *endptr
== '\0';
239 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
242 char buffer
[MAX_STRING_LEN
];
243 char *endptr
= buffer
;
245 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
248 ret
= strtod(buffer
, &endptr
);
250 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| !validate_endptr(endptr
, units
))
260 static void set_size(float size
)
264 ZeroMemory(&fmt
, sizeof(fmt
));
265 fmt
.cbSize
= sizeof(fmt
);
266 fmt
.dwMask
= CFM_SIZE
;
267 fmt
.yHeight
= (int)(size
* 20.0);
268 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
271 static void on_sizelist_modified(HWND hwndSizeList
, LPWSTR wszNewFontSize
)
273 WCHAR sizeBuffer
[MAX_STRING_LEN
];
276 ZeroMemory(&format
, sizeof(format
));
277 format
.cbSize
= sizeof(format
);
278 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
280 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
281 if(lstrcmpW(sizeBuffer
, wszNewFontSize
))
284 if(number_from_string((LPCWSTR
) wszNewFontSize
, &size
, FALSE
)
290 SetWindowTextW(hwndSizeList
, sizeBuffer
);
291 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
292 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
297 static void add_size(HWND hSizeListWnd
, unsigned size
)
300 COMBOBOXEXITEMW cbItem
;
301 cbItem
.mask
= CBEIF_TEXT
;
304 wsprintfW(buffer
, stringFormat
, size
);
305 cbItem
.pszText
= (LPWSTR
)buffer
;
306 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
309 static void populate_size_list(HWND hSizeListWnd
)
311 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
312 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
313 COMBOBOXEXITEMW cbFontItem
;
315 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
316 HDC hdc
= GetDC(hMainWnd
);
317 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
322 ZeroMemory(&fmt
, sizeof(fmt
));
323 fmt
.cbSize
= sizeof(fmt
);
324 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
326 cbFontItem
.mask
= CBEIF_LPARAM
;
327 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
328 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
330 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
332 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
334 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
336 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
337 GetDeviceCaps(hdc
, LOGPIXELSY
)));
340 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
341 add_size(hSizeListWnd
, choices
[i
]);
344 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
345 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
348 static void update_size_list(void)
350 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
351 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
352 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
353 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
356 ZeroMemory(&fmt
, sizeof(fmt
));
357 fmt
.cbSize
= sizeof(fmt
);
359 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
361 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
362 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
364 if(lstrcmpW(fontSize
, sizeBuffer
))
365 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
368 static void update_font_list(void)
370 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
371 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
372 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
373 WCHAR fontName
[MAX_STRING_LEN
];
376 ZeroMemory(&fmt
, sizeof(fmt
));
377 fmt
.cbSize
= sizeof(fmt
);
379 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
380 if (!SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
)) return;
382 if(lstrcmpW(fontName
, fmt
.szFaceName
))
384 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
385 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
392 static void clear_formatting(void)
396 pf
.cbSize
= sizeof(pf
);
397 pf
.dwMask
= PFM_ALIGNMENT
;
398 pf
.wAlignment
= PFA_LEFT
;
399 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
402 static int fileformat_number(WPARAM format
)
406 if(format
== SF_TEXT
)
409 } else if (format
== (SF_TEXT
| SF_UNICODE
))
416 static WPARAM
fileformat_flags(int format
)
418 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
420 return flags
[format
];
423 static void set_font(LPCWSTR wszFaceName
)
425 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
426 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
427 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
428 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
431 ZeroMemory(&fmt
, sizeof(fmt
));
433 fmt
.cbSize
= sizeof(fmt
);
434 fmt
.dwMask
= CFM_FACE
;
436 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
438 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
440 populate_size_list(hSizeListWnd
);
442 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)(LPWSTR
)wszFaceName
);
445 static void set_default_font(void)
447 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
448 'R','o','m','a','n',0};
449 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
453 ZeroMemory(&fmt
, sizeof(fmt
));
455 fmt
.cbSize
= sizeof(fmt
);
456 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
459 if(fileFormat
& SF_RTF
)
462 font
= plainTextFont
;
464 lstrcpyW(fmt
.szFaceName
, font
);
466 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
469 static void on_fontlist_modified(LPWSTR wszNewFaceName
)
472 ZeroMemory(&format
, sizeof(format
));
473 format
.cbSize
= sizeof(format
);
474 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
476 if(lstrcmpW(format
.szFaceName
, wszNewFaceName
))
477 set_font((LPCWSTR
) wszNewFaceName
);
480 static void add_font(LPCWSTR fontName
, DWORD fontType
, HWND hListWnd
, NEWTEXTMETRICEXW
*ntmc
)
482 COMBOBOXEXITEMW cbItem
;
483 WCHAR buffer
[MAX_PATH
];
486 cbItem
.mask
= CBEIF_TEXT
;
487 cbItem
.pszText
= buffer
;
488 cbItem
.cchTextMax
= MAX_STRING_LEN
;
491 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
493 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
498 cbItem
.pszText
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName
) + 1)*sizeof(WCHAR
) );
499 lstrcpyW( cbItem
.pszText
, fontName
);
501 cbItem
.mask
|= CBEIF_LPARAM
;
502 if(fontType
& RASTER_FONTTYPE
)
503 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
505 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
506 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
507 HeapFree( GetProcessHeap(), 0, cbItem
.pszText
);
510 static void dialog_choose_font(void)
515 HDC hDC
= GetDC(hMainWnd
);
517 ZeroMemory(&cf
, sizeof(cf
));
518 cf
.lStructSize
= sizeof(cf
);
519 cf
.hwndOwner
= hMainWnd
;
521 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
523 ZeroMemory(&fmt
, sizeof(fmt
));
524 fmt
.cbSize
= sizeof(fmt
);
526 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
527 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
528 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
529 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
530 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
531 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
532 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
533 cf
.rgbColors
= fmt
.crTextColor
;
537 ZeroMemory(&fmt
, sizeof(fmt
));
538 fmt
.cbSize
= sizeof(fmt
);
539 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
540 fmt
.yHeight
= cf
.iPointSize
* 2;
542 if(cf
.nFontType
& BOLD_FONTTYPE
)
543 fmt
.dwEffects
|= CFE_BOLD
;
544 if(cf
.nFontType
& ITALIC_FONTTYPE
)
545 fmt
.dwEffects
|= CFE_ITALIC
;
546 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
547 fmt
.dwEffects
|= CFE_UNDERLINE
;
548 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
549 fmt
.dwEffects
|= CFE_STRIKEOUT
;
551 fmt
.crTextColor
= cf
.rgbColors
;
553 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
554 set_font(cf
.lpLogFont
->lfFaceName
);
559 int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
560 DWORD FontType
, LPARAM lParam
)
562 HWND hListWnd
= (HWND
) lParam
;
564 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
567 add_font((LPWSTR
)lpelfe
->lfFaceName
, FontType
, hListWnd
, (NEWTEXTMETRICEXW
*)lpntme
);
573 static void populate_font_list(HWND hListWnd
)
575 HDC hdc
= GetDC(hMainWnd
);
577 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
580 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
581 *fontinfo
.lfFaceName
= '\0';
582 fontinfo
.lfPitchAndFamily
= 0;
584 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
585 (LPARAM
)hListWnd
, 0);
587 ZeroMemory(&fmt
, sizeof(fmt
));
588 fmt
.cbSize
= sizeof(fmt
);
589 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
590 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
593 static void update_window(void)
597 GetClientRect(hMainWnd
, &rect
);
599 OnSize(hMainWnd
, SIZE_RESTORED
, MAKELPARAM(rect
.right
, rect
.bottom
));
602 static BOOL
is_bar_visible(int bandId
)
604 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
607 static void store_bar_state(int bandId
, BOOL show
)
609 int formatIndex
= reg_formatindex(fileFormat
);
612 barState
[formatIndex
] |= (1 << bandId
);
614 barState
[formatIndex
] &= ~(1 << bandId
);
617 static void set_toolbar_state(int bandId
, BOOL show
)
619 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
621 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
623 if(bandId
== BANDID_TOOLBAR
)
625 REBARBANDINFOW rbbinfo
;
626 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
628 rbbinfo
.cbSize
= sizeof(rbbinfo
);
629 rbbinfo
.fMask
= RBBIM_STYLE
;
631 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
634 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
636 rbbinfo
.fStyle
|= RBBS_BREAK
;
638 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
641 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
|| bandId
== BANDID_RULER
)
642 store_bar_state(bandId
, show
);
645 static void set_statusbar_state(BOOL show
)
647 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
649 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
650 store_bar_state(BANDID_STATUSBAR
, show
);
653 static void set_bar_states(void)
655 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
656 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
657 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
658 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
659 set_toolbar_state(BANDID_RULER
, is_bar_visible(BANDID_RULER
));
660 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
665 static void preview_exit(HWND hMainWnd
)
667 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
668 HMENU hMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_MAINMENU
));
669 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
672 ShowWindow(hEditorWnd
, TRUE
);
674 close_preview(hMainWnd
);
676 SetMenu(hMainWnd
, hMenu
);
677 registry_read_filelist(hMainWnd
);
682 static void set_fileformat(WPARAM format
)
685 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
689 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
691 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
693 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
697 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
700 static void ShowOpenError(DWORD Code
)
706 case ERROR_ACCESS_DENIED
:
707 Message
= MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED
);
711 Message
= MAKEINTRESOURCEW(STRING_OPEN_FAILED
);
713 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
716 static void DoOpenFile(LPCWSTR szOpenFileName
)
722 WPARAM format
= SF_TEXT
;
724 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
725 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
726 if (hFile
== INVALID_HANDLE_VALUE
)
728 ShowOpenError(GetLastError());
732 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
733 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
735 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
737 format
= SF_TEXT
| SF_UNICODE
;
738 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
739 } else if(readOut
>= 5)
741 static const char header
[] = "{\\rtf";
742 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
744 if(!memcmp(header
, fileStart
, 5))
746 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
749 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
), wszAppTitle
,
750 MB_OK
| MB_ICONEXCLAMATION
);
755 es
.dwCookie
= (DWORD_PTR
)hFile
;
756 es
.pfnCallback
= stream_in
;
759 set_fileformat(format
);
760 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
764 SetFocus(hEditorWnd
);
766 set_caption(szOpenFileName
);
768 lstrcpyW(wszFileName
, szOpenFileName
);
769 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
770 registry_set_filelist(szOpenFileName
, hMainWnd
);
774 static void ShowWriteError(DWORD Code
)
780 case ERROR_ACCESS_DENIED
:
781 Message
= MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED
);
785 Message
= MAKEINTRESOURCEW(STRING_WRITE_FAILED
);
787 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
790 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
796 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
797 FILE_ATTRIBUTE_NORMAL
, NULL
);
799 if(hFile
== INVALID_HANDLE_VALUE
)
801 ShowWriteError(GetLastError());
805 if(format
== (SF_TEXT
| SF_UNICODE
))
807 static const BYTE unicode
[] = {0xff,0xfe};
809 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
811 if(writeOut
!= sizeof(unicode
))
815 stream
.dwCookie
= (DWORD_PTR
)hFile
;
816 stream
.pfnCallback
= stream_out
;
818 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
822 SetFocus(hEditorWnd
);
827 gt
.flags
= GTL_DEFAULT
;
830 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
834 lstrcpyW(wszFileName
, wszSaveFileName
);
835 set_caption(wszFileName
);
836 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
837 set_fileformat(format
);
840 static void DialogSaveFile(void)
844 WCHAR wszFile
[MAX_PATH
] = {'\0'};
845 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
847 ZeroMemory(&sfn
, sizeof(sfn
));
849 sfn
.lStructSize
= sizeof(sfn
);
850 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
851 sfn
.hwndOwner
= hMainWnd
;
852 sfn
.lpstrFilter
= wszFilter
;
853 sfn
.lpstrFile
= wszFile
;
854 sfn
.nMaxFile
= MAX_PATH
;
855 sfn
.lpstrDefExt
= wszDefExt
;
856 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
858 while(GetSaveFileNameW(&sfn
))
860 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
862 if(MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
863 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
868 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
873 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
879 static BOOL
prompt_save_changes(void)
884 gt
.flags
= GTL_NUMCHARS
;
886 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
890 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
895 LPWSTR displayFileName
;
900 displayFileName
= wszDefaultFileName
;
902 displayFileName
= file_basename(wszFileName
);
904 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
905 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
910 wsprintfW(text
, wszSaveChanges
, displayFileName
);
912 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
914 HeapFree(GetProcessHeap(), 0, text
);
923 DoSaveFile(wszFileName
, fileFormat
);
934 static void DialogOpenFile(void)
938 WCHAR wszFile
[MAX_PATH
] = {'\0'};
939 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
941 ZeroMemory(&ofn
, sizeof(ofn
));
943 ofn
.lStructSize
= sizeof(ofn
);
944 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
945 ofn
.hwndOwner
= hMainWnd
;
946 ofn
.lpstrFilter
= wszFilter
;
947 ofn
.lpstrFile
= wszFile
;
948 ofn
.nMaxFile
= MAX_PATH
;
949 ofn
.lpstrDefExt
= wszDefExt
;
950 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
952 if(GetOpenFileNameW(&ofn
))
954 if(prompt_save_changes())
955 DoOpenFile(ofn
.lpstrFile
);
959 static void dialog_about(void)
961 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
962 HICON icon
= LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
, 48, 48, LR_SHARED
);
963 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
966 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
972 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
975 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
977 sprintf(id
, "%d\n", (int)ps
->lParam
);
978 SetWindowTextA(hIdWnd
, id
);
979 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
980 wrap
= IDC_PAGEFMT_WW
;
981 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
982 wrap
= IDC_PAGEFMT_WM
;
985 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
,
986 IDC_PAGEFMT_WM
, wrap
);
988 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
989 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
990 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
991 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
992 if(barState
[ps
->lParam
] & (1 << BANDID_RULER
))
993 CheckDlgButton(hWnd
, IDC_PAGEFMT_RU
, TRUE
);
994 if(barState
[ps
->lParam
] & (1 << BANDID_STATUSBAR
))
995 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1000 switch(LOWORD(wParam
))
1002 case IDC_PAGEFMT_WW
:
1003 case IDC_PAGEFMT_WM
:
1004 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
, IDC_PAGEFMT_WM
,
1008 case IDC_PAGEFMT_TB
:
1009 case IDC_PAGEFMT_FB
:
1010 case IDC_PAGEFMT_RU
:
1011 case IDC_PAGEFMT_SB
:
1012 CheckDlgButton(hWnd
, LOWORD(wParam
),
1013 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1019 LPNMHDR header
= (LPNMHDR
)lParam
;
1020 if(header
->code
== PSN_APPLY
)
1022 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1026 GetWindowTextA(hIdWnd
, sid
, 4);
1028 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1029 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1030 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1031 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1033 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1034 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1036 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1038 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1039 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1041 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1043 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_RU
))
1044 barState
[id
] |= (1 << BANDID_RULER
);
1046 barState
[id
] &= ~(1 << BANDID_RULER
);
1048 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1049 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1051 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1059 static void dialog_viewproperties(void)
1061 PROPSHEETPAGEW psp
[2];
1062 PROPSHEETHEADERW psh
;
1064 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1065 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1067 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1068 psp
[0].dwFlags
= PSP_USETITLE
;
1069 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1070 psp
[0].pfnDlgProc
= formatopts_proc
;
1071 psp
[0].hInstance
= hInstance
;
1072 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1073 psp
[0].pfnCallback
= NULL
;
1074 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1075 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1077 psp
[i
].dwSize
= psp
[0].dwSize
;
1078 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1079 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1080 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1081 psp
[i
].hInstance
= psp
[0].hInstance
;
1082 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1083 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1084 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1087 psh
.dwSize
= sizeof(psh
);
1088 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1089 psh
.hwndParent
= hMainWnd
;
1090 psh
.hInstance
= hInstance
;
1091 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1092 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1093 U3(psh
).ppsp
= ppsp
;
1094 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1096 if(fileFormat
& SF_RTF
)
1097 U2(psh
).nStartPage
= 1;
1099 U2(psh
).nStartPage
= 0;
1100 PropertySheetW(&psh
);
1102 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1105 static void HandleCommandLine(LPWSTR cmdline
)
1110 /* skip white space */
1111 while (*cmdline
== ' ') cmdline
++;
1113 /* skip executable name */
1114 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1116 if (*cmdline
== delimiter
) cmdline
++;
1117 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1118 if (*cmdline
== delimiter
) cmdline
++;
1122 while (isspace(*cmdline
)) cmdline
++;
1124 if (*cmdline
== '-' || *cmdline
== '/')
1126 if (!cmdline
[2] || isspace(cmdline
[2]))
1137 /* a filename starting by / */
1144 /* file name is passed on the command line */
1145 if (cmdline
[0] == '"')
1148 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1150 DoOpenFile(cmdline
);
1151 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1155 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED
), wszAppTitle
, MB_OK
);
1158 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1160 if(pFr
->Flags
& FR_DIALOGTERM
)
1163 pFr
->Flags
= FR_FINDNEXT
;
1167 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1169 DWORD flags
= FR_DOWN
;
1171 static CHARRANGE cr
;
1176 HMENU hMenu
= GetMenu(hMainWnd
);
1179 mi
.cbSize
= sizeof(mi
);
1180 mi
.fMask
= MIIM_DATA
;
1182 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1184 gt
.flags
= GTL_NUMCHARS
;
1187 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1189 if(pFr
->lCustData
== -1)
1191 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1192 cr
.cpMin
= startPos
;
1193 pFr
->lCustData
= startPos
;
1195 if(cr
.cpMin
== length
)
1199 startPos
= pFr
->lCustData
;
1202 if(cr
.cpMax
> length
)
1210 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1212 if(pFr
->Flags
& FR_MATCHCASE
)
1213 flags
|= FR_MATCHCASE
;
1214 if(pFr
->Flags
& FR_WHOLEWORD
)
1215 flags
|= FR_WHOLEWORD
;
1217 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1221 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1223 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1224 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1226 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1232 pFr
->lCustData
= -1;
1233 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1234 MB_OK
| MB_ICONASTERISK
);
1237 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1239 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1240 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1242 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1243 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1245 if(pFr
->Flags
& FR_REPLACEALL
)
1246 handle_findmsg(pFr
);
1253 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1255 static WCHAR findBuffer
[MAX_STRING_LEN
];
1257 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1258 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1259 fr
->hwndOwner
= hMainWnd
;
1260 fr
->Flags
= FR_HIDEUPDOWN
;
1261 fr
->lpstrFindWhat
= findBuffer
;
1263 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1266 hFindWnd
= ReplaceTextW(fr
);
1268 hFindWnd
= FindTextW(fr
);
1271 static int current_units_to_twips(float number
)
1273 int twips
= (int)(number
* TWIPS_PER_CM
);
1277 static void append_current_units(LPWSTR buffer
)
1279 static const WCHAR space
[] = {' ', 0};
1280 lstrcatW(buffer
, space
);
1281 lstrcatW(buffer
, units_cmW
);
1284 static void number_with_units(LPWSTR buffer
, int number
)
1286 float converted
= (float)number
/ TWIPS_PER_CM
;
1287 char string
[MAX_STRING_LEN
];
1289 sprintf(string
, "%.2f ", converted
);
1290 lstrcatA(string
, units_cmA
);
1291 MultiByteToWideChar(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
);
1294 static BOOL
get_comboexlist_selection(HWND hComboEx
, LPWSTR wszBuffer
, UINT bufferLength
)
1297 COMBOBOXEXITEM cbItem
;
1298 COMBOBOXINFO cbInfo
;
1302 hCombo
= (HWND
)SendMessage(hComboEx
, CBEM_GETCOMBOCONTROL
, 0, 0);
1305 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
1306 result
= SendMessage(hCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)&cbInfo
);
1309 hList
= cbInfo
.hwndList
;
1310 idx
= SendMessage(hList
, LB_GETCURSEL
, 0, 0);
1314 hHeap
= GetProcessHeap();
1315 szBuffer
= HeapAlloc(hHeap
, HEAP_ZERO_MEMORY
, bufferLength
);
1316 ZeroMemory(&cbItem
, sizeof(cbItem
));
1317 cbItem
.mask
= CBEIF_TEXT
;
1319 cbItem
.pszText
= szBuffer
;
1320 cbItem
.cchTextMax
= bufferLength
-1;
1321 result
= SendMessage(hComboEx
, CBEM_GETITEM
, 0, (LPARAM
)&cbItem
);
1324 HeapFree(hHeap
, 0, szBuffer
);
1328 result
= MultiByteToWideChar(CP_ACP
, 0, szBuffer
, -1, wszBuffer
, bufferLength
);
1329 HeapFree(hHeap
, 0, szBuffer
);
1333 static INT_PTR CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1339 WCHAR buffer
[MAX_STRING_LEN
];
1341 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1344 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1346 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1347 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1349 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1350 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1351 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1353 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1358 switch(LOWORD(wParam
))
1363 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1365 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1369 WCHAR buffer
[MAX_STRING_LEN
];
1370 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1371 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1377 EndDialog(hWnd
, wParam
);
1384 static INT_PTR CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1390 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1391 WCHAR buffer
[MAX_STRING_LEN
];
1392 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1394 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1395 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1396 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1397 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1398 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1399 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1401 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1406 switch(LOWORD(wParam
))
1411 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1412 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1415 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1420 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1427 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1429 static const WORD ALIGNMENT_VALUES
[] = {PFA_LEFT
, PFA_RIGHT
, PFA_CENTER
};
1435 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
1437 WCHAR buffer
[MAX_STRING_LEN
];
1438 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1439 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1440 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1441 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1445 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1447 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1448 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1450 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1451 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1453 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1455 pf
.cbSize
= sizeof(pf
);
1456 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1458 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1460 if(pf
.wAlignment
== PFA_RIGHT
)
1462 else if(pf
.wAlignment
== PFA_CENTER
)
1465 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1467 number_with_units(buffer
, pf
.dxStartIndent
+ pf
.dxOffset
);
1468 SetWindowTextW(hLeftWnd
, buffer
);
1469 number_with_units(buffer
, pf
.dxRightIndent
);
1470 SetWindowTextW(hRightWnd
, buffer
);
1471 number_with_units(buffer
, -pf
.dxOffset
);
1472 SetWindowTextW(hFirstWnd
, buffer
);
1477 switch(LOWORD(wParam
))
1481 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1482 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1483 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1484 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1485 WCHAR buffer
[MAX_STRING_LEN
];
1491 index
= SendMessageW(hListWnd
, CB_GETCURSEL
, 0, 0);
1492 pf
.wAlignment
= ALIGNMENT_VALUES
[index
];
1494 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1495 if(number_from_string(buffer
, &num
, TRUE
))
1497 pf
.dxOffset
= current_units_to_twips(num
);
1498 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1499 if(number_from_string(buffer
, &num
, TRUE
))
1501 pf
.dxRightIndent
= current_units_to_twips(num
);
1502 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1503 if(number_from_string(buffer
, &num
, TRUE
))
1505 pf
.dxStartIndent
= current_units_to_twips(num
);
1509 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1510 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1514 if (pf
.dxOffset
+ pf
.dxStartIndent
< 0
1515 && pf
.dxStartIndent
< 0)
1517 /* The first line is before the left edge, so
1518 * make sure it is at the left edge. */
1519 pf
.dxOffset
= -pf
.dxStartIndent
;
1520 } else if (pf
.dxOffset
< 0) {
1521 /* The second and following lines are before
1522 * the left edge, so set it to be at the left
1523 * edge, and adjust the first line since it
1524 * is relative to it. */
1525 pf
.dxStartIndent
= max(pf
.dxStartIndent
+ pf
.dxOffset
, 0);
1528 /* Internally the dxStartIndent is the absolute
1529 * offset for the first line and dxOffset is
1530 * to it value as opposed how it is displayed with
1531 * the first line being the relative value.
1532 * These two lines make the adjustments. */
1533 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1534 pf
.dxOffset
= pf
.dxOffset
- pf
.dxStartIndent
;
1536 pf
.cbSize
= sizeof(pf
);
1537 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1539 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1545 EndDialog(hWnd
, wParam
);
1552 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1558 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1560 WCHAR buffer
[MAX_STRING_LEN
];
1563 pf
.cbSize
= sizeof(pf
);
1564 pf
.dwMask
= PFM_TABSTOPS
;
1565 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1566 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1568 for(i
= 0; i
< pf
.cTabCount
; i
++)
1570 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1571 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1578 switch(LOWORD(wParam
))
1582 HWND hTabWnd
= (HWND
)lParam
;
1583 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1584 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1585 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1587 if(GetWindowTextLengthW(hTabWnd
))
1588 EnableWindow(hAddWnd
, TRUE
);
1590 EnableWindow(hAddWnd
, FALSE
);
1592 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1594 EnableWindow(hEmptyWnd
, TRUE
);
1596 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1597 EnableWindow(hDelWnd
, FALSE
);
1599 EnableWindow(hDelWnd
, TRUE
);
1602 EnableWindow(hEmptyWnd
, FALSE
);
1609 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1610 WCHAR buffer
[MAX_STRING_LEN
];
1612 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1613 append_current_units(buffer
);
1615 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1619 if(!number_from_string(buffer
, &number
, TRUE
))
1621 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1622 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1625 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1626 SetWindowTextW(hTabWnd
, 0);
1635 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1637 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1639 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1645 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1646 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1653 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1655 WCHAR buffer
[MAX_STRING_LEN
];
1659 pf
.cbSize
= sizeof(pf
);
1660 pf
.dwMask
= PFM_TABSTOPS
;
1662 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1663 (LPARAM
)&buffer
) != CB_ERR
&&
1664 i
< MAX_TAB_STOPS
; i
++)
1666 number_from_string(buffer
, &number
, TRUE
);
1667 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
1670 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1674 EndDialog(hWnd
, wParam
);
1681 static int context_menu(LPARAM lParam
)
1683 int x
= (int)(short)LOWORD(lParam
);
1684 int y
= (int)(short)HIWORD(lParam
);
1685 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1689 int from
= 0, to
= 0;
1691 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1692 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
1693 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1698 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1699 x
, y
, 0, hMainWnd
, 0);
1704 static LRESULT
OnCreate( HWND hWnd
)
1706 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
, hRulerWnd
;
1707 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1710 int nStdBitmaps
= 0;
1713 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1714 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1716 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1718 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1719 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1720 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1722 rbi
.cbSize
= sizeof(rbi
);
1725 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1728 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1730 1, hInstance
, IDB_TOOLBAR
,
1732 24, 24, 16, 16, sizeof(TBBUTTON
));
1734 ab
.hInst
= HINST_COMMCTRL
;
1735 ab
.nID
= IDB_STD_SMALL_COLOR
;
1736 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1738 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1739 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1740 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1741 AddSeparator(hToolBarWnd
);
1742 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1743 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1744 AddSeparator(hToolBarWnd
);
1745 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1746 AddSeparator(hToolBarWnd
);
1747 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1748 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1749 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1750 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1751 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1752 AddSeparator(hToolBarWnd
);
1753 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1755 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1757 rbb
.cbSize
= sizeof(rbb
);
1758 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1759 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1761 rbb
.hwndChild
= hToolBarWnd
;
1763 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1764 rbb
.wID
= BANDID_TOOLBAR
;
1766 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1768 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1769 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1770 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1772 rbb
.hwndChild
= hFontListWnd
;
1774 rbb
.wID
= BANDID_FONTLIST
;
1776 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1778 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1779 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1780 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1782 rbb
.hwndChild
= hSizeListWnd
;
1784 rbb
.fStyle
^= RBBS_BREAK
;
1785 rbb
.wID
= BANDID_SIZELIST
;
1787 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1789 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1790 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1791 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1793 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1794 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1795 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1796 AddSeparator(hFormatBarWnd
);
1797 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
1798 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
1799 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
1800 AddSeparator(hFormatBarWnd
);
1801 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
1803 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
1805 rbb
.hwndChild
= hFormatBarWnd
;
1806 rbb
.wID
= BANDID_FORMATBAR
;
1808 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1810 hRulerWnd
= CreateWindowExW(0, WC_STATICW
, NULL
, WS_VISIBLE
| WS_CHILD
,
1811 0, 0, 200, 10, hReBarWnd
, (HMENU
)IDC_RULER
, hInstance
, NULL
);
1814 rbb
.hwndChild
= hRulerWnd
;
1815 rbb
.wID
= BANDID_RULER
;
1816 rbb
.fStyle
|= RBBS_BREAK
;
1818 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1820 hDLL
= LoadLibraryW(wszRichEditDll
);
1823 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
1824 MB_OK
| MB_ICONEXCLAMATION
);
1828 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
1829 WS_CHILD
|WS_VISIBLE
|ES_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
1830 |ES_WANTRETURN
|WS_VSCROLL
|ES_NOHIDESEL
,
1831 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
1835 fprintf(stderr
, "Error code %u\n", GetLastError());
1840 SetFocus(hEditorWnd
);
1841 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
1845 populate_font_list(hFontListWnd
);
1846 populate_size_list(hSizeListWnd
);
1848 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1850 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
1852 registry_read_filelist(hWnd
);
1853 registry_read_formatopts_all(barState
, wordWrap
);
1854 registry_read_options();
1855 DragAcceptFiles(hWnd
, TRUE
);
1860 static LRESULT
OnUser( HWND hWnd
)
1862 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1863 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1864 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
1865 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
1871 ZeroMemory(&fmt
, sizeof(fmt
));
1872 fmt
.cbSize
= sizeof(fmt
);
1874 ZeroMemory(&pf
, sizeof(pf
));
1875 pf
.cbSize
= sizeof(pf
);
1877 gt
.flags
= GTL_NUMCHARS
;
1880 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
1881 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
1883 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
1885 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1886 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
1887 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
1888 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
1889 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
1890 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
1891 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
1893 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
1894 (fmt
.dwEffects
& CFE_BOLD
));
1895 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
1896 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
1897 (fmt
.dwEffects
& CFE_ITALIC
));
1898 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
1899 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
1900 (fmt
.dwEffects
& CFE_UNDERLINE
));
1901 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
1903 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1904 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
1905 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
1906 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
1908 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
1912 static LRESULT
OnNotify( HWND hWnd
, LPARAM lParam
)
1914 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1915 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1916 NMHDR
*pHdr
= (NMHDR
*)lParam
;
1917 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
1918 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
1920 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
1922 if (pHdr
->code
== CBEN_ENDEDITW
)
1924 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
1925 if(pHdr
->hwndFrom
== hwndFontList
)
1927 on_fontlist_modified((LPWSTR
)endEdit
->szText
);
1928 } else if (pHdr
->hwndFrom
== hwndSizeList
)
1930 on_sizelist_modified(hwndFontList
,(LPWSTR
)endEdit
->szText
);
1936 if (pHdr
->hwndFrom
!= hwndEditor
)
1939 if (pHdr
->code
== EN_SELCHANGE
)
1941 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
1946 sprintf( buf
,"selection = %d..%d, line count=%ld",
1947 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
1948 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
1949 SetWindowTextA(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
1950 SendMessage(hWnd
, WM_USER
, 0, 0);
1956 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1958 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1959 static FINDREPLACEW findreplace
;
1961 if ((HWND
)lParam
== hwndEditor
)
1964 switch(LOWORD(wParam
))
1968 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
1973 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1974 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
1977 if(ret
!= ID_NEWFILE_ABORT
)
1979 if(prompt_save_changes())
1984 wszFileName
[0] = '\0';
1988 st
.flags
= ST_DEFAULT
;
1990 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
1992 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1993 set_fileformat(ret
);
2007 DoSaveFile(wszFileName
, fileFormat
);
2012 case ID_FILE_SAVEAS
:
2016 case ID_FILE_RECENT1
:
2017 case ID_FILE_RECENT2
:
2018 case ID_FILE_RECENT3
:
2019 case ID_FILE_RECENT4
:
2021 HMENU hMenu
= GetMenu(hWnd
);
2024 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2025 mi
.fMask
= MIIM_DATA
;
2026 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2027 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2032 dialog_find(&findreplace
, FALSE
);
2036 handle_findmsg(&findreplace
);
2040 dialog_find(&findreplace
, TRUE
);
2043 case ID_FONTSETTINGS
:
2044 dialog_choose_font();
2048 dialog_print(hWnd
, wszFileName
);
2049 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2052 case ID_PRINT_QUICK
:
2053 print_quick(wszFileName
);
2054 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2059 int index
= reg_formatindex(fileFormat
);
2060 DWORD tmp
= barState
[index
];
2061 barState
[index
] = 0;
2063 barState
[index
] = tmp
;
2064 ShowWindow(hEditorWnd
, FALSE
);
2066 init_preview(hWnd
, wszFileName
);
2068 SetMenu(hWnd
, NULL
);
2069 InvalidateRect(0, 0, TRUE
);
2074 dialog_printsetup(hWnd
);
2075 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2078 case ID_FORMAT_BOLD
:
2079 case ID_FORMAT_ITALIC
:
2080 case ID_FORMAT_UNDERLINE
:
2083 int effects
= CFE_BOLD
;
2085 ZeroMemory(&fmt
, sizeof(fmt
));
2086 fmt
.cbSize
= sizeof(fmt
);
2087 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2089 fmt
.dwMask
= CFM_BOLD
;
2091 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2093 effects
= CFE_ITALIC
;
2094 fmt
.dwMask
= CFM_ITALIC
;
2095 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2097 effects
= CFE_UNDERLINE
;
2098 fmt
.dwMask
= CFM_UNDERLINE
;
2101 fmt
.dwEffects
^= effects
;
2103 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2108 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2112 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2116 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2120 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2123 case ID_EDIT_SELECTALL
:
2125 CHARRANGE range
= {0, -1};
2126 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2127 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2131 case ID_EDIT_GETTEXT
:
2133 int nLen
= GetWindowTextLengthW(hwndEditor
);
2134 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2137 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2138 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2140 HeapFree( GetProcessHeap(), 0, data
);
2141 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2143 tr
.chrg
.cpMax
= nLen
;
2144 tr
.lpstrText
= data
;
2145 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2146 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2147 HeapFree( GetProcessHeap(), 0, data
);
2149 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2153 case ID_EDIT_CHARFORMAT
:
2154 case ID_EDIT_DEFCHARFORMAT
:
2158 ZeroMemory(&cf
, sizeof(cf
));
2159 cf
.cbSize
= sizeof(cf
);
2161 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2162 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2166 case ID_EDIT_PARAFORMAT
:
2169 ZeroMemory(&pf
, sizeof(pf
));
2170 pf
.cbSize
= sizeof(pf
);
2171 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2175 case ID_EDIT_SELECTIONINFO
:
2177 CHARRANGE range
= {0, -1};
2181 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2182 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2183 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2184 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2185 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2186 MessageBoxW(hWnd
, data
, wszAppTitle
, MB_OK
);
2187 HeapFree( GetProcessHeap(), 0, data
);
2188 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2192 case ID_EDIT_READONLY
:
2194 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2195 if (nStyle
& ES_READONLY
)
2196 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2198 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2202 case ID_EDIT_MODIFIED
:
2203 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2204 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2206 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2210 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2214 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2221 pf
.cbSize
= sizeof(pf
);
2222 pf
.dwMask
= PFM_NUMBERING
;
2223 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2225 pf
.dwMask
|= PFM_OFFSET
;
2227 if(pf
.wNumbering
== PFN_BULLET
)
2233 pf
.wNumbering
= PFN_BULLET
;
2237 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2242 case ID_ALIGN_CENTER
:
2243 case ID_ALIGN_RIGHT
:
2247 pf
.cbSize
= sizeof(pf
);
2248 pf
.dwMask
= PFM_ALIGNMENT
;
2249 switch(LOWORD(wParam
)) {
2250 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2251 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2252 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2254 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2259 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2263 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2266 case ID_TOGGLE_TOOLBAR
:
2267 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2271 case ID_TOGGLE_FORMATBAR
:
2272 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2273 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2274 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2278 case ID_TOGGLE_STATUSBAR
:
2279 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2283 case ID_TOGGLE_RULER
:
2284 set_toolbar_state(BANDID_RULER
, !is_bar_visible(BANDID_RULER
));
2290 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2291 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, datetime_proc
);
2297 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2298 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
2305 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2306 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2314 case ID_VIEWPROPERTIES
:
2315 dialog_viewproperties();
2319 if (HIWORD(wParam
) == CBN_SELENDOK
)
2321 WCHAR buffer
[LF_FACESIZE
];
2322 HWND hwndFontList
= (HWND
)lParam
;
2323 get_comboexlist_selection(hwndFontList
, buffer
, LF_FACESIZE
);
2324 on_fontlist_modified(buffer
);
2329 if (HIWORD(wParam
) == CBN_SELENDOK
)
2331 WCHAR buffer
[MAX_STRING_LEN
+1];
2332 HWND hwndSizeList
= (HWND
)lParam
;
2333 get_comboexlist_selection(hwndSizeList
, buffer
, MAX_STRING_LEN
+1);
2334 on_sizelist_modified(hwndSizeList
, buffer
);
2339 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2345 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
)
2347 HMENU hMenu
= (HMENU
)wParam
;
2348 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2349 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2351 int nAlignment
= -1;
2357 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2358 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2359 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2361 pf
.cbSize
= sizeof(PARAFORMAT
);
2362 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2363 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2364 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2365 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2366 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2367 if (pf
.dwMask
& PFM_ALIGNMENT
)
2368 nAlignment
= pf
.wAlignment
;
2369 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2370 MF_CHECKED
: MF_UNCHECKED
);
2371 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2372 MF_CHECKED
: MF_UNCHECKED
);
2373 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2374 MF_CHECKED
: MF_UNCHECKED
);
2375 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2376 MF_CHECKED
: MF_UNCHECKED
));
2377 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2378 MF_ENABLED
: MF_GRAYED
);
2379 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2380 MF_ENABLED
: MF_GRAYED
);
2382 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2383 MF_CHECKED
: MF_UNCHECKED
);
2385 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2386 MF_CHECKED
: MF_UNCHECKED
);
2388 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2389 MF_CHECKED
: MF_UNCHECKED
);
2391 CheckMenuItem(hMenu
, ID_TOGGLE_RULER
, MF_BYCOMMAND
|(is_bar_visible(BANDID_RULER
)) ? MF_CHECKED
: MF_UNCHECKED
);
2393 gt
.flags
= GTL_NUMCHARS
;
2395 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2396 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2398 mi
.cbSize
= sizeof(mi
);
2399 mi
.fMask
= MIIM_DATA
;
2401 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2403 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2404 MF_ENABLED
: MF_GRAYED
));
2406 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2411 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2413 int nStatusSize
= 0;
2415 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2416 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2417 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2418 HWND hRulerWnd
= GetDlgItem(hWnd
, IDC_RULER
);
2419 int rebarHeight
= 0;
2423 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2424 if (IsWindowVisible(hwndStatusBar
))
2426 GetClientRect(hwndStatusBar
, &rc
);
2427 nStatusSize
= rc
.bottom
- rc
.top
;
2435 rebarHeight
= SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
2437 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2441 GetClientRect(hWnd
, &rc
);
2442 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2445 redraw_ruler(hRulerWnd
);
2447 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2450 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2452 if(msg
== ID_FINDMSGSTRING
)
2453 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2458 return OnCreate( hWnd
);
2461 return OnUser( hWnd
);
2464 return OnNotify( hWnd
, lParam
);
2467 if(preview_isactive())
2469 return preview_command( hWnd
, wParam
);
2472 return OnCommand( hWnd
, wParam
, lParam
);
2479 if(preview_isactive())
2482 } else if(prompt_save_changes())
2484 registry_set_options(hMainWnd
);
2485 registry_set_formatopts_all(barState
);
2492 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2495 case WM_INITMENUPOPUP
:
2496 return OnInitPopupMenu( hWnd
, wParam
);
2499 return OnSize( hWnd
, wParam
, lParam
);
2501 case WM_CONTEXTMENU
:
2502 if((HWND
)wParam
== hEditorWnd
)
2503 return context_menu(lParam
);
2505 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2509 WCHAR file
[MAX_PATH
];
2510 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2511 DragFinish((HDROP
)wParam
);
2513 if(prompt_save_changes())
2518 if(preview_isactive())
2519 return print_preview(hWnd
);
2521 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2524 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2530 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int nCmdShow
)
2532 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2537 UINT_PTR hPrevRulerProc
;
2541 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2542 'T','A','B','L','E','\0'};
2544 InitCommonControlsEx(&classes
);
2546 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2548 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2549 wc
.lpfnWndProc
= WndProc
;
2552 wc
.hInstance
= hInstance
;
2553 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2554 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2555 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2556 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2557 wc
.lpszClassName
= wszMainWndClass
;
2558 RegisterClassW(&wc
);
2560 registry_read_winrect(&rc
);
2561 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2562 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2563 registry_read_maximized(&bMaximized
);
2564 if ((nCmdShow
== SW_SHOWNORMAL
|| nCmdShow
== SW_SHOWDEFAULT
)
2566 nCmdShow
= SW_SHOWMAXIMIZED
;
2567 ShowWindow(hMainWnd
, nCmdShow
);
2571 set_fileformat(SF_RTF
);
2572 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2573 get_default_printer_opts();
2574 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2576 hRulerWnd
= GetDlgItem(GetDlgItem(hMainWnd
, IDC_REBAR
), IDC_RULER
);
2577 SendMessageW(GetDlgItem(hMainWnd
, IDC_EDITOR
), EM_POSFROMCHAR
, (WPARAM
)&EditPoint
, 0);
2578 hPrevRulerProc
= SetWindowLongPtrW(hRulerWnd
, GWLP_WNDPROC
, (UINT_PTR
)ruler_proc
);
2579 SendMessageW(hRulerWnd
, WM_USER
, (WPARAM
)&EditPoint
, hPrevRulerProc
);
2581 HandleCommandLine(GetCommandLineW());
2583 while(GetMessageW(&msg
,0,0,0))
2585 if (IsDialogMessage(hFindWnd
, &msg
))
2588 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2590 TranslateMessage(&msg
);
2591 DispatchMessageW(&msg
);
2592 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2593 SendMessageW(hMainWnd
, WM_USER
, 0, 0);