2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2007-2008 by Alexander N. Sørnes <alex@thehandofagony.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define _WIN32_IE 0x0400
39 #include "wine/unicode.h"
42 #ifdef NONAMELESSUNION
53 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
55 static const WCHAR wszRichEditClass
[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
56 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
58 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
61 static HWND hEditorWnd
;
63 static HMENU hPopupMenu
;
65 static UINT ID_FINDMSGSTRING
;
67 static DWORD wordWrap
[2];
68 static DWORD barState
[2];
69 static WPARAM fileFormat
= SF_RTF
;
71 static WCHAR wszFileName
[MAX_PATH
];
72 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
73 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
74 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
75 static WCHAR units_cmW
[MAX_STRING_LEN
];
77 static char units_cmA
[MAX_STRING_LEN
];
79 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
81 /* Load string resources */
82 static void DoLoadStrings(void)
85 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
86 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
87 static const WCHAR files_all
[] = {'*','.','*','\0'};
89 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
91 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
93 lstrcpyW(p
, files_rtf
);
95 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
97 lstrcpyW(p
, files_txt
);
99 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
100 p
+= lstrlenW(p
) + 1;
101 lstrcpyW(p
, files_txt
);
102 p
+= lstrlenW(p
) + 1;
103 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
104 p
+= lstrlenW(p
) + 1;
105 lstrcpyW(p
, files_all
);
106 p
+= lstrlenW(p
) + 1;
109 p
= wszDefaultFileName
;
110 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
113 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
115 LoadStringA(hInstance
, STRING_UNITS_CM
, units_cmA
, MAX_STRING_LEN
);
116 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
119 /* Show a message box with resource strings */
120 static int MessageBoxWithResStringW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
)
122 MSGBOXPARAMSW params
;
124 params
.cbSize
= sizeof(params
);
125 params
.hwndOwner
= hWnd
;
126 params
.hInstance
= GetModuleHandleW(0);
127 params
.lpszText
= lpText
;
128 params
.lpszCaption
= lpCaption
;
129 params
.dwStyle
= uType
;
130 params
.lpszIcon
= NULL
;
131 params
.dwContextHelpId
= 0;
132 params
.lpfnMsgBoxCallback
= NULL
;
133 params
.dwLanguageId
= 0;
134 return MessageBoxIndirectW(¶ms
);
138 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
142 ZeroMemory(&button
, sizeof(button
));
143 button
.iBitmap
= nImage
;
144 button
.idCommand
= nCommand
;
145 button
.fsState
= TBSTATE_ENABLED
;
146 button
.fsStyle
= TBSTYLE_BUTTON
;
149 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
152 static void AddSeparator(HWND hwndToolBar
)
156 ZeroMemory(&button
, sizeof(button
));
158 button
.idCommand
= 0;
160 button
.fsStyle
= TBSTYLE_SEP
;
163 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
166 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
168 HANDLE hFile
= (HANDLE
)cookie
;
171 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
179 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
183 HANDLE hFile
= (HANDLE
)cookie
;
185 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
187 if(!ret
|| (cb
!= written
))
195 LPWSTR
file_basename(LPWSTR path
)
197 LPWSTR pos
= path
+ lstrlenW(path
);
201 if(*pos
== '\\' || *pos
== '/')
211 static void set_caption(LPCWSTR wszNewFileName
)
213 static const WCHAR wszSeparator
[] = {' ','-',' '};
218 wszNewFileName
= wszDefaultFileName
;
220 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
222 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
223 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
228 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
229 length
+= lstrlenW(wszNewFileName
);
230 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
231 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
232 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
234 SetWindowTextW(hMainWnd
, wszCaption
);
236 HeapFree(GetProcessHeap(), 0, wszCaption
);
239 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
246 while(*endptr
== ' ')
250 return *endptr
== '\0';
252 /* FIXME: Allow other units and convert between them */
253 if(!lstrcmpA(endptr
, units_cmA
))
256 return *endptr
== '\0';
259 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
262 char buffer
[MAX_STRING_LEN
];
263 char *endptr
= buffer
;
265 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
268 ret
= strtod(buffer
, &endptr
);
270 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| !validate_endptr(endptr
, units
))
280 static void set_size(float size
)
284 ZeroMemory(&fmt
, sizeof(fmt
));
285 fmt
.cbSize
= sizeof(fmt
);
286 fmt
.dwMask
= CFM_SIZE
;
287 fmt
.yHeight
= (int)(size
* 20.0);
288 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
291 static void on_sizelist_modified(HWND hwndSizeList
, LPWSTR wszNewFontSize
)
293 WCHAR sizeBuffer
[MAX_STRING_LEN
];
296 ZeroMemory(&format
, sizeof(format
));
297 format
.cbSize
= sizeof(format
);
298 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
300 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
301 if(lstrcmpW(sizeBuffer
, wszNewFontSize
))
304 if(number_from_string((LPCWSTR
) wszNewFontSize
, &size
, FALSE
)
310 SetWindowTextW(hwndSizeList
, sizeBuffer
);
311 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
312 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
317 static void add_size(HWND hSizeListWnd
, unsigned size
)
320 COMBOBOXEXITEMW cbItem
;
321 cbItem
.mask
= CBEIF_TEXT
;
324 wsprintfW(buffer
, stringFormat
, size
);
325 cbItem
.pszText
= (LPWSTR
)buffer
;
326 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
329 static void populate_size_list(HWND hSizeListWnd
)
331 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
332 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
333 COMBOBOXEXITEMW cbFontItem
;
335 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
336 HDC hdc
= GetDC(hMainWnd
);
337 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
342 ZeroMemory(&fmt
, sizeof(fmt
));
343 fmt
.cbSize
= sizeof(fmt
);
344 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
346 cbFontItem
.mask
= CBEIF_LPARAM
;
347 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
348 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
350 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
352 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
354 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
356 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
357 GetDeviceCaps(hdc
, LOGPIXELSY
)));
360 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
361 add_size(hSizeListWnd
, choices
[i
]);
364 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
365 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
368 static void update_size_list(void)
370 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
371 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
372 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
373 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
376 ZeroMemory(&fmt
, sizeof(fmt
));
377 fmt
.cbSize
= sizeof(fmt
);
379 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
381 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
382 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
384 if(lstrcmpW(fontSize
, sizeBuffer
))
385 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
388 static void update_font_list(void)
390 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
391 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
392 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
393 WCHAR fontName
[MAX_STRING_LEN
];
396 ZeroMemory(&fmt
, sizeof(fmt
));
397 fmt
.cbSize
= sizeof(fmt
);
399 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
400 if (!SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
)) return;
402 if(lstrcmpW(fontName
, fmt
.szFaceName
))
404 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
405 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
412 static void clear_formatting(void)
416 pf
.cbSize
= sizeof(pf
);
417 pf
.dwMask
= PFM_ALIGNMENT
;
418 pf
.wAlignment
= PFA_LEFT
;
419 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
422 static int fileformat_number(WPARAM format
)
426 if(format
== SF_TEXT
)
429 } else if (format
== (SF_TEXT
| SF_UNICODE
))
436 static WPARAM
fileformat_flags(int format
)
438 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
440 return flags
[format
];
443 static void set_font(LPCWSTR wszFaceName
)
445 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
446 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
447 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
448 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
451 ZeroMemory(&fmt
, sizeof(fmt
));
453 fmt
.cbSize
= sizeof(fmt
);
454 fmt
.dwMask
= CFM_FACE
;
456 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
458 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
460 populate_size_list(hSizeListWnd
);
462 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)wszFaceName
);
465 static void set_default_font(void)
467 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
468 'R','o','m','a','n',0};
469 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
473 ZeroMemory(&fmt
, sizeof(fmt
));
475 fmt
.cbSize
= sizeof(fmt
);
476 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
479 if(fileFormat
& SF_RTF
)
482 font
= plainTextFont
;
484 lstrcpyW(fmt
.szFaceName
, font
);
486 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
489 static void on_fontlist_modified(LPWSTR wszNewFaceName
)
492 ZeroMemory(&format
, sizeof(format
));
493 format
.cbSize
= sizeof(format
);
494 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
496 if(lstrcmpW(format
.szFaceName
, wszNewFaceName
))
497 set_font((LPCWSTR
) wszNewFaceName
);
500 static void add_font(LPCWSTR fontName
, DWORD fontType
, HWND hListWnd
, const NEWTEXTMETRICEXW
*ntmc
)
502 COMBOBOXEXITEMW cbItem
;
503 WCHAR buffer
[MAX_PATH
];
506 cbItem
.mask
= CBEIF_TEXT
;
507 cbItem
.pszText
= buffer
;
508 cbItem
.cchTextMax
= MAX_STRING_LEN
;
511 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
513 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
518 cbItem
.pszText
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName
) + 1)*sizeof(WCHAR
) );
519 lstrcpyW( cbItem
.pszText
, fontName
);
521 cbItem
.mask
|= CBEIF_LPARAM
;
522 if(fontType
& RASTER_FONTTYPE
)
523 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
525 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
526 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
527 HeapFree( GetProcessHeap(), 0, cbItem
.pszText
);
530 static void dialog_choose_font(void)
535 HDC hDC
= GetDC(hMainWnd
);
537 ZeroMemory(&cf
, sizeof(cf
));
538 cf
.lStructSize
= sizeof(cf
);
539 cf
.hwndOwner
= hMainWnd
;
541 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
543 ZeroMemory(&fmt
, sizeof(fmt
));
544 fmt
.cbSize
= sizeof(fmt
);
546 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
547 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
548 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
549 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
550 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
551 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
552 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
553 cf
.rgbColors
= fmt
.crTextColor
;
557 ZeroMemory(&fmt
, sizeof(fmt
));
558 fmt
.cbSize
= sizeof(fmt
);
559 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
560 fmt
.yHeight
= cf
.iPointSize
* 2;
562 if(cf
.nFontType
& BOLD_FONTTYPE
)
563 fmt
.dwEffects
|= CFE_BOLD
;
564 if(cf
.nFontType
& ITALIC_FONTTYPE
)
565 fmt
.dwEffects
|= CFE_ITALIC
;
566 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
567 fmt
.dwEffects
|= CFE_UNDERLINE
;
568 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
569 fmt
.dwEffects
|= CFE_STRIKEOUT
;
571 fmt
.crTextColor
= cf
.rgbColors
;
573 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
574 set_font(cf
.lpLogFont
->lfFaceName
);
579 static int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
580 DWORD FontType
, LPARAM lParam
)
582 HWND hListWnd
= (HWND
) lParam
;
584 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
587 add_font(lpelfe
->lfFaceName
, FontType
, hListWnd
, (const NEWTEXTMETRICEXW
*)lpntme
);
593 static void populate_font_list(HWND hListWnd
)
595 HDC hdc
= GetDC(hMainWnd
);
597 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
600 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
601 *fontinfo
.lfFaceName
= '\0';
602 fontinfo
.lfPitchAndFamily
= 0;
604 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
605 (LPARAM
)hListWnd
, 0);
607 ZeroMemory(&fmt
, sizeof(fmt
));
608 fmt
.cbSize
= sizeof(fmt
);
609 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
610 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
613 static void update_window(void)
617 GetClientRect(hMainWnd
, &rect
);
619 OnSize(hMainWnd
, SIZE_RESTORED
, MAKELPARAM(rect
.right
, rect
.bottom
));
622 static BOOL
is_bar_visible(int bandId
)
624 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
627 static void store_bar_state(int bandId
, BOOL show
)
629 int formatIndex
= reg_formatindex(fileFormat
);
632 barState
[formatIndex
] |= (1 << bandId
);
634 barState
[formatIndex
] &= ~(1 << bandId
);
637 static void set_toolbar_state(int bandId
, BOOL show
)
639 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
641 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
643 if(bandId
== BANDID_TOOLBAR
)
645 REBARBANDINFOW rbbinfo
;
646 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
648 rbbinfo
.cbSize
= sizeof(rbbinfo
);
649 rbbinfo
.fMask
= RBBIM_STYLE
;
651 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
654 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
656 rbbinfo
.fStyle
|= RBBS_BREAK
;
658 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
661 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
|| bandId
== BANDID_RULER
)
662 store_bar_state(bandId
, show
);
665 static void set_statusbar_state(BOOL show
)
667 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
669 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
670 store_bar_state(BANDID_STATUSBAR
, show
);
673 static void set_bar_states(void)
675 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
676 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
677 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
678 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
679 set_toolbar_state(BANDID_RULER
, is_bar_visible(BANDID_RULER
));
680 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
685 static void preview_exit(HWND hMainWnd
)
687 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
688 HMENU hMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_MAINMENU
));
689 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
692 ShowWindow(hEditorWnd
, TRUE
);
694 close_preview(hMainWnd
);
696 SetMenu(hMainWnd
, hMenu
);
697 registry_read_filelist(hMainWnd
);
702 static void set_fileformat(WPARAM format
)
705 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
709 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
711 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
713 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
717 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
720 static void ShowOpenError(DWORD Code
)
726 case ERROR_ACCESS_DENIED
:
727 Message
= MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED
);
731 Message
= MAKEINTRESOURCEW(STRING_OPEN_FAILED
);
733 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
736 static void DoOpenFile(LPCWSTR szOpenFileName
)
742 WPARAM format
= SF_TEXT
;
744 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
745 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
746 if (hFile
== INVALID_HANDLE_VALUE
)
748 ShowOpenError(GetLastError());
752 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
753 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
755 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
757 format
= SF_TEXT
| SF_UNICODE
;
758 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
759 } else if(readOut
>= 5)
761 static const char header
[] = "{\\rtf";
762 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
764 if(!memcmp(header
, fileStart
, 5))
766 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
769 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
),
770 wszAppTitle
, MB_OK
| MB_ICONEXCLAMATION
);
775 es
.dwCookie
= (DWORD_PTR
)hFile
;
776 es
.pfnCallback
= stream_in
;
779 set_fileformat(format
);
780 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
784 SetFocus(hEditorWnd
);
786 set_caption(szOpenFileName
);
788 lstrcpyW(wszFileName
, szOpenFileName
);
789 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
790 registry_set_filelist(szOpenFileName
, hMainWnd
);
794 static void ShowWriteError(DWORD Code
)
800 case ERROR_ACCESS_DENIED
:
801 Message
= MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED
);
805 Message
= MAKEINTRESOURCEW(STRING_WRITE_FAILED
);
807 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
810 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
816 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
817 FILE_ATTRIBUTE_NORMAL
, NULL
);
819 if(hFile
== INVALID_HANDLE_VALUE
)
821 ShowWriteError(GetLastError());
825 if(format
== (SF_TEXT
| SF_UNICODE
))
827 static const BYTE unicode
[] = {0xff,0xfe};
829 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
831 if(writeOut
!= sizeof(unicode
))
838 stream
.dwCookie
= (DWORD_PTR
)hFile
;
839 stream
.pfnCallback
= stream_out
;
841 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
845 SetFocus(hEditorWnd
);
850 gt
.flags
= GTL_DEFAULT
;
853 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
857 lstrcpyW(wszFileName
, wszSaveFileName
);
858 set_caption(wszFileName
);
859 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
860 set_fileformat(format
);
863 static void DialogSaveFile(void)
867 WCHAR wszFile
[MAX_PATH
] = {'\0'};
868 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
870 ZeroMemory(&sfn
, sizeof(sfn
));
872 sfn
.lStructSize
= sizeof(sfn
);
873 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
874 sfn
.hwndOwner
= hMainWnd
;
875 sfn
.lpstrFilter
= wszFilter
;
876 sfn
.lpstrFile
= wszFile
;
877 sfn
.nMaxFile
= MAX_PATH
;
878 sfn
.lpstrDefExt
= wszDefExt
;
879 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
881 while(GetSaveFileNameW(&sfn
))
883 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
885 if(MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
886 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
891 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
896 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
902 static BOOL
prompt_save_changes(void)
907 gt
.flags
= GTL_NUMCHARS
;
909 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
913 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
918 LPWSTR displayFileName
;
923 displayFileName
= wszDefaultFileName
;
925 displayFileName
= file_basename(wszFileName
);
927 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
928 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
933 wsprintfW(text
, wszSaveChanges
, displayFileName
);
935 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
937 HeapFree(GetProcessHeap(), 0, text
);
946 DoSaveFile(wszFileName
, fileFormat
);
957 static void DialogOpenFile(void)
961 WCHAR wszFile
[MAX_PATH
] = {'\0'};
962 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
964 ZeroMemory(&ofn
, sizeof(ofn
));
966 ofn
.lStructSize
= sizeof(ofn
);
967 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
968 ofn
.hwndOwner
= hMainWnd
;
969 ofn
.lpstrFilter
= wszFilter
;
970 ofn
.lpstrFile
= wszFile
;
971 ofn
.nMaxFile
= MAX_PATH
;
972 ofn
.lpstrDefExt
= wszDefExt
;
973 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
975 if(GetOpenFileNameW(&ofn
))
977 if(prompt_save_changes())
978 DoOpenFile(ofn
.lpstrFile
);
982 static void dialog_about(void)
984 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
985 HICON icon
= LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
, 48, 48, LR_SHARED
);
986 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
989 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
995 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
998 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1000 sprintf(id
, "%d\n", (int)ps
->lParam
);
1001 SetWindowTextA(hIdWnd
, id
);
1002 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_NONE
)
1003 wrap
= IDC_PAGEFMT_WN
;
1004 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
1005 wrap
= IDC_PAGEFMT_WW
;
1006 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
1007 wrap
= IDC_PAGEFMT_WM
;
1010 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
,
1011 IDC_PAGEFMT_WM
, wrap
);
1013 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
1014 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
1015 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
1016 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
1017 if(barState
[ps
->lParam
] & (1 << BANDID_RULER
))
1018 CheckDlgButton(hWnd
, IDC_PAGEFMT_RU
, TRUE
);
1019 if(barState
[ps
->lParam
] & (1 << BANDID_STATUSBAR
))
1020 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1025 switch(LOWORD(wParam
))
1027 case IDC_PAGEFMT_WN
:
1028 case IDC_PAGEFMT_WW
:
1029 case IDC_PAGEFMT_WM
:
1030 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
, IDC_PAGEFMT_WM
,
1034 case IDC_PAGEFMT_TB
:
1035 case IDC_PAGEFMT_FB
:
1036 case IDC_PAGEFMT_RU
:
1037 case IDC_PAGEFMT_SB
:
1038 CheckDlgButton(hWnd
, LOWORD(wParam
),
1039 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1045 LPNMHDR header
= (LPNMHDR
)lParam
;
1046 if(header
->code
== PSN_APPLY
)
1048 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1052 GetWindowTextA(hIdWnd
, sid
, 4);
1054 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WN
))
1055 wordWrap
[id
] = ID_WORDWRAP_NONE
;
1056 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1057 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1058 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1059 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1061 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1062 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1064 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1066 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1067 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1069 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1071 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_RU
))
1072 barState
[id
] |= (1 << BANDID_RULER
);
1074 barState
[id
] &= ~(1 << BANDID_RULER
);
1076 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1077 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1079 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1087 static void dialog_viewproperties(void)
1089 PROPSHEETPAGEW psp
[2];
1090 PROPSHEETHEADERW psh
;
1092 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1093 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1095 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1096 psp
[0].dwFlags
= PSP_USETITLE
;
1097 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1098 psp
[0].pfnDlgProc
= formatopts_proc
;
1099 psp
[0].hInstance
= hInstance
;
1100 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1101 psp
[0].pfnCallback
= NULL
;
1102 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1103 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1105 psp
[i
].dwSize
= psp
[0].dwSize
;
1106 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1107 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1108 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1109 psp
[i
].hInstance
= psp
[0].hInstance
;
1110 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1111 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1112 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1115 psh
.dwSize
= sizeof(psh
);
1116 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1117 psh
.hwndParent
= hMainWnd
;
1118 psh
.hInstance
= hInstance
;
1119 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1120 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1121 U3(psh
).ppsp
= ppsp
;
1122 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1124 if(fileFormat
& SF_RTF
)
1125 U2(psh
).nStartPage
= 1;
1127 U2(psh
).nStartPage
= 0;
1128 PropertySheetW(&psh
);
1130 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1133 static void HandleCommandLine(LPWSTR cmdline
)
1138 /* skip white space */
1139 while (*cmdline
== ' ') cmdline
++;
1141 /* skip executable name */
1142 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1144 if (*cmdline
== delimiter
) cmdline
++;
1145 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1146 if (*cmdline
== delimiter
) cmdline
++;
1150 while (isspace(*cmdline
)) cmdline
++;
1152 if (*cmdline
== '-' || *cmdline
== '/')
1154 if (!cmdline
[2] || isspace(cmdline
[2]))
1165 /* a filename starting by / */
1172 /* file name is passed on the command line */
1173 if (cmdline
[0] == '"')
1176 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1178 DoOpenFile(cmdline
);
1179 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1183 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED
), wszAppTitle
, MB_OK
);
1186 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1188 if(pFr
->Flags
& FR_DIALOGTERM
)
1191 pFr
->Flags
= FR_FINDNEXT
;
1195 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1197 DWORD flags
= FR_DOWN
;
1199 static CHARRANGE cr
;
1204 HMENU hMenu
= GetMenu(hMainWnd
);
1207 mi
.cbSize
= sizeof(mi
);
1208 mi
.fMask
= MIIM_DATA
;
1210 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1212 gt
.flags
= GTL_NUMCHARS
;
1215 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1217 if(pFr
->lCustData
== -1)
1219 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1220 cr
.cpMin
= startPos
;
1221 pFr
->lCustData
= startPos
;
1223 if(cr
.cpMin
== length
)
1227 startPos
= pFr
->lCustData
;
1230 if(cr
.cpMax
> length
)
1238 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1240 if(pFr
->Flags
& FR_MATCHCASE
)
1241 flags
|= FR_MATCHCASE
;
1242 if(pFr
->Flags
& FR_WHOLEWORD
)
1243 flags
|= FR_WHOLEWORD
;
1245 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1249 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1251 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1252 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1254 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1260 pFr
->lCustData
= -1;
1261 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1262 MB_OK
| MB_ICONASTERISK
);
1265 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1267 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1268 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1270 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1271 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1273 if(pFr
->Flags
& FR_REPLACEALL
)
1274 handle_findmsg(pFr
);
1281 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1283 static WCHAR findBuffer
[MAX_STRING_LEN
];
1285 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1286 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1287 fr
->hwndOwner
= hMainWnd
;
1288 fr
->Flags
= FR_HIDEUPDOWN
;
1289 fr
->lpstrFindWhat
= findBuffer
;
1291 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1294 hFindWnd
= ReplaceTextW(fr
);
1296 hFindWnd
= FindTextW(fr
);
1299 static int current_units_to_twips(float number
)
1301 int twips
= (int)(number
* 1000.0 / (float)CENTMM_PER_INCH
* (float)TWIPS_PER_INCH
);
1305 static void append_current_units(LPWSTR buffer
)
1307 static const WCHAR space
[] = {' ', 0};
1308 lstrcatW(buffer
, space
);
1309 lstrcatW(buffer
, units_cmW
);
1312 static void number_with_units(LPWSTR buffer
, int number
)
1314 static const WCHAR fmt
[] = {'%','.','2','f',' ','%','s','\0'};
1315 float converted
= (float)number
/ (float)TWIPS_PER_INCH
*(float)CENTMM_PER_INCH
/ 1000.0;
1317 wsprintfW(buffer
, fmt
, converted
, units_cmW
);
1320 static BOOL
get_comboexlist_selection(HWND hComboEx
, LPWSTR wszBuffer
, UINT bufferLength
)
1322 COMBOBOXEXITEMW cbItem
;
1323 COMBOBOXINFO cbInfo
;
1327 hCombo
= (HWND
)SendMessage(hComboEx
, CBEM_GETCOMBOCONTROL
, 0, 0);
1330 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
1331 result
= SendMessage(hCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)&cbInfo
);
1334 hList
= cbInfo
.hwndList
;
1335 idx
= SendMessage(hList
, LB_GETCURSEL
, 0, 0);
1339 ZeroMemory(&cbItem
, sizeof(cbItem
));
1340 cbItem
.mask
= CBEIF_TEXT
;
1342 cbItem
.pszText
= wszBuffer
;
1343 cbItem
.cchTextMax
= bufferLength
-1;
1344 result
= SendMessageW(hComboEx
, CBEM_GETITEM
, 0, (LPARAM
)&cbItem
);
1349 static INT_PTR CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1355 WCHAR buffer
[MAX_STRING_LEN
];
1357 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1360 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1362 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1363 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1365 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1366 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1367 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1369 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1374 switch(LOWORD(wParam
))
1379 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1381 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1385 WCHAR buffer
[MAX_STRING_LEN
];
1386 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1387 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1393 EndDialog(hWnd
, wParam
);
1400 static INT_PTR CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1406 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1407 WCHAR buffer
[MAX_STRING_LEN
];
1408 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1410 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1411 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1412 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1413 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1414 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
1415 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1417 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1422 switch(LOWORD(wParam
))
1427 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1428 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1431 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1436 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1443 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1445 static const WORD ALIGNMENT_VALUES
[] = {PFA_LEFT
, PFA_RIGHT
, PFA_CENTER
};
1451 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
1453 WCHAR buffer
[MAX_STRING_LEN
];
1454 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1455 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1456 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1457 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1461 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1463 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1464 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1466 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1467 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1469 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1471 pf
.cbSize
= sizeof(pf
);
1472 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1474 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1476 if(pf
.wAlignment
== PFA_RIGHT
)
1478 else if(pf
.wAlignment
== PFA_CENTER
)
1481 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1483 number_with_units(buffer
, pf
.dxStartIndent
+ pf
.dxOffset
);
1484 SetWindowTextW(hLeftWnd
, buffer
);
1485 number_with_units(buffer
, pf
.dxRightIndent
);
1486 SetWindowTextW(hRightWnd
, buffer
);
1487 number_with_units(buffer
, -pf
.dxOffset
);
1488 SetWindowTextW(hFirstWnd
, buffer
);
1493 switch(LOWORD(wParam
))
1497 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1498 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1499 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1500 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1501 WCHAR buffer
[MAX_STRING_LEN
];
1507 index
= SendMessageW(hListWnd
, CB_GETCURSEL
, 0, 0);
1508 pf
.wAlignment
= ALIGNMENT_VALUES
[index
];
1510 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1511 if(number_from_string(buffer
, &num
, TRUE
))
1513 pf
.dxOffset
= current_units_to_twips(num
);
1514 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1515 if(number_from_string(buffer
, &num
, TRUE
))
1517 pf
.dxRightIndent
= current_units_to_twips(num
);
1518 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1519 if(number_from_string(buffer
, &num
, TRUE
))
1521 pf
.dxStartIndent
= current_units_to_twips(num
);
1525 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1526 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1530 if (pf
.dxOffset
+ pf
.dxStartIndent
< 0
1531 && pf
.dxStartIndent
< 0)
1533 /* The first line is before the left edge, so
1534 * make sure it is at the left edge. */
1535 pf
.dxOffset
= -pf
.dxStartIndent
;
1536 } else if (pf
.dxOffset
< 0) {
1537 /* The second and following lines are before
1538 * the left edge, so set it to be at the left
1539 * edge, and adjust the first line since it
1540 * is relative to it. */
1541 pf
.dxStartIndent
= max(pf
.dxStartIndent
+ pf
.dxOffset
, 0);
1544 /* Internally the dxStartIndent is the absolute
1545 * offset for the first line and dxOffset is
1546 * to it value as opposed how it is displayed with
1547 * the first line being the relative value.
1548 * These two lines make the adjustments. */
1549 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1550 pf
.dxOffset
= pf
.dxOffset
- pf
.dxStartIndent
;
1552 pf
.cbSize
= sizeof(pf
);
1553 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1555 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1561 EndDialog(hWnd
, wParam
);
1568 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1574 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1576 WCHAR buffer
[MAX_STRING_LEN
];
1579 pf
.cbSize
= sizeof(pf
);
1580 pf
.dwMask
= PFM_TABSTOPS
;
1581 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1582 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1584 for(i
= 0; i
< pf
.cTabCount
; i
++)
1586 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1587 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1594 switch(LOWORD(wParam
))
1598 HWND hTabWnd
= (HWND
)lParam
;
1599 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1600 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1601 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1603 if(GetWindowTextLengthW(hTabWnd
))
1604 EnableWindow(hAddWnd
, TRUE
);
1606 EnableWindow(hAddWnd
, FALSE
);
1608 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1610 EnableWindow(hEmptyWnd
, TRUE
);
1612 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1613 EnableWindow(hDelWnd
, FALSE
);
1615 EnableWindow(hDelWnd
, TRUE
);
1618 EnableWindow(hEmptyWnd
, FALSE
);
1625 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1626 WCHAR buffer
[MAX_STRING_LEN
];
1628 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1629 append_current_units(buffer
);
1631 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1635 if(!number_from_string(buffer
, &number
, TRUE
))
1637 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1638 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1641 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1642 SetWindowTextW(hTabWnd
, 0);
1651 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1653 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1655 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1661 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1662 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1669 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1671 WCHAR buffer
[MAX_STRING_LEN
];
1675 pf
.cbSize
= sizeof(pf
);
1676 pf
.dwMask
= PFM_TABSTOPS
;
1678 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1679 (LPARAM
)&buffer
) != CB_ERR
&&
1680 i
< MAX_TAB_STOPS
; i
++)
1682 number_from_string(buffer
, &number
, TRUE
);
1683 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
1686 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1690 EndDialog(hWnd
, wParam
);
1697 static int context_menu(LPARAM lParam
)
1699 int x
= (int)(short)LOWORD(lParam
);
1700 int y
= (int)(short)HIWORD(lParam
);
1701 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1705 int from
= 0, to
= 0;
1707 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1708 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
1709 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1714 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1715 x
, y
, 0, hMainWnd
, 0);
1720 static LRESULT
OnCreate( HWND hWnd
)
1722 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
, hRulerWnd
;
1723 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1726 int nStdBitmaps
= 0;
1729 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1730 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1732 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1734 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1735 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1736 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1738 rbi
.cbSize
= sizeof(rbi
);
1741 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1744 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1746 1, hInstance
, IDB_TOOLBAR
,
1748 24, 24, 16, 16, sizeof(TBBUTTON
));
1750 ab
.hInst
= HINST_COMMCTRL
;
1751 ab
.nID
= IDB_STD_SMALL_COLOR
;
1752 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1754 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1755 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1756 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1757 AddSeparator(hToolBarWnd
);
1758 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1759 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1760 AddSeparator(hToolBarWnd
);
1761 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1762 AddSeparator(hToolBarWnd
);
1763 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1764 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1765 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1766 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1767 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1768 AddSeparator(hToolBarWnd
);
1769 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1771 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1773 rbb
.cbSize
= sizeof(rbb
);
1774 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1775 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1777 rbb
.hwndChild
= hToolBarWnd
;
1779 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1780 rbb
.wID
= BANDID_TOOLBAR
;
1782 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1784 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1785 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1786 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1788 rbb
.hwndChild
= hFontListWnd
;
1790 rbb
.wID
= BANDID_FONTLIST
;
1792 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1794 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1795 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1796 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1798 rbb
.hwndChild
= hSizeListWnd
;
1800 rbb
.fStyle
^= RBBS_BREAK
;
1801 rbb
.wID
= BANDID_SIZELIST
;
1803 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1805 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1806 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1807 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1809 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1810 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1811 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1812 AddSeparator(hFormatBarWnd
);
1813 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
1814 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
1815 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
1816 AddSeparator(hFormatBarWnd
);
1817 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
1819 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
1821 rbb
.hwndChild
= hFormatBarWnd
;
1822 rbb
.wID
= BANDID_FORMATBAR
;
1824 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1826 hRulerWnd
= CreateWindowExW(0, WC_STATICW
, NULL
, WS_VISIBLE
| WS_CHILD
,
1827 0, 0, 200, 10, hReBarWnd
, (HMENU
)IDC_RULER
, hInstance
, NULL
);
1830 rbb
.hwndChild
= hRulerWnd
;
1831 rbb
.wID
= BANDID_RULER
;
1832 rbb
.fStyle
|= RBBS_BREAK
;
1834 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1836 hDLL
= LoadLibraryW(wszRichEditDll
);
1839 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
1840 MB_OK
| MB_ICONEXCLAMATION
);
1844 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
1845 WS_CHILD
|WS_VISIBLE
|ES_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
1846 |ES_WANTRETURN
|WS_VSCROLL
|ES_NOHIDESEL
|WS_HSCROLL
,
1847 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
1851 fprintf(stderr
, "Error code %u\n", GetLastError());
1856 SetFocus(hEditorWnd
);
1857 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
1861 populate_font_list(hFontListWnd
);
1862 populate_size_list(hSizeListWnd
);
1864 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1866 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
1868 registry_read_filelist(hWnd
);
1869 registry_read_formatopts_all(barState
, wordWrap
);
1870 registry_read_options();
1871 DragAcceptFiles(hWnd
, TRUE
);
1876 static LRESULT
OnUser( HWND hWnd
)
1878 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1879 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1880 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
1881 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
1887 ZeroMemory(&fmt
, sizeof(fmt
));
1888 fmt
.cbSize
= sizeof(fmt
);
1890 ZeroMemory(&pf
, sizeof(pf
));
1891 pf
.cbSize
= sizeof(pf
);
1893 gt
.flags
= GTL_NUMCHARS
;
1896 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
1897 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
1899 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
1901 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1902 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
1903 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
1904 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
1905 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
1906 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
1907 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
1909 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
1910 (fmt
.dwEffects
& CFE_BOLD
));
1911 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
1912 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
1913 (fmt
.dwEffects
& CFE_ITALIC
));
1914 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
1915 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
1916 (fmt
.dwEffects
& CFE_UNDERLINE
));
1917 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
1919 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1920 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
1921 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
1922 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
1924 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
1928 static LRESULT
OnNotify( HWND hWnd
, LPARAM lParam
)
1930 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1931 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1932 NMHDR
*pHdr
= (NMHDR
*)lParam
;
1933 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
1934 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
1936 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
1938 if (pHdr
->code
== CBEN_ENDEDITW
)
1940 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
1941 if(pHdr
->hwndFrom
== hwndFontList
)
1943 on_fontlist_modified((LPWSTR
)endEdit
->szText
);
1944 } else if (pHdr
->hwndFrom
== hwndSizeList
)
1946 on_sizelist_modified(hwndFontList
,(LPWSTR
)endEdit
->szText
);
1952 if (pHdr
->hwndFrom
!= hwndEditor
)
1955 if (pHdr
->code
== EN_SELCHANGE
)
1957 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
1962 sprintf( buf
,"selection = %d..%d, line count=%ld",
1963 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
1964 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
1965 SetWindowTextA(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
1966 SendMessage(hWnd
, WM_USER
, 0, 0);
1972 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1974 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1975 static FINDREPLACEW findreplace
;
1977 if ((HWND
)lParam
== hwndEditor
)
1980 switch(LOWORD(wParam
))
1984 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
1989 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1990 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
1993 if(ret
!= ID_NEWFILE_ABORT
)
1995 if(prompt_save_changes())
2000 wszFileName
[0] = '\0';
2004 st
.flags
= ST_DEFAULT
;
2006 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
2008 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2009 set_fileformat(ret
);
2023 DoSaveFile(wszFileName
, fileFormat
);
2028 case ID_FILE_SAVEAS
:
2032 case ID_FILE_RECENT1
:
2033 case ID_FILE_RECENT2
:
2034 case ID_FILE_RECENT3
:
2035 case ID_FILE_RECENT4
:
2037 HMENU hMenu
= GetMenu(hWnd
);
2040 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2041 mi
.fMask
= MIIM_DATA
;
2042 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2043 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2048 dialog_find(&findreplace
, FALSE
);
2052 handle_findmsg(&findreplace
);
2056 dialog_find(&findreplace
, TRUE
);
2059 case ID_FONTSETTINGS
:
2060 dialog_choose_font();
2064 dialog_print(hWnd
, wszFileName
);
2065 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2068 case ID_PRINT_QUICK
:
2069 print_quick(wszFileName
);
2070 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2075 int index
= reg_formatindex(fileFormat
);
2076 DWORD tmp
= barState
[index
];
2077 barState
[index
] = 0;
2079 barState
[index
] = tmp
;
2080 ShowWindow(hEditorWnd
, FALSE
);
2082 init_preview(hWnd
, wszFileName
);
2084 SetMenu(hWnd
, NULL
);
2085 InvalidateRect(0, 0, TRUE
);
2090 dialog_printsetup(hWnd
);
2091 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2094 case ID_FORMAT_BOLD
:
2095 case ID_FORMAT_ITALIC
:
2096 case ID_FORMAT_UNDERLINE
:
2099 int effects
= CFE_BOLD
;
2101 ZeroMemory(&fmt
, sizeof(fmt
));
2102 fmt
.cbSize
= sizeof(fmt
);
2103 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2105 fmt
.dwMask
= CFM_BOLD
;
2107 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2109 effects
= CFE_ITALIC
;
2110 fmt
.dwMask
= CFM_ITALIC
;
2111 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2113 effects
= CFE_UNDERLINE
;
2114 fmt
.dwMask
= CFM_UNDERLINE
;
2117 fmt
.dwEffects
^= effects
;
2119 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2124 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2128 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2132 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2136 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2139 case ID_EDIT_SELECTALL
:
2141 CHARRANGE range
= {0, -1};
2142 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2143 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2147 case ID_EDIT_GETTEXT
:
2149 int nLen
= GetWindowTextLengthW(hwndEditor
);
2150 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2153 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2154 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2156 HeapFree( GetProcessHeap(), 0, data
);
2157 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2159 tr
.chrg
.cpMax
= nLen
;
2160 tr
.lpstrText
= data
;
2161 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2162 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2163 HeapFree( GetProcessHeap(), 0, data
);
2165 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2169 case ID_EDIT_CHARFORMAT
:
2170 case ID_EDIT_DEFCHARFORMAT
:
2174 ZeroMemory(&cf
, sizeof(cf
));
2175 cf
.cbSize
= sizeof(cf
);
2177 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2178 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2182 case ID_EDIT_PARAFORMAT
:
2185 ZeroMemory(&pf
, sizeof(pf
));
2186 pf
.cbSize
= sizeof(pf
);
2187 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2191 case ID_EDIT_SELECTIONINFO
:
2193 CHARRANGE range
= {0, -1};
2197 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2198 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2199 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2200 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2201 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2202 MessageBoxW(hWnd
, data
, wszAppTitle
, MB_OK
);
2203 HeapFree( GetProcessHeap(), 0, data
);
2204 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2208 case ID_EDIT_READONLY
:
2210 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2211 if (nStyle
& ES_READONLY
)
2212 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2214 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2218 case ID_EDIT_MODIFIED
:
2219 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2220 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2222 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2226 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2230 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2237 pf
.cbSize
= sizeof(pf
);
2238 pf
.dwMask
= PFM_NUMBERING
;
2239 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2241 pf
.dwMask
|= PFM_OFFSET
;
2243 if(pf
.wNumbering
== PFN_BULLET
)
2249 pf
.wNumbering
= PFN_BULLET
;
2253 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2258 case ID_ALIGN_CENTER
:
2259 case ID_ALIGN_RIGHT
:
2263 pf
.cbSize
= sizeof(pf
);
2264 pf
.dwMask
= PFM_ALIGNMENT
;
2265 switch(LOWORD(wParam
)) {
2266 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2267 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2268 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2270 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2275 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2279 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2282 case ID_TOGGLE_TOOLBAR
:
2283 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2287 case ID_TOGGLE_FORMATBAR
:
2288 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2289 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2290 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2294 case ID_TOGGLE_STATUSBAR
:
2295 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2299 case ID_TOGGLE_RULER
:
2300 set_toolbar_state(BANDID_RULER
, !is_bar_visible(BANDID_RULER
));
2306 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2307 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, datetime_proc
);
2313 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2314 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
2321 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2322 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2330 case ID_VIEWPROPERTIES
:
2331 dialog_viewproperties();
2335 if (HIWORD(wParam
) == CBN_SELENDOK
)
2337 WCHAR buffer
[LF_FACESIZE
];
2338 HWND hwndFontList
= (HWND
)lParam
;
2339 get_comboexlist_selection(hwndFontList
, buffer
, LF_FACESIZE
);
2340 on_fontlist_modified(buffer
);
2345 if (HIWORD(wParam
) == CBN_SELENDOK
)
2347 WCHAR buffer
[MAX_STRING_LEN
+1];
2348 HWND hwndSizeList
= (HWND
)lParam
;
2349 get_comboexlist_selection(hwndSizeList
, buffer
, MAX_STRING_LEN
+1);
2350 on_sizelist_modified(hwndSizeList
, buffer
);
2355 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2361 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
)
2363 HMENU hMenu
= (HMENU
)wParam
;
2364 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2365 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2367 int nAlignment
= -1;
2373 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2374 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2375 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2377 pf
.cbSize
= sizeof(PARAFORMAT
);
2378 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2379 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2380 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2381 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2382 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2383 if (pf
.dwMask
& PFM_ALIGNMENT
)
2384 nAlignment
= pf
.wAlignment
;
2385 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2386 MF_CHECKED
: MF_UNCHECKED
);
2387 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2388 MF_CHECKED
: MF_UNCHECKED
);
2389 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2390 MF_CHECKED
: MF_UNCHECKED
);
2391 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2392 MF_CHECKED
: MF_UNCHECKED
));
2393 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2394 MF_ENABLED
: MF_GRAYED
);
2395 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2396 MF_ENABLED
: MF_GRAYED
);
2398 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2399 MF_CHECKED
: MF_UNCHECKED
);
2401 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2402 MF_CHECKED
: MF_UNCHECKED
);
2404 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2405 MF_CHECKED
: MF_UNCHECKED
);
2407 CheckMenuItem(hMenu
, ID_TOGGLE_RULER
, MF_BYCOMMAND
|(is_bar_visible(BANDID_RULER
)) ? MF_CHECKED
: MF_UNCHECKED
);
2409 gt
.flags
= GTL_NUMCHARS
;
2411 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2412 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2414 mi
.cbSize
= sizeof(mi
);
2415 mi
.fMask
= MIIM_DATA
;
2417 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2419 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2420 MF_ENABLED
: MF_GRAYED
));
2422 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2427 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2429 int nStatusSize
= 0;
2431 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2432 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2433 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2434 HWND hRulerWnd
= GetDlgItem(hWnd
, IDC_RULER
);
2435 int rebarHeight
= 0;
2439 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2440 if (IsWindowVisible(hwndStatusBar
))
2442 GetClientRect(hwndStatusBar
, &rc
);
2443 nStatusSize
= rc
.bottom
- rc
.top
;
2451 rebarHeight
= SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
2453 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2457 GetClientRect(hWnd
, &rc
);
2458 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2461 redraw_ruler(hRulerWnd
);
2463 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2466 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2468 if(msg
== ID_FINDMSGSTRING
)
2469 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2474 return OnCreate( hWnd
);
2477 return OnUser( hWnd
);
2480 return OnNotify( hWnd
, lParam
);
2483 if(preview_isactive())
2485 return preview_command( hWnd
, wParam
);
2488 return OnCommand( hWnd
, wParam
, lParam
);
2495 if(preview_isactive())
2498 } else if(prompt_save_changes())
2500 registry_set_options(hMainWnd
);
2501 registry_set_formatopts_all(barState
);
2508 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2511 case WM_INITMENUPOPUP
:
2512 return OnInitPopupMenu( hWnd
, wParam
);
2515 return OnSize( hWnd
, wParam
, lParam
);
2517 case WM_CONTEXTMENU
:
2518 if((HWND
)wParam
== hEditorWnd
)
2519 return context_menu(lParam
);
2521 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2525 WCHAR file
[MAX_PATH
];
2526 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2527 DragFinish((HDROP
)wParam
);
2529 if(prompt_save_changes())
2534 if(preview_isactive())
2535 return print_preview(hWnd
);
2537 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2540 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2546 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int nCmdShow
)
2548 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2553 UINT_PTR hPrevRulerProc
;
2557 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2558 'T','A','B','L','E','\0'};
2560 InitCommonControlsEx(&classes
);
2562 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2564 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2565 wc
.lpfnWndProc
= WndProc
;
2568 wc
.hInstance
= hInstance
;
2569 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2570 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2571 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2572 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2573 wc
.lpszClassName
= wszMainWndClass
;
2574 RegisterClassW(&wc
);
2576 registry_read_winrect(&rc
);
2577 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2578 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2579 registry_read_maximized(&bMaximized
);
2580 if ((nCmdShow
== SW_SHOWNORMAL
|| nCmdShow
== SW_SHOWDEFAULT
)
2582 nCmdShow
= SW_SHOWMAXIMIZED
;
2583 ShowWindow(hMainWnd
, nCmdShow
);
2587 set_fileformat(SF_RTF
);
2588 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2589 get_default_printer_opts();
2590 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2592 hRulerWnd
= GetDlgItem(GetDlgItem(hMainWnd
, IDC_REBAR
), IDC_RULER
);
2593 SendMessageW(GetDlgItem(hMainWnd
, IDC_EDITOR
), EM_POSFROMCHAR
, (WPARAM
)&EditPoint
, 0);
2594 hPrevRulerProc
= SetWindowLongPtrW(hRulerWnd
, GWLP_WNDPROC
, (UINT_PTR
)ruler_proc
);
2595 SendMessageW(hRulerWnd
, WM_USER
, (WPARAM
)&EditPoint
, hPrevRulerProc
);
2597 HandleCommandLine(GetCommandLineW());
2599 while(GetMessageW(&msg
,0,0,0))
2601 if (IsDialogMessage(hFindWnd
, &msg
))
2604 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2606 TranslateMessage(&msg
);
2607 DispatchMessageW(&msg
);
2608 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2609 SendMessageW(hMainWnd
, WM_USER
, 0, 0);