2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2007-2008 by Alexander N. Sørnes <alex@thehandofagony.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define _WIN32_IE 0x0400
39 #include "wine/unicode.h"
42 #ifdef NONAMELESSUNION
53 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
55 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
57 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
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 /* Show a message box with resource strings */
119 static int MessageBoxWithResStringW(HWND hWnd
, LPCWSTR lpText
, LPCWSTR lpCaption
, UINT uType
)
121 MSGBOXPARAMSW params
;
123 params
.cbSize
= sizeof(params
);
124 params
.hwndOwner
= hWnd
;
125 params
.hInstance
= GetModuleHandleW(0);
126 params
.lpszText
= lpText
;
127 params
.lpszCaption
= lpCaption
;
128 params
.dwStyle
= uType
;
129 params
.lpszIcon
= NULL
;
130 params
.dwContextHelpId
= 0;
131 params
.lpfnMsgBoxCallback
= NULL
;
132 params
.dwLanguageId
= 0;
133 return MessageBoxIndirectW(¶ms
);
137 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
141 ZeroMemory(&button
, sizeof(button
));
142 button
.iBitmap
= nImage
;
143 button
.idCommand
= nCommand
;
144 button
.fsState
= TBSTATE_ENABLED
;
145 button
.fsStyle
= TBSTYLE_BUTTON
;
148 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
151 static void AddSeparator(HWND hwndToolBar
)
155 ZeroMemory(&button
, sizeof(button
));
157 button
.idCommand
= 0;
159 button
.fsStyle
= TBSTYLE_SEP
;
162 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
165 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
167 HANDLE hFile
= (HANDLE
)cookie
;
170 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
178 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
182 HANDLE hFile
= (HANDLE
)cookie
;
184 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
186 if(!ret
|| (cb
!= written
))
194 LPWSTR
file_basename(LPWSTR path
)
196 LPWSTR pos
= path
+ lstrlenW(path
);
200 if(*pos
== '\\' || *pos
== '/')
210 static void set_caption(LPCWSTR wszNewFileName
)
212 static const WCHAR wszSeparator
[] = {' ','-',' '};
217 wszNewFileName
= wszDefaultFileName
;
219 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
221 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
222 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
227 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
228 length
+= lstrlenW(wszNewFileName
);
229 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
230 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
231 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
233 SetWindowTextW(hMainWnd
, wszCaption
);
235 HeapFree(GetProcessHeap(), 0, wszCaption
);
238 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
245 while(*endptr
== ' ')
249 return *endptr
== '\0';
251 /* FIXME: Allow other units and convert between them */
252 if(!lstrcmpA(endptr
, units_cmA
))
255 return *endptr
== '\0';
258 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
261 char buffer
[MAX_STRING_LEN
];
262 char *endptr
= buffer
;
264 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
267 ret
= strtod(buffer
, &endptr
);
269 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| !validate_endptr(endptr
, units
))
279 static void set_size(float size
)
283 ZeroMemory(&fmt
, sizeof(fmt
));
284 fmt
.cbSize
= sizeof(fmt
);
285 fmt
.dwMask
= CFM_SIZE
;
286 fmt
.yHeight
= (int)(size
* 20.0);
287 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
290 static void on_sizelist_modified(HWND hwndSizeList
, LPWSTR wszNewFontSize
)
292 WCHAR sizeBuffer
[MAX_STRING_LEN
];
295 ZeroMemory(&format
, sizeof(format
));
296 format
.cbSize
= sizeof(format
);
297 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
299 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
300 if(lstrcmpW(sizeBuffer
, wszNewFontSize
))
303 if(number_from_string(wszNewFontSize
, &size
, FALSE
)
309 SetWindowTextW(hwndSizeList
, sizeBuffer
);
310 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
311 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
316 static void add_size(HWND hSizeListWnd
, unsigned size
)
319 COMBOBOXEXITEMW cbItem
;
320 cbItem
.mask
= CBEIF_TEXT
;
323 wsprintfW(buffer
, stringFormat
, size
);
324 cbItem
.pszText
= buffer
;
325 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
328 static void populate_size_list(HWND hSizeListWnd
)
330 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
331 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
332 COMBOBOXEXITEMW cbFontItem
;
334 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
335 HDC hdc
= GetDC(hMainWnd
);
336 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
341 ZeroMemory(&fmt
, sizeof(fmt
));
342 fmt
.cbSize
= sizeof(fmt
);
343 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
345 cbFontItem
.mask
= CBEIF_LPARAM
;
346 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
347 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
349 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
351 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
353 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
355 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
356 GetDeviceCaps(hdc
, LOGPIXELSY
)));
359 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
360 add_size(hSizeListWnd
, choices
[i
]);
363 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
364 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
367 static void update_size_list(void)
369 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
370 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
371 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
372 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
375 ZeroMemory(&fmt
, sizeof(fmt
));
376 fmt
.cbSize
= sizeof(fmt
);
378 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
380 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
381 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
383 if(lstrcmpW(fontSize
, sizeBuffer
))
384 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
387 static void update_font_list(void)
389 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
390 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
391 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
392 WCHAR fontName
[MAX_STRING_LEN
];
395 ZeroMemory(&fmt
, sizeof(fmt
));
396 fmt
.cbSize
= sizeof(fmt
);
398 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
399 if (!SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
)) return;
401 if(lstrcmpW(fontName
, fmt
.szFaceName
))
403 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
404 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
411 static void clear_formatting(void)
415 pf
.cbSize
= sizeof(pf
);
416 pf
.dwMask
= PFM_ALIGNMENT
;
417 pf
.wAlignment
= PFA_LEFT
;
418 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
421 static int fileformat_number(WPARAM format
)
425 if(format
== SF_TEXT
)
428 } else if (format
== (SF_TEXT
| SF_UNICODE
))
435 static WPARAM
fileformat_flags(int format
)
437 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
439 return flags
[format
];
442 static void set_font(LPCWSTR wszFaceName
)
444 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
445 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
446 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
447 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
450 ZeroMemory(&fmt
, sizeof(fmt
));
452 fmt
.cbSize
= sizeof(fmt
);
453 fmt
.dwMask
= CFM_FACE
;
455 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
457 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
459 populate_size_list(hSizeListWnd
);
461 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)wszFaceName
);
464 static void set_default_font(void)
466 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
467 'R','o','m','a','n',0};
468 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
472 ZeroMemory(&fmt
, sizeof(fmt
));
474 fmt
.cbSize
= sizeof(fmt
);
475 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
478 if(fileFormat
& SF_RTF
)
481 font
= plainTextFont
;
483 lstrcpyW(fmt
.szFaceName
, font
);
485 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
488 static void on_fontlist_modified(LPWSTR wszNewFaceName
)
491 ZeroMemory(&format
, sizeof(format
));
492 format
.cbSize
= sizeof(format
);
493 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
495 if(lstrcmpW(format
.szFaceName
, wszNewFaceName
))
496 set_font(wszNewFaceName
);
499 static void add_font(LPCWSTR fontName
, DWORD fontType
, HWND hListWnd
, const NEWTEXTMETRICEXW
*ntmc
)
501 COMBOBOXEXITEMW cbItem
;
502 WCHAR buffer
[MAX_PATH
];
505 cbItem
.mask
= CBEIF_TEXT
;
506 cbItem
.pszText
= buffer
;
507 cbItem
.cchTextMax
= MAX_STRING_LEN
;
510 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
512 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
517 cbItem
.pszText
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName
) + 1)*sizeof(WCHAR
) );
518 lstrcpyW( cbItem
.pszText
, fontName
);
520 cbItem
.mask
|= CBEIF_LPARAM
;
521 if(fontType
& RASTER_FONTTYPE
)
522 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
524 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
525 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
526 HeapFree( GetProcessHeap(), 0, cbItem
.pszText
);
529 static void dialog_choose_font(void)
534 HDC hDC
= GetDC(hMainWnd
);
536 ZeroMemory(&cf
, sizeof(cf
));
537 cf
.lStructSize
= sizeof(cf
);
538 cf
.hwndOwner
= hMainWnd
;
540 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
542 ZeroMemory(&fmt
, sizeof(fmt
));
543 fmt
.cbSize
= sizeof(fmt
);
545 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
546 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
547 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
548 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
549 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
550 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
551 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
552 cf
.rgbColors
= fmt
.crTextColor
;
556 ZeroMemory(&fmt
, sizeof(fmt
));
557 fmt
.cbSize
= sizeof(fmt
);
558 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
559 fmt
.yHeight
= cf
.iPointSize
* 2;
561 if(cf
.nFontType
& BOLD_FONTTYPE
)
562 fmt
.dwEffects
|= CFE_BOLD
;
563 if(cf
.nFontType
& ITALIC_FONTTYPE
)
564 fmt
.dwEffects
|= CFE_ITALIC
;
565 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
566 fmt
.dwEffects
|= CFE_UNDERLINE
;
567 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
568 fmt
.dwEffects
|= CFE_STRIKEOUT
;
570 fmt
.crTextColor
= cf
.rgbColors
;
572 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
573 set_font(cf
.lpLogFont
->lfFaceName
);
578 static int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
579 DWORD FontType
, LPARAM lParam
)
581 HWND hListWnd
= (HWND
) lParam
;
583 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
586 add_font(lpelfe
->lfFaceName
, FontType
, hListWnd
, (const NEWTEXTMETRICEXW
*)lpntme
);
592 static void populate_font_list(HWND hListWnd
)
594 HDC hdc
= GetDC(hMainWnd
);
596 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
599 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
600 *fontinfo
.lfFaceName
= '\0';
601 fontinfo
.lfPitchAndFamily
= 0;
603 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
604 (LPARAM
)hListWnd
, 0);
606 ZeroMemory(&fmt
, sizeof(fmt
));
607 fmt
.cbSize
= sizeof(fmt
);
608 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
609 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
612 static void update_window(void)
616 GetClientRect(hMainWnd
, &rect
);
618 OnSize(hMainWnd
, SIZE_RESTORED
, MAKELPARAM(rect
.right
, rect
.bottom
));
621 static BOOL
is_bar_visible(int bandId
)
623 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
626 static void store_bar_state(int bandId
, BOOL show
)
628 int formatIndex
= reg_formatindex(fileFormat
);
631 barState
[formatIndex
] |= (1 << bandId
);
633 barState
[formatIndex
] &= ~(1 << bandId
);
636 static void set_toolbar_state(int bandId
, BOOL show
)
638 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
640 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
642 if(bandId
== BANDID_TOOLBAR
)
644 REBARBANDINFOW rbbinfo
;
645 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
647 rbbinfo
.cbSize
= REBARBANDINFOW_V6_SIZE
;
648 rbbinfo
.fMask
= RBBIM_STYLE
;
650 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
653 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
655 rbbinfo
.fStyle
|= RBBS_BREAK
;
657 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
660 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
|| bandId
== BANDID_RULER
)
661 store_bar_state(bandId
, show
);
664 static void set_statusbar_state(BOOL show
)
666 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
668 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
669 store_bar_state(BANDID_STATUSBAR
, show
);
672 static void set_bar_states(void)
674 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
675 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
676 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
677 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
678 set_toolbar_state(BANDID_RULER
, is_bar_visible(BANDID_RULER
));
679 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
684 static void preview_exit(HWND hMainWnd
)
686 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
687 HMENU hMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_MAINMENU
));
688 HWND hEditorWnd
= GetDlgItem(hMainWnd
, IDC_EDITOR
);
691 ShowWindow(hEditorWnd
, TRUE
);
693 close_preview(hMainWnd
);
695 SetMenu(hMainWnd
, hMenu
);
696 registry_read_filelist(hMainWnd
);
701 static void set_fileformat(WPARAM format
)
704 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
708 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
710 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
712 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
716 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
719 static void ShowOpenError(DWORD Code
)
725 case ERROR_ACCESS_DENIED
:
726 Message
= MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED
);
730 Message
= MAKEINTRESOURCEW(STRING_OPEN_FAILED
);
732 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
735 static void DoOpenFile(LPCWSTR szOpenFileName
)
741 WPARAM format
= SF_TEXT
;
743 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
744 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
745 if (hFile
== INVALID_HANDLE_VALUE
)
747 ShowOpenError(GetLastError());
751 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
752 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
754 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
756 format
= SF_TEXT
| SF_UNICODE
;
757 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
758 } else if(readOut
>= 5)
760 static const char header
[] = "{\\rtf";
761 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
763 if(!memcmp(header
, fileStart
, 5))
765 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
768 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
),
769 wszAppTitle
, MB_OK
| MB_ICONEXCLAMATION
);
774 es
.dwCookie
= (DWORD_PTR
)hFile
;
775 es
.pfnCallback
= stream_in
;
778 set_fileformat(format
);
779 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
783 SetFocus(hEditorWnd
);
785 set_caption(szOpenFileName
);
787 lstrcpyW(wszFileName
, szOpenFileName
);
788 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
789 registry_set_filelist(szOpenFileName
, hMainWnd
);
793 static void ShowWriteError(DWORD Code
)
799 case ERROR_ACCESS_DENIED
:
800 Message
= MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED
);
804 Message
= MAKEINTRESOURCEW(STRING_WRITE_FAILED
);
806 MessageBoxW(hMainWnd
, Message
, wszAppTitle
, MB_ICONEXCLAMATION
| MB_OK
);
809 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
815 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
816 FILE_ATTRIBUTE_NORMAL
, NULL
);
818 if(hFile
== INVALID_HANDLE_VALUE
)
820 ShowWriteError(GetLastError());
824 if(format
== (SF_TEXT
| SF_UNICODE
))
826 static const BYTE unicode
[] = {0xff,0xfe};
828 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
830 if(writeOut
!= sizeof(unicode
))
837 stream
.dwCookie
= (DWORD_PTR
)hFile
;
838 stream
.pfnCallback
= stream_out
;
840 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
844 SetFocus(hEditorWnd
);
849 gt
.flags
= GTL_DEFAULT
;
852 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
856 lstrcpyW(wszFileName
, wszSaveFileName
);
857 set_caption(wszFileName
);
858 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
859 set_fileformat(format
);
862 static void DialogSaveFile(void)
866 WCHAR wszFile
[MAX_PATH
] = {'\0'};
867 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
869 ZeroMemory(&sfn
, sizeof(sfn
));
871 sfn
.lStructSize
= sizeof(sfn
);
872 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
| OFN_ENABLESIZING
;
873 sfn
.hwndOwner
= hMainWnd
;
874 sfn
.lpstrFilter
= wszFilter
;
875 sfn
.lpstrFile
= wszFile
;
876 sfn
.nMaxFile
= MAX_PATH
;
877 sfn
.lpstrDefExt
= wszDefExt
;
878 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
880 while(GetSaveFileNameW(&sfn
))
882 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
884 if(MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
885 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
890 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
895 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
901 static BOOL
prompt_save_changes(void)
906 gt
.flags
= GTL_NUMCHARS
;
908 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
912 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
917 LPWSTR displayFileName
;
922 displayFileName
= wszDefaultFileName
;
924 displayFileName
= file_basename(wszFileName
);
926 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
927 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
932 wsprintfW(text
, wszSaveChanges
, displayFileName
);
934 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
936 HeapFree(GetProcessHeap(), 0, text
);
945 DoSaveFile(wszFileName
, fileFormat
);
956 static void DialogOpenFile(void)
960 WCHAR wszFile
[MAX_PATH
] = {'\0'};
961 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
963 ZeroMemory(&ofn
, sizeof(ofn
));
965 ofn
.lStructSize
= sizeof(ofn
);
966 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
| OFN_ENABLESIZING
;
967 ofn
.hwndOwner
= hMainWnd
;
968 ofn
.lpstrFilter
= wszFilter
;
969 ofn
.lpstrFile
= wszFile
;
970 ofn
.nMaxFile
= MAX_PATH
;
971 ofn
.lpstrDefExt
= wszDefExt
;
972 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
974 if(GetOpenFileNameW(&ofn
))
976 if(prompt_save_changes())
977 DoOpenFile(ofn
.lpstrFile
);
981 static void dialog_about(void)
983 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
984 HICON icon
= LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
), IMAGE_ICON
, 48, 48, LR_SHARED
);
985 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
988 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
994 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
997 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
999 sprintf(id
, "%d\n", (int)ps
->lParam
);
1000 SetWindowTextA(hIdWnd
, id
);
1001 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_NONE
)
1002 wrap
= IDC_PAGEFMT_WN
;
1003 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
1004 wrap
= IDC_PAGEFMT_WW
;
1005 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
1006 wrap
= IDC_PAGEFMT_WM
;
1009 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
,
1010 IDC_PAGEFMT_WM
, wrap
);
1012 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
1013 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
1014 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
1015 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
1016 if(barState
[ps
->lParam
] & (1 << BANDID_RULER
))
1017 CheckDlgButton(hWnd
, IDC_PAGEFMT_RU
, TRUE
);
1018 if(barState
[ps
->lParam
] & (1 << BANDID_STATUSBAR
))
1019 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1024 switch(LOWORD(wParam
))
1026 case IDC_PAGEFMT_WN
:
1027 case IDC_PAGEFMT_WW
:
1028 case IDC_PAGEFMT_WM
:
1029 CheckRadioButton(hWnd
, IDC_PAGEFMT_WN
, IDC_PAGEFMT_WM
,
1033 case IDC_PAGEFMT_TB
:
1034 case IDC_PAGEFMT_FB
:
1035 case IDC_PAGEFMT_RU
:
1036 case IDC_PAGEFMT_SB
:
1037 CheckDlgButton(hWnd
, LOWORD(wParam
),
1038 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1044 LPNMHDR header
= (LPNMHDR
)lParam
;
1045 if(header
->code
== PSN_APPLY
)
1047 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1051 GetWindowTextA(hIdWnd
, sid
, 4);
1053 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WN
))
1054 wordWrap
[id
] = ID_WORDWRAP_NONE
;
1055 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1056 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1057 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1058 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1060 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1061 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1063 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1065 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1066 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1068 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1070 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_RU
))
1071 barState
[id
] |= (1 << BANDID_RULER
);
1073 barState
[id
] &= ~(1 << BANDID_RULER
);
1075 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1076 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1078 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1086 static void dialog_viewproperties(void)
1088 PROPSHEETPAGEW psp
[2];
1089 PROPSHEETHEADERW psh
;
1091 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1092 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1094 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1095 psp
[0].dwFlags
= PSP_USETITLE
;
1096 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1097 psp
[0].pfnDlgProc
= formatopts_proc
;
1098 psp
[0].hInstance
= hInstance
;
1099 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1100 psp
[0].pfnCallback
= NULL
;
1101 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1102 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1104 psp
[i
].dwSize
= psp
[0].dwSize
;
1105 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1106 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1107 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1108 psp
[i
].hInstance
= psp
[0].hInstance
;
1109 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1110 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1111 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1114 psh
.dwSize
= sizeof(psh
);
1115 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1116 psh
.hwndParent
= hMainWnd
;
1117 psh
.hInstance
= hInstance
;
1118 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1119 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1120 U3(psh
).ppsp
= ppsp
;
1121 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1123 if(fileFormat
& SF_RTF
)
1124 U2(psh
).nStartPage
= 1;
1126 U2(psh
).nStartPage
= 0;
1127 PropertySheetW(&psh
);
1129 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
1132 static void HandleCommandLine(LPWSTR cmdline
)
1137 /* skip white space */
1138 while (*cmdline
== ' ') cmdline
++;
1140 /* skip executable name */
1141 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1143 if (*cmdline
== delimiter
) cmdline
++;
1144 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1145 if (*cmdline
== delimiter
) cmdline
++;
1149 while (isspace(*cmdline
)) cmdline
++;
1151 if (*cmdline
== '-' || *cmdline
== '/')
1153 if (!cmdline
[2] || isspace(cmdline
[2]))
1164 /* a filename starting by / */
1171 /* file name is passed on the command line */
1172 if (cmdline
[0] == '"')
1175 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1177 DoOpenFile(cmdline
);
1178 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1182 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED
), wszAppTitle
, MB_OK
);
1185 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1187 if(pFr
->Flags
& FR_DIALOGTERM
)
1190 pFr
->Flags
= FR_FINDNEXT
;
1194 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1196 DWORD flags
= FR_DOWN
;
1198 static CHARRANGE cr
;
1203 HMENU hMenu
= GetMenu(hMainWnd
);
1206 mi
.cbSize
= sizeof(mi
);
1207 mi
.fMask
= MIIM_DATA
;
1209 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1211 gt
.flags
= GTL_NUMCHARS
;
1214 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1216 if(pFr
->lCustData
== -1)
1218 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1219 cr
.cpMin
= startPos
;
1220 pFr
->lCustData
= startPos
;
1222 if(cr
.cpMin
== length
)
1226 startPos
= pFr
->lCustData
;
1229 if(cr
.cpMax
> length
)
1237 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1239 if(pFr
->Flags
& FR_MATCHCASE
)
1240 flags
|= FR_MATCHCASE
;
1241 if(pFr
->Flags
& FR_WHOLEWORD
)
1242 flags
|= FR_WHOLEWORD
;
1244 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1248 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1250 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1251 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1253 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1259 pFr
->lCustData
= -1;
1260 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1261 MB_OK
| MB_ICONASTERISK
);
1264 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1266 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1267 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1269 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1270 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1272 if(pFr
->Flags
& FR_REPLACEALL
)
1273 handle_findmsg(pFr
);
1280 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1282 static WCHAR findBuffer
[MAX_STRING_LEN
];
1284 /* Allow only one search/replace dialog to open */
1285 if(hFindWnd
!= NULL
)
1287 SetActiveWindow(hFindWnd
);
1291 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1292 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1293 fr
->hwndOwner
= hMainWnd
;
1294 fr
->Flags
= FR_HIDEUPDOWN
;
1295 fr
->lpstrFindWhat
= findBuffer
;
1297 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1300 hFindWnd
= ReplaceTextW(fr
);
1302 hFindWnd
= FindTextW(fr
);
1305 static int current_units_to_twips(float number
)
1307 int twips
= (int)(number
* 1000.0 / (float)CENTMM_PER_INCH
* (float)TWIPS_PER_INCH
);
1311 static void append_current_units(LPWSTR buffer
)
1313 static const WCHAR space
[] = {' ', 0};
1314 lstrcatW(buffer
, space
);
1315 lstrcatW(buffer
, units_cmW
);
1318 static void number_with_units(LPWSTR buffer
, int number
)
1320 static const WCHAR fmt
[] = {'%','.','2','f',' ','%','s','\0'};
1321 float converted
= (float)number
/ (float)TWIPS_PER_INCH
*(float)CENTMM_PER_INCH
/ 1000.0;
1323 sprintfW(buffer
, fmt
, converted
, units_cmW
);
1326 static BOOL
get_comboexlist_selection(HWND hComboEx
, LPWSTR wszBuffer
, UINT bufferLength
)
1328 COMBOBOXEXITEMW cbItem
;
1329 COMBOBOXINFO cbInfo
;
1333 hCombo
= (HWND
)SendMessage(hComboEx
, CBEM_GETCOMBOCONTROL
, 0, 0);
1336 cbInfo
.cbSize
= sizeof(COMBOBOXINFO
);
1337 result
= SendMessage(hCombo
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)&cbInfo
);
1340 hList
= cbInfo
.hwndList
;
1341 idx
= SendMessage(hList
, LB_GETCURSEL
, 0, 0);
1345 ZeroMemory(&cbItem
, sizeof(cbItem
));
1346 cbItem
.mask
= CBEIF_TEXT
;
1348 cbItem
.pszText
= wszBuffer
;
1349 cbItem
.cchTextMax
= bufferLength
-1;
1350 result
= SendMessageW(hComboEx
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
);
1355 static INT_PTR CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1361 WCHAR buffer
[MAX_STRING_LEN
];
1363 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1366 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
1368 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1369 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
1371 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1372 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
1373 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1375 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1380 switch(LOWORD(wParam
))
1383 if (HIWORD(wParam
) != LBN_DBLCLK
)
1390 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
1392 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1396 WCHAR buffer
[MAX_STRING_LEN
];
1397 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
1398 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
1404 EndDialog(hWnd
, wParam
);
1411 static INT_PTR CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1417 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1418 WCHAR buffer
[MAX_STRING_LEN
];
1419 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1421 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, buffer
, MAX_STRING_LEN
);
1422 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1423 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, buffer
, MAX_STRING_LEN
);
1424 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1425 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, buffer
, MAX_STRING_LEN
);
1426 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1428 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
1433 switch(LOWORD(wParam
))
1438 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
1439 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
1442 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
1447 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
1454 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1456 static const WORD ALIGNMENT_VALUES
[] = {PFA_LEFT
, PFA_RIGHT
, PFA_CENTER
};
1462 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
1464 WCHAR buffer
[MAX_STRING_LEN
];
1465 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1466 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1467 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1468 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1472 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
1474 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1475 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
1477 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1478 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
1480 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
1482 pf
.cbSize
= sizeof(pf
);
1483 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1485 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1487 if(pf
.wAlignment
== PFA_RIGHT
)
1489 else if(pf
.wAlignment
== PFA_CENTER
)
1492 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
1494 number_with_units(buffer
, pf
.dxStartIndent
+ pf
.dxOffset
);
1495 SetWindowTextW(hLeftWnd
, buffer
);
1496 number_with_units(buffer
, pf
.dxRightIndent
);
1497 SetWindowTextW(hRightWnd
, buffer
);
1498 number_with_units(buffer
, -pf
.dxOffset
);
1499 SetWindowTextW(hFirstWnd
, buffer
);
1504 switch(LOWORD(wParam
))
1508 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
1509 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
1510 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
1511 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
1512 WCHAR buffer
[MAX_STRING_LEN
];
1518 index
= SendMessageW(hListWnd
, CB_GETCURSEL
, 0, 0);
1519 pf
.wAlignment
= ALIGNMENT_VALUES
[index
];
1521 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
1522 if(number_from_string(buffer
, &num
, TRUE
))
1524 pf
.dxOffset
= current_units_to_twips(num
);
1525 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
1526 if(number_from_string(buffer
, &num
, TRUE
))
1528 pf
.dxRightIndent
= current_units_to_twips(num
);
1529 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
1530 if(number_from_string(buffer
, &num
, TRUE
))
1532 pf
.dxStartIndent
= current_units_to_twips(num
);
1536 MessageBoxWithResStringW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1537 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
1541 if (pf
.dxOffset
+ pf
.dxStartIndent
< 0
1542 && pf
.dxStartIndent
< 0)
1544 /* The first line is before the left edge, so
1545 * make sure it is at the left edge. */
1546 pf
.dxOffset
= -pf
.dxStartIndent
;
1547 } else if (pf
.dxOffset
< 0) {
1548 /* The second and following lines are before
1549 * the left edge, so set it to be at the left
1550 * edge, and adjust the first line since it
1551 * is relative to it. */
1552 pf
.dxStartIndent
= max(pf
.dxStartIndent
+ pf
.dxOffset
, 0);
1555 /* Internally the dxStartIndent is the absolute
1556 * offset for the first line and dxOffset is
1557 * to it value as opposed how it is displayed with
1558 * the first line being the relative value.
1559 * These two lines make the adjustments. */
1560 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
1561 pf
.dxOffset
= pf
.dxOffset
- pf
.dxStartIndent
;
1563 pf
.cbSize
= sizeof(pf
);
1564 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
1566 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1572 EndDialog(hWnd
, wParam
);
1579 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1585 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1587 WCHAR buffer
[MAX_STRING_LEN
];
1590 pf
.cbSize
= sizeof(pf
);
1591 pf
.dwMask
= PFM_TABSTOPS
;
1592 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1593 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
1595 for(i
= 0; i
< pf
.cTabCount
; i
++)
1597 number_with_units(buffer
, pf
.rgxTabs
[i
]);
1598 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
1605 switch(LOWORD(wParam
))
1609 HWND hTabWnd
= (HWND
)lParam
;
1610 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
1611 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
1612 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
1614 if(GetWindowTextLengthW(hTabWnd
))
1615 EnableWindow(hAddWnd
, TRUE
);
1617 EnableWindow(hAddWnd
, FALSE
);
1619 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
1621 EnableWindow(hEmptyWnd
, TRUE
);
1623 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
1624 EnableWindow(hDelWnd
, FALSE
);
1626 EnableWindow(hDelWnd
, TRUE
);
1629 EnableWindow(hEmptyWnd
, FALSE
);
1636 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1637 WCHAR buffer
[MAX_STRING_LEN
];
1639 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
1640 append_current_units(buffer
);
1642 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
1645 int item_count
= SendMessage(hTabWnd
, CB_GETCOUNT
, 0, 0);
1647 if(!number_from_string(buffer
, &number
, TRUE
))
1649 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
1650 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1651 } else if (item_count
>= MAX_TAB_STOPS
) {
1652 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_MAX_TAB_STOPS
),
1653 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
1656 float next_number
= -1;
1657 int next_number_in_twips
= -1;
1658 int insert_number
= current_units_to_twips(number
);
1660 /* linear search for position to insert the string */
1661 for(i
= 0; i
< item_count
; i
++)
1663 SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
, (LPARAM
)&buffer
);
1664 number_from_string(buffer
, &next_number
, TRUE
);
1665 next_number_in_twips
= current_units_to_twips(next_number
);
1666 if (insert_number
<= next_number_in_twips
)
1669 if (insert_number
!= next_number_in_twips
)
1671 number_with_units(buffer
, insert_number
);
1672 SendMessageW(hTabWnd
, CB_INSERTSTRING
, i
, (LPARAM
)&buffer
);
1673 SetWindowTextW(hTabWnd
, 0);
1683 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1685 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
1687 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
1693 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1694 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
1701 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
1703 WCHAR buffer
[MAX_STRING_LEN
];
1707 pf
.cbSize
= sizeof(pf
);
1708 pf
.dwMask
= PFM_TABSTOPS
;
1710 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
1711 (LPARAM
)&buffer
) != CB_ERR
&&
1712 i
< MAX_TAB_STOPS
; i
++)
1714 number_from_string(buffer
, &number
, TRUE
);
1715 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
1718 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
1722 EndDialog(hWnd
, wParam
);
1729 static int context_menu(LPARAM lParam
)
1731 int x
= (int)(short)LOWORD(lParam
);
1732 int y
= (int)(short)HIWORD(lParam
);
1733 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
1737 int from
= 0, to
= 0;
1739 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1740 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
1741 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
1746 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
1747 x
, y
, 0, hMainWnd
, 0);
1752 static LRESULT
OnCreate( HWND hWnd
)
1754 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
, hRulerWnd
;
1755 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
1758 int nStdBitmaps
= 0;
1761 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
1762 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
1764 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
1766 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
1767 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
1768 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
1770 rbi
.cbSize
= sizeof(rbi
);
1773 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
1776 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
1778 1, hInstance
, IDB_TOOLBAR
,
1780 24, 24, 16, 16, sizeof(TBBUTTON
));
1782 ab
.hInst
= HINST_COMMCTRL
;
1783 ab
.nID
= IDB_STD_SMALL_COLOR
;
1784 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
1786 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
1787 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
1788 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
1789 AddSeparator(hToolBarWnd
);
1790 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
1791 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
1792 AddSeparator(hToolBarWnd
);
1793 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
1794 AddSeparator(hToolBarWnd
);
1795 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
1796 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
1797 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
1798 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
1799 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
1800 AddSeparator(hToolBarWnd
);
1801 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
1803 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
1805 rbb
.cbSize
= REBARBANDINFOW_V6_SIZE
;
1806 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
1807 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
1809 rbb
.hwndChild
= hToolBarWnd
;
1811 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
1812 rbb
.wID
= BANDID_TOOLBAR
;
1814 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1816 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1817 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
1818 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
1820 rbb
.hwndChild
= hFontListWnd
;
1822 rbb
.wID
= BANDID_FONTLIST
;
1824 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1826 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
1827 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
1828 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
1830 rbb
.hwndChild
= hSizeListWnd
;
1832 rbb
.fStyle
^= RBBS_BREAK
;
1833 rbb
.wID
= BANDID_SIZELIST
;
1835 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1837 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
1838 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
1839 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
1841 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
1842 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
1843 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
1844 AddSeparator(hFormatBarWnd
);
1845 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
1846 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
1847 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
1848 AddSeparator(hFormatBarWnd
);
1849 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
1851 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
1853 rbb
.hwndChild
= hFormatBarWnd
;
1854 rbb
.wID
= BANDID_FORMATBAR
;
1856 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1858 hRulerWnd
= CreateWindowExW(0, WC_STATICW
, NULL
, WS_VISIBLE
| WS_CHILD
,
1859 0, 0, 200, 10, hReBarWnd
, (HMENU
)IDC_RULER
, hInstance
, NULL
);
1862 rbb
.hwndChild
= hRulerWnd
;
1863 rbb
.wID
= BANDID_RULER
;
1864 rbb
.fStyle
|= RBBS_BREAK
;
1866 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
1868 hDLL
= LoadLibraryW(wszRichEditDll
);
1871 MessageBoxWithResStringW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
1872 MB_OK
| MB_ICONEXCLAMATION
);
1876 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, RICHEDIT_CLASS20W
, NULL
,
1877 WS_CHILD
|WS_VISIBLE
|ES_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
1878 |ES_WANTRETURN
|WS_VSCROLL
|ES_NOHIDESEL
|WS_HSCROLL
,
1879 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
1883 fprintf(stderr
, "Error code %u\n", GetLastError());
1888 SetFocus(hEditorWnd
);
1889 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
1893 populate_font_list(hFontListWnd
);
1894 populate_size_list(hSizeListWnd
);
1896 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1898 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
1900 registry_read_filelist(hWnd
);
1901 registry_read_formatopts_all(barState
, wordWrap
);
1902 registry_read_options();
1903 DragAcceptFiles(hWnd
, TRUE
);
1908 static LRESULT
OnUser( HWND hWnd
)
1910 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1911 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1912 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
1913 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
1919 ZeroMemory(&fmt
, sizeof(fmt
));
1920 fmt
.cbSize
= sizeof(fmt
);
1922 ZeroMemory(&pf
, sizeof(pf
));
1923 pf
.cbSize
= sizeof(pf
);
1925 gt
.flags
= GTL_NUMCHARS
;
1928 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
1929 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
1931 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
1933 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1934 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
1935 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
1936 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
1937 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
1938 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
1939 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
1941 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
1942 (fmt
.dwEffects
& CFE_BOLD
));
1943 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
1944 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
1945 (fmt
.dwEffects
& CFE_ITALIC
));
1946 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
1947 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
1948 (fmt
.dwEffects
& CFE_UNDERLINE
));
1949 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
1951 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
1952 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
1953 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
1954 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
1956 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
1960 static LRESULT
OnNotify( HWND hWnd
, LPARAM lParam
)
1962 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
1963 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
1964 NMHDR
*pHdr
= (NMHDR
*)lParam
;
1965 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
1966 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
1968 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
1970 if (pHdr
->code
== CBEN_ENDEDITW
)
1972 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
1973 if(pHdr
->hwndFrom
== hwndFontList
)
1975 on_fontlist_modified((LPWSTR
)endEdit
->szText
);
1976 } else if (pHdr
->hwndFrom
== hwndSizeList
)
1978 on_sizelist_modified(hwndFontList
,(LPWSTR
)endEdit
->szText
);
1984 if (pHdr
->hwndFrom
!= hwndEditor
)
1987 if (pHdr
->code
== EN_SELCHANGE
)
1989 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
1994 sprintf( buf
,"selection = %d..%d, line count=%ld",
1995 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
1996 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
1997 SetWindowTextA(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
1998 SendMessage(hWnd
, WM_USER
, 0, 0);
2004 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2006 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2007 static FINDREPLACEW findreplace
;
2009 if ((HWND
)lParam
== hwndEditor
)
2012 switch(LOWORD(wParam
))
2016 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
2021 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2022 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
2025 if(ret
!= ID_NEWFILE_ABORT
)
2027 if(prompt_save_changes())
2032 wszFileName
[0] = '\0';
2036 st
.flags
= ST_DEFAULT
;
2038 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
2040 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2041 set_fileformat(ret
);
2055 DoSaveFile(wszFileName
, fileFormat
);
2060 case ID_FILE_SAVEAS
:
2064 case ID_FILE_RECENT1
:
2065 case ID_FILE_RECENT2
:
2066 case ID_FILE_RECENT3
:
2067 case ID_FILE_RECENT4
:
2069 HMENU hMenu
= GetMenu(hWnd
);
2072 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2073 mi
.fMask
= MIIM_DATA
;
2074 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2075 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2080 dialog_find(&findreplace
, FALSE
);
2084 handle_findmsg(&findreplace
);
2088 dialog_find(&findreplace
, TRUE
);
2091 case ID_FONTSETTINGS
:
2092 dialog_choose_font();
2096 dialog_print(hWnd
, wszFileName
);
2097 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2100 case ID_PRINT_QUICK
:
2101 print_quick(wszFileName
);
2102 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2107 int index
= reg_formatindex(fileFormat
);
2108 DWORD tmp
= barState
[index
];
2109 barState
[index
] = 0;
2111 barState
[index
] = tmp
;
2112 ShowWindow(hEditorWnd
, FALSE
);
2114 init_preview(hWnd
, wszFileName
);
2116 SetMenu(hWnd
, NULL
);
2117 InvalidateRect(0, 0, TRUE
);
2122 dialog_printsetup(hWnd
);
2123 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2126 case ID_FORMAT_BOLD
:
2127 case ID_FORMAT_ITALIC
:
2128 case ID_FORMAT_UNDERLINE
:
2131 int effects
= CFE_BOLD
;
2133 ZeroMemory(&fmt
, sizeof(fmt
));
2134 fmt
.cbSize
= sizeof(fmt
);
2135 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2137 fmt
.dwMask
= CFM_BOLD
;
2139 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2141 effects
= CFE_ITALIC
;
2142 fmt
.dwMask
= CFM_ITALIC
;
2143 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2145 effects
= CFE_UNDERLINE
;
2146 fmt
.dwMask
= CFM_UNDERLINE
;
2149 fmt
.dwEffects
^= effects
;
2151 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2156 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2160 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2164 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2168 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2171 case ID_EDIT_SELECTALL
:
2173 CHARRANGE range
= {0, -1};
2174 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2175 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2179 case ID_EDIT_GETTEXT
:
2181 int nLen
= GetWindowTextLengthW(hwndEditor
);
2182 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2185 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2186 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2188 HeapFree( GetProcessHeap(), 0, data
);
2189 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2191 tr
.chrg
.cpMax
= nLen
;
2192 tr
.lpstrText
= data
;
2193 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2194 MessageBoxW(NULL
, data
, wszAppTitle
, MB_OK
);
2195 HeapFree( GetProcessHeap(), 0, data
);
2197 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2201 case ID_EDIT_CHARFORMAT
:
2202 case ID_EDIT_DEFCHARFORMAT
:
2206 ZeroMemory(&cf
, sizeof(cf
));
2207 cf
.cbSize
= sizeof(cf
);
2209 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2210 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2214 case ID_EDIT_PARAFORMAT
:
2217 ZeroMemory(&pf
, sizeof(pf
));
2218 pf
.cbSize
= sizeof(pf
);
2219 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2223 case ID_EDIT_SELECTIONINFO
:
2225 CHARRANGE range
= {0, -1};
2229 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2230 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2231 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2232 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2233 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2234 MessageBoxW(hWnd
, data
, wszAppTitle
, MB_OK
);
2235 HeapFree( GetProcessHeap(), 0, data
);
2236 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2240 case ID_EDIT_READONLY
:
2242 LONG nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2243 if (nStyle
& ES_READONLY
)
2244 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2246 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2250 case ID_EDIT_MODIFIED
:
2251 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2252 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2254 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2258 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2262 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2269 pf
.cbSize
= sizeof(pf
);
2270 pf
.dwMask
= PFM_NUMBERING
;
2271 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2273 pf
.dwMask
|= PFM_OFFSET
;
2275 if(pf
.wNumbering
== PFN_BULLET
)
2281 pf
.wNumbering
= PFN_BULLET
;
2285 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2290 case ID_ALIGN_CENTER
:
2291 case ID_ALIGN_RIGHT
:
2295 pf
.cbSize
= sizeof(pf
);
2296 pf
.dwMask
= PFM_ALIGNMENT
;
2297 switch(LOWORD(wParam
)) {
2298 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2299 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2300 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2302 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2307 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
2311 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
2314 case ID_TOGGLE_TOOLBAR
:
2315 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
2319 case ID_TOGGLE_FORMATBAR
:
2320 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
2321 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
2322 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
2326 case ID_TOGGLE_STATUSBAR
:
2327 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
2331 case ID_TOGGLE_RULER
:
2332 set_toolbar_state(BANDID_RULER
, !is_bar_visible(BANDID_RULER
));
2338 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2339 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, datetime_proc
);
2345 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2346 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
2353 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2354 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
2362 case ID_VIEWPROPERTIES
:
2363 dialog_viewproperties();
2367 if (HIWORD(wParam
) == CBN_SELENDOK
)
2369 WCHAR buffer
[LF_FACESIZE
];
2370 HWND hwndFontList
= (HWND
)lParam
;
2371 get_comboexlist_selection(hwndFontList
, buffer
, LF_FACESIZE
);
2372 on_fontlist_modified(buffer
);
2377 if (HIWORD(wParam
) == CBN_SELENDOK
)
2379 WCHAR buffer
[MAX_STRING_LEN
+1];
2380 HWND hwndSizeList
= (HWND
)lParam
;
2381 get_comboexlist_selection(hwndSizeList
, buffer
, MAX_STRING_LEN
+1);
2382 on_sizelist_modified(hwndSizeList
, buffer
);
2387 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
2393 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
)
2395 HMENU hMenu
= (HMENU
)wParam
;
2396 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2397 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2399 int nAlignment
= -1;
2405 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
2406 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2407 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
2409 pf
.cbSize
= sizeof(PARAFORMAT
);
2410 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2411 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
2412 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
2413 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
2414 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
2415 if (pf
.dwMask
& PFM_ALIGNMENT
)
2416 nAlignment
= pf
.wAlignment
;
2417 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
2418 MF_CHECKED
: MF_UNCHECKED
);
2419 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
2420 MF_CHECKED
: MF_UNCHECKED
);
2421 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
2422 MF_CHECKED
: MF_UNCHECKED
);
2423 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
2424 MF_CHECKED
: MF_UNCHECKED
));
2425 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
2426 MF_ENABLED
: MF_GRAYED
);
2427 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
2428 MF_ENABLED
: MF_GRAYED
);
2430 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
2431 MF_CHECKED
: MF_UNCHECKED
);
2433 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
2434 MF_CHECKED
: MF_UNCHECKED
);
2436 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
2437 MF_CHECKED
: MF_UNCHECKED
);
2439 CheckMenuItem(hMenu
, ID_TOGGLE_RULER
, MF_BYCOMMAND
|(is_bar_visible(BANDID_RULER
)) ? MF_CHECKED
: MF_UNCHECKED
);
2441 gt
.flags
= GTL_NUMCHARS
;
2443 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
2444 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2446 mi
.cbSize
= sizeof(mi
);
2447 mi
.fMask
= MIIM_DATA
;
2449 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
2451 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
2452 MF_ENABLED
: MF_GRAYED
));
2454 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
2459 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2461 int nStatusSize
= 0;
2463 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2464 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
2465 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2466 HWND hRulerWnd
= GetDlgItem(hWnd
, IDC_RULER
);
2467 int rebarHeight
= 0;
2471 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
2472 if (IsWindowVisible(hwndStatusBar
))
2474 GetClientRect(hwndStatusBar
, &rc
);
2475 nStatusSize
= rc
.bottom
- rc
.top
;
2483 rebarHeight
= SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
2485 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
2489 GetClientRect(hWnd
, &rc
);
2490 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
2493 redraw_ruler(hRulerWnd
);
2495 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
2498 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2500 if(msg
== ID_FINDMSGSTRING
)
2501 return handle_findmsg((LPFINDREPLACEW
)lParam
);
2506 return OnCreate( hWnd
);
2509 return OnUser( hWnd
);
2512 return OnNotify( hWnd
, lParam
);
2515 if(preview_isactive())
2517 return preview_command( hWnd
, wParam
);
2520 return OnCommand( hWnd
, wParam
, lParam
);
2527 if(preview_isactive())
2530 } else if(prompt_save_changes())
2532 registry_set_options(hMainWnd
);
2533 registry_set_formatopts_all(barState
);
2540 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
2543 case WM_INITMENUPOPUP
:
2544 return OnInitPopupMenu( hWnd
, wParam
);
2547 return OnSize( hWnd
, wParam
, lParam
);
2549 case WM_CONTEXTMENU
:
2550 if((HWND
)wParam
== hEditorWnd
)
2551 return context_menu(lParam
);
2553 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2557 WCHAR file
[MAX_PATH
];
2558 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
2559 DragFinish((HDROP
)wParam
);
2561 if(prompt_save_changes())
2566 if(preview_isactive())
2567 return print_preview(hWnd
);
2569 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2572 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
2578 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int nCmdShow
)
2580 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
2585 UINT_PTR hPrevRulerProc
;
2589 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
2590 'T','A','B','L','E','\0'};
2592 InitCommonControlsEx(&classes
);
2594 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
2596 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
2597 wc
.lpfnWndProc
= WndProc
;
2600 wc
.hInstance
= hInstance
;
2601 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
2602 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
2603 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
2604 wc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_MAINMENU
);
2605 wc
.lpszClassName
= wszMainWndClass
;
2606 RegisterClassW(&wc
);
2608 registry_read_winrect(&rc
);
2609 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
2610 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
2611 registry_read_maximized(&bMaximized
);
2612 if ((nCmdShow
== SW_SHOWNORMAL
|| nCmdShow
== SW_SHOWDEFAULT
)
2614 nCmdShow
= SW_SHOWMAXIMIZED
;
2615 ShowWindow(hMainWnd
, nCmdShow
);
2619 set_fileformat(SF_RTF
);
2620 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
2621 get_default_printer_opts();
2622 target_device(hMainWnd
, wordWrap
[reg_formatindex(fileFormat
)]);
2624 hRulerWnd
= GetDlgItem(GetDlgItem(hMainWnd
, IDC_REBAR
), IDC_RULER
);
2625 SendMessageW(GetDlgItem(hMainWnd
, IDC_EDITOR
), EM_POSFROMCHAR
, (WPARAM
)&EditPoint
, 0);
2626 hPrevRulerProc
= SetWindowLongPtrW(hRulerWnd
, GWLP_WNDPROC
, (UINT_PTR
)ruler_proc
);
2627 SendMessageW(hRulerWnd
, WM_USER
, (WPARAM
)&EditPoint
, hPrevRulerProc
);
2629 HandleCommandLine(GetCommandLineW());
2631 while(GetMessageW(&msg
,0,0,0))
2633 if (IsDialogMessage(hFindWnd
, &msg
))
2636 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
2638 TranslateMessage(&msg
);
2639 DispatchMessageW(&msg
);
2640 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
2641 SendMessageW(hMainWnd
, WM_USER
, 0, 0);