2006-02-14 14:48:29 +01:00
|
|
|
/*
|
|
|
|
* Wordpad implementation
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2008-01-14 00:36:23 +01:00
|
|
|
* Copyright 2007-2008 by Alexander N. Sørnes <alex@thehandofagony.com>
|
2006-02-14 14:48:29 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-02-14 14:48:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2007-12-12 09:36:41 +01:00
|
|
|
#include <stdlib.h>
|
2006-02-14 14:48:29 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <richedit.h>
|
|
|
|
#include <commctrl.h>
|
2007-02-25 14:40:27 +01:00
|
|
|
#include <commdlg.h>
|
2007-08-22 22:45:11 +02:00
|
|
|
#include <shellapi.h>
|
2007-08-23 01:15:17 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include <errno.h>
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
#include "wordpad.h"
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-09-18 00:39:11 +02:00
|
|
|
#ifdef NONAMELESSUNION
|
|
|
|
# define U(x) (x).u
|
|
|
|
# define U2(x) (x).u2
|
|
|
|
# define U3(x) (x).u3
|
|
|
|
#else
|
|
|
|
# define U(x) (x)
|
|
|
|
# define U2(x) (x)
|
|
|
|
# define U3(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
/* use LoadString */
|
2008-10-09 20:34:01 +02:00
|
|
|
static const WCHAR wszAppTitle[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
static const WCHAR wszMainWndClass[] = {'W','O','R','D','P','A','D','T','O','P',0};
|
|
|
|
|
2007-08-24 19:45:54 +02:00
|
|
|
static const WCHAR stringFormat[] = {'%','2','d','\0'};
|
|
|
|
|
2010-01-29 09:02:41 +01:00
|
|
|
const WCHAR wszPreviewWndClass[] = {'P','r','t','P','r','e','v','i','e','w',0};
|
|
|
|
LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2007-02-10 22:55:29 +01:00
|
|
|
static HWND hMainWnd;
|
|
|
|
static HWND hEditorWnd;
|
2007-07-18 15:41:33 +02:00
|
|
|
static HWND hFindWnd;
|
2010-02-17 20:19:36 +01:00
|
|
|
static HMENU hColorPopupMenu;
|
2007-07-18 15:41:33 +02:00
|
|
|
|
|
|
|
static UINT ID_FINDMSGSTRING;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
static DWORD wordWrap[2];
|
2007-12-12 09:36:41 +01:00
|
|
|
static DWORD barState[2];
|
2007-11-11 01:06:46 +01:00
|
|
|
static WPARAM fileFormat = SF_RTF;
|
|
|
|
|
|
|
|
static WCHAR wszFileName[MAX_PATH];
|
2007-07-18 21:59:24 +02:00
|
|
|
static WCHAR wszFilter[MAX_STRING_LEN*4+6*3+5];
|
2007-07-08 13:51:19 +02:00
|
|
|
static WCHAR wszDefaultFileName[MAX_STRING_LEN];
|
|
|
|
static WCHAR wszSaveChanges[MAX_STRING_LEN];
|
2007-08-23 01:27:50 +02:00
|
|
|
static WCHAR units_cmW[MAX_STRING_LEN];
|
2010-05-08 03:23:06 +02:00
|
|
|
static WCHAR units_inW[MAX_STRING_LEN];
|
|
|
|
static WCHAR units_inchW[MAX_STRING_LEN];
|
|
|
|
static WCHAR units_ptW[MAX_STRING_LEN];
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2016-10-10 14:13:05 +02:00
|
|
|
static int last_bullet = PFN_BULLET;
|
|
|
|
|
2007-06-06 11:10:47 +02:00
|
|
|
static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam );
|
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
UNIT_CM,
|
|
|
|
UNIT_INCH,
|
|
|
|
UNIT_PT
|
|
|
|
} UNIT;
|
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int endPos;
|
|
|
|
BOOL wrapped;
|
2010-07-20 00:18:08 +02:00
|
|
|
WCHAR findBuffer[128];
|
2010-07-20 00:17:57 +02:00
|
|
|
} FINDREPLACE_custom;
|
|
|
|
|
2007-02-25 14:40:27 +01:00
|
|
|
/* Load string resources */
|
2007-03-10 22:00:47 +01:00
|
|
|
static void DoLoadStrings(void)
|
2007-02-25 14:40:27 +01:00
|
|
|
{
|
2007-05-31 15:31:44 +02:00
|
|
|
LPWSTR p = wszFilter;
|
|
|
|
static const WCHAR files_rtf[] = {'*','.','r','t','f','\0'};
|
|
|
|
static const WCHAR files_txt[] = {'*','.','t','x','t','\0'};
|
|
|
|
static const WCHAR files_all[] = {'*','.','*','\0'};
|
2007-11-11 01:06:46 +01:00
|
|
|
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2007-02-25 14:40:27 +01:00
|
|
|
|
2016-11-12 09:48:47 +01:00
|
|
|
p += 1 + LoadStringW(hInstance, STRING_RICHTEXT_FILES_RTF, p, MAX_STRING_LEN);
|
2007-05-31 15:31:44 +02:00
|
|
|
lstrcpyW(p, files_rtf);
|
|
|
|
p += lstrlenW(p) + 1;
|
2016-11-12 09:48:47 +01:00
|
|
|
p += 1 + LoadStringW(hInstance, STRING_TEXT_FILES_TXT, p, MAX_STRING_LEN);
|
2007-05-31 15:31:44 +02:00
|
|
|
lstrcpyW(p, files_txt);
|
|
|
|
p += lstrlenW(p) + 1;
|
2016-11-12 09:48:47 +01:00
|
|
|
p += 1 + LoadStringW(hInstance, STRING_TEXT_FILES_UNICODE_TXT, p, MAX_STRING_LEN);
|
2007-07-18 21:59:24 +02:00
|
|
|
lstrcpyW(p, files_txt);
|
|
|
|
p += lstrlenW(p) + 1;
|
2016-11-12 09:48:47 +01:00
|
|
|
p += 1 + LoadStringW(hInstance, STRING_ALL_FILES, p, MAX_STRING_LEN);
|
2007-05-31 15:31:44 +02:00
|
|
|
lstrcpyW(p, files_all);
|
|
|
|
p += lstrlenW(p) + 1;
|
2007-02-25 14:40:27 +01:00
|
|
|
*p = '\0';
|
2007-07-08 13:51:19 +02:00
|
|
|
|
|
|
|
p = wszDefaultFileName;
|
|
|
|
LoadStringW(hInstance, STRING_DEFAULT_FILENAME, p, MAX_STRING_LEN);
|
|
|
|
|
|
|
|
p = wszSaveChanges;
|
|
|
|
LoadStringW(hInstance, STRING_PROMPT_SAVE_CHANGES, p, MAX_STRING_LEN);
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2007-08-23 01:27:50 +02:00
|
|
|
LoadStringW(hInstance, STRING_UNITS_CM, units_cmW, MAX_STRING_LEN);
|
2010-05-08 03:23:06 +02:00
|
|
|
LoadStringW(hInstance, STRING_UNITS_IN, units_inW, MAX_STRING_LEN);
|
|
|
|
LoadStringW(hInstance, STRING_UNITS_INCH, units_inchW, MAX_STRING_LEN);
|
|
|
|
LoadStringW(hInstance, STRING_UNITS_PT, units_ptW, MAX_STRING_LEN);
|
2007-02-25 14:40:27 +01:00
|
|
|
}
|
|
|
|
|
2008-10-21 09:07:09 +02:00
|
|
|
/* Show a message box with resource strings */
|
|
|
|
static int MessageBoxWithResStringW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
|
|
|
|
{
|
|
|
|
MSGBOXPARAMSW params;
|
|
|
|
|
|
|
|
params.cbSize = sizeof(params);
|
|
|
|
params.hwndOwner = hWnd;
|
|
|
|
params.hInstance = GetModuleHandleW(0);
|
|
|
|
params.lpszText = lpText;
|
|
|
|
params.lpszCaption = lpCaption;
|
|
|
|
params.dwStyle = uType;
|
|
|
|
params.lpszIcon = NULL;
|
|
|
|
params.dwContextHelpId = 0;
|
|
|
|
params.lpfnMsgBoxCallback = NULL;
|
|
|
|
params.dwLanguageId = 0;
|
|
|
|
return MessageBoxIndirectW(¶ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
static void AddButtonStyle(HWND hwndToolBar, int nImage, int nCommand, BYTE style)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
|
|
|
TBBUTTON button;
|
|
|
|
|
|
|
|
ZeroMemory(&button, sizeof(button));
|
|
|
|
button.iBitmap = nImage;
|
|
|
|
button.idCommand = nCommand;
|
|
|
|
button.fsState = TBSTATE_ENABLED;
|
2016-10-11 14:01:11 +02:00
|
|
|
button.fsStyle = style;
|
2006-02-14 14:48:29 +01:00
|
|
|
button.dwData = 0;
|
|
|
|
button.iString = -1;
|
2007-06-14 20:03:04 +02:00
|
|
|
SendMessageW(hwndToolBar, TB_ADDBUTTONSW, 1, (LPARAM)&button);
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
static void AddButton(HWND hwndToolBar, int nImage, int nCommand)
|
|
|
|
{
|
|
|
|
AddButtonStyle(hwndToolBar, nImage, nCommand, BTNS_BUTTON);
|
|
|
|
}
|
|
|
|
|
2006-06-05 12:10:40 +02:00
|
|
|
static void AddSeparator(HWND hwndToolBar)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
|
|
|
TBBUTTON button;
|
|
|
|
|
|
|
|
ZeroMemory(&button, sizeof(button));
|
|
|
|
button.iBitmap = -1;
|
|
|
|
button.idCommand = 0;
|
|
|
|
button.fsState = 0;
|
2010-11-02 19:56:20 +01:00
|
|
|
button.fsStyle = BTNS_SEP;
|
2006-02-14 14:48:29 +01:00
|
|
|
button.dwData = 0;
|
|
|
|
button.iString = -1;
|
2007-06-14 20:03:04 +02:00
|
|
|
SendMessageW(hwndToolBar, TB_ADDBUTTONSW, 1, (LPARAM)&button);
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
|
|
|
|
2007-02-10 22:55:29 +01:00
|
|
|
static DWORD CALLBACK stream_in(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb)
|
|
|
|
{
|
2007-06-02 00:19:37 +02:00
|
|
|
HANDLE hFile = (HANDLE)cookie;
|
|
|
|
DWORD read;
|
|
|
|
|
|
|
|
if(!ReadFile(hFile, buffer, cb, &read, 0))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
*pcb = read;
|
2007-02-10 22:55:29 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:07:02 +02:00
|
|
|
static DWORD CALLBACK stream_out(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb)
|
|
|
|
{
|
|
|
|
DWORD written;
|
|
|
|
int ret;
|
|
|
|
HANDLE hFile = (HANDLE)cookie;
|
|
|
|
|
|
|
|
ret = WriteFile(hFile, buffer, cb, &written, 0);
|
|
|
|
|
|
|
|
if(!ret || (cb != written))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
*pcb = cb;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-12 09:36:41 +01:00
|
|
|
LPWSTR file_basename(LPWSTR path)
|
2007-07-18 15:41:57 +02:00
|
|
|
{
|
|
|
|
LPWSTR pos = path + lstrlenW(path);
|
|
|
|
|
|
|
|
while(pos > path)
|
|
|
|
{
|
|
|
|
if(*pos == '\\' || *pos == '/')
|
|
|
|
{
|
|
|
|
pos++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos--;
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2007-05-30 14:42:36 +02:00
|
|
|
static void set_caption(LPCWSTR wszNewFileName)
|
|
|
|
{
|
2007-06-05 23:08:29 +02:00
|
|
|
static const WCHAR wszSeparator[] = {' ','-',' '};
|
2007-07-08 13:51:19 +02:00
|
|
|
WCHAR *wszCaption;
|
|
|
|
SIZE_T length = 0;
|
2007-05-30 14:42:36 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
if(!wszNewFileName)
|
|
|
|
wszNewFileName = wszDefaultFileName;
|
2007-08-22 22:44:21 +02:00
|
|
|
else
|
|
|
|
wszNewFileName = file_basename((LPWSTR)wszNewFileName);
|
2007-06-05 23:08:29 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
wszCaption = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
lstrlenW(wszNewFileName)*sizeof(WCHAR)+sizeof(wszSeparator)+sizeof(wszAppTitle));
|
2007-06-05 23:08:29 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
if(!wszCaption)
|
|
|
|
return;
|
2007-06-05 23:08:29 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
memcpy(wszCaption, wszNewFileName, lstrlenW(wszNewFileName)*sizeof(WCHAR));
|
|
|
|
length += lstrlenW(wszNewFileName);
|
|
|
|
memcpy(wszCaption + length, wszSeparator, sizeof(wszSeparator));
|
2018-07-24 22:13:45 +02:00
|
|
|
length += ARRAY_SIZE(wszSeparator);
|
2007-07-08 13:51:19 +02:00
|
|
|
memcpy(wszCaption + length, wszAppTitle, sizeof(wszAppTitle));
|
2007-06-05 23:08:29 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
SetWindowTextW(hMainWnd, wszCaption);
|
2007-06-05 23:08:29 +02:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, wszCaption);
|
2007-05-30 14:42:36 +02:00
|
|
|
}
|
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
static BOOL validate_endptr(LPCWSTR endptr, UNIT *punit)
|
2007-08-23 01:15:17 +02:00
|
|
|
{
|
2010-05-08 03:23:06 +02:00
|
|
|
if(punit != NULL)
|
|
|
|
*punit = UNIT_CM;
|
2008-06-18 03:19:11 +02:00
|
|
|
if(!endptr)
|
|
|
|
return FALSE;
|
|
|
|
if(!*endptr)
|
2007-08-23 01:15:17 +02:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
while(*endptr == ' ')
|
|
|
|
endptr++;
|
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
if(punit == NULL)
|
2008-06-18 03:19:11 +02:00
|
|
|
return *endptr == '\0';
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
if(!lstrcmpW(endptr, units_cmW))
|
|
|
|
{
|
|
|
|
*punit = UNIT_CM;
|
|
|
|
endptr += lstrlenW(units_cmW);
|
|
|
|
}
|
|
|
|
else if (!lstrcmpW(endptr, units_inW))
|
|
|
|
{
|
|
|
|
*punit = UNIT_INCH;
|
|
|
|
endptr += lstrlenW(units_inW);
|
|
|
|
}
|
|
|
|
else if (!lstrcmpW(endptr, units_inchW))
|
|
|
|
{
|
|
|
|
*punit = UNIT_INCH;
|
|
|
|
endptr += lstrlenW(units_inchW);
|
|
|
|
}
|
|
|
|
else if (!lstrcmpW(endptr, units_ptW))
|
|
|
|
{
|
|
|
|
*punit = UNIT_PT;
|
|
|
|
endptr += lstrlenW(units_ptW);
|
|
|
|
}
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2008-06-18 03:19:11 +02:00
|
|
|
return *endptr == '\0';
|
2007-08-23 01:15:17 +02:00
|
|
|
}
|
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
static BOOL number_from_string(LPCWSTR string, float *num, UNIT *punit)
|
2007-08-23 01:15:17 +02:00
|
|
|
{
|
|
|
|
double ret;
|
2010-05-08 03:23:06 +02:00
|
|
|
WCHAR *endptr;
|
2007-08-23 01:15:17 +02:00
|
|
|
|
|
|
|
*num = 0;
|
|
|
|
errno = 0;
|
2010-05-08 03:23:06 +02:00
|
|
|
ret = wcstod(string, &endptr);
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
if (punit != NULL)
|
|
|
|
*punit = UNIT_CM;
|
|
|
|
if((ret == 0 && errno != 0) || endptr == string || !validate_endptr(endptr, punit))
|
2007-08-23 01:15:17 +02:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
*num = (float)ret;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-24 19:45:54 +02:00
|
|
|
static void set_size(float size)
|
|
|
|
{
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = CFM_SIZE;
|
|
|
|
fmt.yHeight = (int)(size * 20.0);
|
|
|
|
SendMessageW(hEditorWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
}
|
|
|
|
|
2008-06-18 03:19:15 +02:00
|
|
|
static void on_sizelist_modified(HWND hwndSizeList, LPWSTR wszNewFontSize)
|
|
|
|
{
|
|
|
|
WCHAR sizeBuffer[MAX_STRING_LEN];
|
|
|
|
CHARFORMAT2W format;
|
|
|
|
|
|
|
|
ZeroMemory(&format, sizeof(format));
|
|
|
|
format.cbSize = sizeof(format);
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
|
|
|
|
|
|
|
|
wsprintfW(sizeBuffer, stringFormat, format.yHeight / 20);
|
|
|
|
if(lstrcmpW(sizeBuffer, wszNewFontSize))
|
|
|
|
{
|
|
|
|
float size = 0;
|
2010-05-08 03:23:06 +02:00
|
|
|
if(number_from_string(wszNewFontSize, &size, NULL)
|
2008-06-18 03:19:15 +02:00
|
|
|
&& size > 0)
|
|
|
|
{
|
|
|
|
set_size(size);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
SetWindowTextW(hwndSizeList, sizeBuffer);
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hMainWnd, MAKEINTRESOURCEW(STRING_INVALID_NUMBER),
|
2008-06-18 03:19:15 +02:00
|
|
|
wszAppTitle, MB_OK | MB_ICONINFORMATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-24 19:45:54 +02:00
|
|
|
static void add_size(HWND hSizeListWnd, unsigned size)
|
|
|
|
{
|
|
|
|
WCHAR buffer[3];
|
|
|
|
COMBOBOXEXITEMW cbItem;
|
|
|
|
cbItem.mask = CBEIF_TEXT;
|
|
|
|
cbItem.iItem = -1;
|
|
|
|
|
|
|
|
wsprintfW(buffer, stringFormat, size);
|
2009-01-17 22:56:19 +01:00
|
|
|
cbItem.pszText = buffer;
|
2007-08-24 19:45:54 +02:00
|
|
|
SendMessageW(hSizeListWnd, CBEM_INSERTITEMW, 0, (LPARAM)&cbItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void populate_size_list(HWND hSizeListWnd)
|
|
|
|
{
|
|
|
|
HWND hReBarWnd = GetDlgItem(hMainWnd, IDC_REBAR);
|
|
|
|
HWND hFontListWnd = GetDlgItem(hReBarWnd, IDC_FONTLIST);
|
|
|
|
COMBOBOXEXITEMW cbFontItem;
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
HWND hListEditWnd = (HWND)SendMessageW(hSizeListWnd, CBEM_GETEDITCONTROL, 0, 0);
|
|
|
|
HDC hdc = GetDC(hMainWnd);
|
|
|
|
static const unsigned choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
|
|
|
|
WCHAR buffer[3];
|
2008-10-09 20:34:27 +02:00
|
|
|
size_t i;
|
2007-08-24 19:45:54 +02:00
|
|
|
DWORD fontStyle;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
|
|
|
|
cbFontItem.mask = CBEIF_LPARAM;
|
|
|
|
cbFontItem.iItem = SendMessageW(hFontListWnd, CB_FINDSTRINGEXACT, -1, (LPARAM)fmt.szFaceName);
|
|
|
|
SendMessageW(hFontListWnd, CBEM_GETITEMW, 0, (LPARAM)&cbFontItem);
|
|
|
|
|
|
|
|
fontStyle = (DWORD)LOWORD(cbFontItem.lParam);
|
|
|
|
|
|
|
|
SendMessageW(hSizeListWnd, CB_RESETCONTENT, 0, 0);
|
|
|
|
|
|
|
|
if((fontStyle & RASTER_FONTTYPE) && cbFontItem.iItem)
|
|
|
|
{
|
|
|
|
add_size(hSizeListWnd, (BYTE)MulDiv(HIWORD(cbFontItem.lParam), 72,
|
|
|
|
GetDeviceCaps(hdc, LOGPIXELSY)));
|
|
|
|
} else
|
|
|
|
{
|
2018-07-24 22:13:45 +02:00
|
|
|
for(i = 0; i < ARRAY_SIZE(choices); i++)
|
2007-08-24 19:45:54 +02:00
|
|
|
add_size(hSizeListWnd, choices[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
wsprintfW(buffer, stringFormat, fmt.yHeight / 20);
|
|
|
|
SendMessageW(hListEditWnd, WM_SETTEXT, 0, (LPARAM)buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_size_list(void)
|
|
|
|
{
|
|
|
|
HWND hReBar = GetDlgItem(hMainWnd, IDC_REBAR);
|
|
|
|
HWND hwndSizeList = GetDlgItem(hReBar, IDC_SIZELIST);
|
|
|
|
HWND hwndSizeListEdit = (HWND)SendMessageW(hwndSizeList, CBEM_GETEDITCONTROL, 0, 0);
|
|
|
|
WCHAR fontSize[MAX_STRING_LEN], sizeBuffer[MAX_STRING_LEN];
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
|
|
|
|
SendMessageW(hwndSizeListEdit, WM_GETTEXT, MAX_PATH, (LPARAM)fontSize);
|
|
|
|
wsprintfW(sizeBuffer, stringFormat, fmt.yHeight / 20);
|
|
|
|
|
|
|
|
if(lstrcmpW(fontSize, sizeBuffer))
|
|
|
|
SendMessageW(hwndSizeListEdit, WM_SETTEXT, 0, (LPARAM)sizeBuffer);
|
|
|
|
}
|
|
|
|
|
2007-08-24 15:46:09 +02:00
|
|
|
static void update_font_list(void)
|
|
|
|
{
|
|
|
|
HWND hReBar = GetDlgItem(hMainWnd, IDC_REBAR);
|
|
|
|
HWND hFontList = GetDlgItem(hReBar, IDC_FONTLIST);
|
|
|
|
HWND hFontListEdit = (HWND)SendMessageW(hFontList, CBEM_GETEDITCONTROL, 0, 0);
|
|
|
|
WCHAR fontName[MAX_STRING_LEN];
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
2008-03-23 09:22:51 +01:00
|
|
|
if (!SendMessageW(hFontListEdit, WM_GETTEXT, MAX_PATH, (LPARAM)fontName)) return;
|
2007-08-24 15:46:09 +02:00
|
|
|
|
|
|
|
if(lstrcmpW(fontName, fmt.szFaceName))
|
2007-08-24 19:45:54 +02:00
|
|
|
{
|
2007-08-24 15:46:09 +02:00
|
|
|
SendMessageW(hFontListEdit, WM_SETTEXT, 0, (LPARAM)fmt.szFaceName);
|
2007-08-24 19:45:54 +02:00
|
|
|
populate_size_list(GetDlgItem(hReBar, IDC_SIZELIST));
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
update_size_list();
|
|
|
|
}
|
2007-08-24 15:46:09 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 22:27:15 +02:00
|
|
|
static void clear_formatting(void)
|
|
|
|
{
|
|
|
|
PARAFORMAT2 pf;
|
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_ALIGNMENT;
|
|
|
|
pf.wAlignment = PFA_LEFT;
|
|
|
|
SendMessageW(hEditorWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
}
|
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
static int fileformat_number(WPARAM format)
|
|
|
|
{
|
|
|
|
int number = 0;
|
|
|
|
|
|
|
|
if(format == SF_TEXT)
|
|
|
|
{
|
|
|
|
number = 1;
|
|
|
|
} else if (format == (SF_TEXT | SF_UNICODE))
|
|
|
|
{
|
|
|
|
number = 2;
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WPARAM fileformat_flags(int format)
|
|
|
|
{
|
|
|
|
WPARAM flags[] = { SF_RTF , SF_TEXT , SF_TEXT | SF_UNICODE };
|
|
|
|
|
|
|
|
return flags[format];
|
|
|
|
}
|
|
|
|
|
2007-08-24 15:46:09 +02:00
|
|
|
static void set_font(LPCWSTR wszFaceName)
|
|
|
|
{
|
2007-08-24 19:45:54 +02:00
|
|
|
HWND hReBarWnd = GetDlgItem(hMainWnd, IDC_REBAR);
|
|
|
|
HWND hSizeListWnd = GetDlgItem(hReBarWnd, IDC_SIZELIST);
|
2007-08-25 16:54:02 +02:00
|
|
|
HWND hFontListWnd = GetDlgItem(hReBarWnd, IDC_FONTLIST);
|
|
|
|
HWND hFontListEditWnd = (HWND)SendMessageW(hFontListWnd, CBEM_GETEDITCONTROL, 0, 0);
|
2007-08-24 15:46:09 +02:00
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = CFM_FACE;
|
|
|
|
|
|
|
|
lstrcpyW(fmt.szFaceName, wszFaceName);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
2007-08-24 19:45:54 +02:00
|
|
|
|
|
|
|
populate_size_list(hSizeListWnd);
|
2007-08-25 16:54:02 +02:00
|
|
|
|
2008-10-09 20:34:27 +02:00
|
|
|
SendMessageW(hFontListEditWnd, WM_SETTEXT, 0, (LPARAM)wszFaceName);
|
2007-08-24 15:46:09 +02:00
|
|
|
}
|
|
|
|
|
2007-08-22 22:51:46 +02:00
|
|
|
static void set_default_font(void)
|
|
|
|
{
|
|
|
|
static const WCHAR richTextFont[] = {'T','i','m','e','s',' ','N','e','w',' ',
|
|
|
|
'R','o','m','a','n',0};
|
|
|
|
static const WCHAR plainTextFont[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
LPCWSTR font;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = CFM_FACE | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE;
|
|
|
|
fmt.dwEffects = 0;
|
|
|
|
|
|
|
|
if(fileFormat & SF_RTF)
|
|
|
|
font = richTextFont;
|
|
|
|
else
|
|
|
|
font = plainTextFont;
|
|
|
|
|
|
|
|
lstrcpyW(fmt.szFaceName, font);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM)&fmt);
|
|
|
|
}
|
|
|
|
|
2008-09-07 16:05:26 +02:00
|
|
|
static void on_fontlist_modified(LPWSTR wszNewFaceName)
|
2008-06-18 03:19:15 +02:00
|
|
|
{
|
|
|
|
CHARFORMAT2W format;
|
|
|
|
ZeroMemory(&format, sizeof(format));
|
|
|
|
format.cbSize = sizeof(format);
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
|
|
|
|
|
|
|
|
if(lstrcmpW(format.szFaceName, wszNewFaceName))
|
2009-01-17 22:56:19 +01:00
|
|
|
set_font(wszNewFaceName);
|
2008-06-18 03:19:15 +02:00
|
|
|
}
|
|
|
|
|
2007-08-25 16:54:02 +02:00
|
|
|
static void dialog_choose_font(void)
|
|
|
|
{
|
|
|
|
CHOOSEFONTW cf;
|
|
|
|
LOGFONTW lf;
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
HDC hDC = GetDC(hMainWnd);
|
|
|
|
|
|
|
|
ZeroMemory(&cf, sizeof(cf));
|
|
|
|
cf.lStructSize = sizeof(cf);
|
|
|
|
cf.hwndOwner = hMainWnd;
|
|
|
|
cf.lpLogFont = &lf;
|
2013-06-25 12:39:41 +02:00
|
|
|
cf.Flags = CF_SCREENFONTS | CF_NOSCRIPTSEL | CF_INITTOLOGFONTSTRUCT | CF_EFFECTS | CF_NOVERTFONTS;
|
2007-08-25 16:54:02 +02:00
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
lstrcpyW(cf.lpLogFont->lfFaceName, fmt.szFaceName);
|
2012-08-08 21:42:16 +02:00
|
|
|
cf.lpLogFont->lfItalic = (fmt.dwEffects & CFE_ITALIC) != 0;
|
2007-08-25 16:54:02 +02:00
|
|
|
cf.lpLogFont->lfWeight = (fmt.dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
|
2012-08-08 21:42:16 +02:00
|
|
|
cf.lpLogFont->lfUnderline = (fmt.dwEffects & CFE_UNDERLINE) != 0;
|
|
|
|
cf.lpLogFont->lfStrikeOut = (fmt.dwEffects & CFE_STRIKEOUT) != 0;
|
2007-08-25 16:54:02 +02:00
|
|
|
cf.lpLogFont->lfHeight = -MulDiv(fmt.yHeight / 20, GetDeviceCaps(hDC, LOGPIXELSY), 72);
|
2007-08-26 18:37:08 +02:00
|
|
|
cf.rgbColors = fmt.crTextColor;
|
2007-08-25 16:54:02 +02:00
|
|
|
|
|
|
|
if(ChooseFontW(&cf))
|
|
|
|
{
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
2007-08-26 18:37:08 +02:00
|
|
|
fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR;
|
2007-08-25 16:54:02 +02:00
|
|
|
fmt.yHeight = cf.iPointSize * 2;
|
|
|
|
|
|
|
|
if(cf.nFontType & BOLD_FONTTYPE)
|
|
|
|
fmt.dwEffects |= CFE_BOLD;
|
|
|
|
if(cf.nFontType & ITALIC_FONTTYPE)
|
|
|
|
fmt.dwEffects |= CFE_ITALIC;
|
2011-10-01 21:44:54 +02:00
|
|
|
if(cf.lpLogFont->lfUnderline)
|
2007-08-26 18:37:08 +02:00
|
|
|
fmt.dwEffects |= CFE_UNDERLINE;
|
2011-10-01 21:44:54 +02:00
|
|
|
if(cf.lpLogFont->lfStrikeOut)
|
2007-08-26 18:37:08 +02:00
|
|
|
fmt.dwEffects |= CFE_STRIKEOUT;
|
|
|
|
|
|
|
|
fmt.crTextColor = cf.rgbColors;
|
2007-08-25 16:54:02 +02:00
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
set_font(cf.lpLogFont->lfFaceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 09:16:16 +01:00
|
|
|
struct font_desc
|
|
|
|
{
|
|
|
|
WCHAR *name;
|
|
|
|
LPARAM lParam;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct font_array
|
|
|
|
{
|
|
|
|
struct font_desc *fonts;
|
|
|
|
size_t count;
|
|
|
|
size_t capacity;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL array_reserve(void **elements, size_t *capacity, size_t count, size_t size)
|
|
|
|
{
|
|
|
|
size_t new_capacity, max_capacity;
|
|
|
|
void *new_elements;
|
|
|
|
|
|
|
|
if (count <= *capacity)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
max_capacity = ~(SIZE_T)0 / size;
|
|
|
|
if (count > max_capacity)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
new_capacity = max(4, *capacity);
|
|
|
|
while (new_capacity < count && new_capacity <= max_capacity / 2)
|
|
|
|
new_capacity *= 2;
|
|
|
|
if (new_capacity < count)
|
|
|
|
new_capacity = max_capacity;
|
|
|
|
|
|
|
|
new_elements = *elements ? HeapReAlloc(GetProcessHeap(), 0, *elements, new_capacity * size) :
|
|
|
|
HeapAlloc(GetProcessHeap(), 0, new_capacity * size);
|
|
|
|
if (!new_elements)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*elements = new_elements;
|
|
|
|
*capacity = new_capacity;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_font(struct font_array *fonts, LPCWSTR fontName, DWORD fontType, const NEWTEXTMETRICEXW *ntmc)
|
|
|
|
{
|
|
|
|
int fontHeight = 0;
|
|
|
|
size_t idx;
|
|
|
|
|
|
|
|
if (!array_reserve((void **)&fonts->fonts, &fonts->capacity, fonts->count + 1, sizeof(*fonts->fonts)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fontType & RASTER_FONTTYPE)
|
|
|
|
fontHeight = ntmc->ntmTm.tmHeight - ntmc->ntmTm.tmInternalLeading;
|
|
|
|
|
|
|
|
idx = fonts->count;
|
|
|
|
fonts->fonts[idx].name = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(fontName) + 1)*sizeof(WCHAR) );
|
|
|
|
lstrcpyW( fonts->fonts[idx].name, fontName );
|
|
|
|
fonts->fonts[idx].lParam = MAKELONG(fontType, fontHeight);
|
|
|
|
|
|
|
|
fonts->count++;
|
|
|
|
}
|
2007-08-25 16:54:02 +02:00
|
|
|
|
2008-10-09 20:34:27 +02:00
|
|
|
static int CALLBACK enum_font_proc(const LOGFONTW *lpelfe, const TEXTMETRICW *lpntme,
|
2007-08-25 16:54:02 +02:00
|
|
|
DWORD FontType, LPARAM lParam)
|
2007-08-24 15:46:09 +02:00
|
|
|
{
|
2020-11-13 09:16:16 +01:00
|
|
|
struct font_array *fonts = (void *)lParam;
|
2007-08-24 15:46:09 +02:00
|
|
|
|
2013-06-25 12:39:41 +02:00
|
|
|
if (lpelfe->lfFaceName[0] == '@') return 1; /* ignore vertical fonts */
|
|
|
|
|
2020-11-13 09:16:16 +01:00
|
|
|
add_font(fonts, lpelfe->lfFaceName, FontType, (const NEWTEXTMETRICEXW *)lpntme);
|
2007-08-24 15:46:09 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-01-16 11:45:39 +01:00
|
|
|
static int __cdecl fonts_desc_compare(const void *a, const void *b)
|
2020-11-13 09:16:16 +01:00
|
|
|
{
|
|
|
|
const struct font_desc *left = a, *right = b;
|
|
|
|
return lstrcmpiW(left->name, right->name);
|
|
|
|
}
|
|
|
|
|
2007-08-24 15:46:09 +02:00
|
|
|
static void populate_font_list(HWND hListWnd)
|
|
|
|
{
|
2020-11-13 09:16:16 +01:00
|
|
|
struct font_array font_array = { 0 };
|
2007-08-24 15:46:09 +02:00
|
|
|
HDC hdc = GetDC(hMainWnd);
|
|
|
|
LOGFONTW fontinfo;
|
|
|
|
HWND hListEditWnd = (HWND)SendMessageW(hListWnd, CBEM_GETEDITCONTROL, 0, 0);
|
|
|
|
CHARFORMAT2W fmt;
|
2020-11-13 09:16:16 +01:00
|
|
|
size_t i, j;
|
2007-08-24 15:46:09 +02:00
|
|
|
|
|
|
|
fontinfo.lfCharSet = DEFAULT_CHARSET;
|
|
|
|
*fontinfo.lfFaceName = '\0';
|
|
|
|
fontinfo.lfPitchAndFamily = 0;
|
|
|
|
|
2020-11-13 09:16:16 +01:00
|
|
|
/* Collect font names, sort, remove duplicates. */
|
|
|
|
EnumFontFamiliesExW(hdc, &fontinfo, enum_font_proc, (LPARAM)&font_array, 0);
|
|
|
|
|
|
|
|
qsort(font_array.fonts, font_array.count, sizeof(*font_array.fonts), fonts_desc_compare);
|
|
|
|
|
|
|
|
for (i = 1, j = 0; i < font_array.count; ++i)
|
|
|
|
{
|
|
|
|
if (!lstrcmpiW(font_array.fonts[i].name, font_array.fonts[j].name))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, font_array.fonts[i].name);
|
|
|
|
font_array.fonts[i].name = NULL;
|
|
|
|
}
|
|
|
|
else if (++j != i)
|
|
|
|
{
|
|
|
|
font_array.fonts[j] = font_array.fonts[i];
|
|
|
|
font_array.fonts[i].name = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font_array.count = j + 1;
|
|
|
|
|
|
|
|
for (i = 0; i < font_array.count; ++i)
|
|
|
|
{
|
|
|
|
COMBOBOXEXITEMW cbitem = { 0 };
|
|
|
|
|
|
|
|
cbitem.mask = CBEIF_TEXT | CBEIF_LPARAM;
|
|
|
|
cbitem.pszText = font_array.fonts[i].name;
|
|
|
|
cbitem.iItem = -1;
|
|
|
|
cbitem.lParam = font_array.fonts[i].lParam;
|
|
|
|
|
|
|
|
SendMessageW(hListWnd, CBEM_INSERTITEMW, 0, (LPARAM)&cbitem);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, font_array.fonts[i].name);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, font_array.fonts);
|
2007-08-24 15:46:09 +02:00
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
SendMessageW(hEditorWnd, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&fmt);
|
|
|
|
SendMessageW(hListEditWnd, WM_SETTEXT, 0, (LPARAM)fmt.szFaceName);
|
|
|
|
}
|
|
|
|
|
2007-08-22 22:41:25 +02:00
|
|
|
static void update_window(void)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
2008-06-27 12:05:44 +02:00
|
|
|
GetClientRect(hMainWnd, &rect);
|
2007-08-22 22:41:25 +02:00
|
|
|
|
2008-06-27 12:05:44 +02:00
|
|
|
OnSize(hMainWnd, SIZE_RESTORED, MAKELPARAM(rect.right, rect.bottom));
|
2007-08-22 22:41:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL is_bar_visible(int bandId)
|
|
|
|
{
|
|
|
|
return barState[reg_formatindex(fileFormat)] & (1 << bandId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void store_bar_state(int bandId, BOOL show)
|
|
|
|
{
|
|
|
|
int formatIndex = reg_formatindex(fileFormat);
|
|
|
|
|
|
|
|
if(show)
|
|
|
|
barState[formatIndex] |= (1 << bandId);
|
|
|
|
else
|
|
|
|
barState[formatIndex] &= ~(1 << bandId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_toolbar_state(int bandId, BOOL show)
|
|
|
|
{
|
|
|
|
HWND hwndReBar = GetDlgItem(hMainWnd, IDC_REBAR);
|
|
|
|
|
|
|
|
SendMessageW(hwndReBar, RB_SHOWBAND, SendMessageW(hwndReBar, RB_IDTOINDEX, bandId, 0), show);
|
|
|
|
|
|
|
|
if(bandId == BANDID_TOOLBAR)
|
|
|
|
{
|
|
|
|
REBARBANDINFOW rbbinfo;
|
2007-08-24 15:46:09 +02:00
|
|
|
int index = SendMessageW(hwndReBar, RB_IDTOINDEX, BANDID_FONTLIST, 0);
|
2007-08-22 22:41:25 +02:00
|
|
|
|
2009-08-15 04:23:21 +02:00
|
|
|
rbbinfo.cbSize = REBARBANDINFOW_V6_SIZE;
|
2007-08-22 22:41:25 +02:00
|
|
|
rbbinfo.fMask = RBBIM_STYLE;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hwndReBar, RB_GETBANDINFOW, index, (LPARAM)&rbbinfo);
|
2007-08-22 22:41:25 +02:00
|
|
|
|
|
|
|
if(!show)
|
|
|
|
rbbinfo.fStyle &= ~RBBS_BREAK;
|
|
|
|
else
|
|
|
|
rbbinfo.fStyle |= RBBS_BREAK;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hwndReBar, RB_SETBANDINFOW, index, (LPARAM)&rbbinfo);
|
2007-08-22 22:41:25 +02:00
|
|
|
}
|
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
if(bandId == BANDID_TOOLBAR || bandId == BANDID_FORMATBAR || bandId == BANDID_RULER)
|
2007-08-22 22:41:25 +02:00
|
|
|
store_bar_state(bandId, show);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_statusbar_state(BOOL show)
|
|
|
|
{
|
|
|
|
HWND hStatusWnd = GetDlgItem(hMainWnd, IDC_STATUSBAR);
|
|
|
|
|
|
|
|
ShowWindow(hStatusWnd, show ? SW_SHOW : SW_HIDE);
|
|
|
|
store_bar_state(BANDID_STATUSBAR, show);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_bar_states(void)
|
|
|
|
{
|
|
|
|
set_toolbar_state(BANDID_TOOLBAR, is_bar_visible(BANDID_TOOLBAR));
|
2007-08-24 15:46:09 +02:00
|
|
|
set_toolbar_state(BANDID_FONTLIST, is_bar_visible(BANDID_FORMATBAR));
|
2007-08-24 19:45:54 +02:00
|
|
|
set_toolbar_state(BANDID_SIZELIST, is_bar_visible(BANDID_FORMATBAR));
|
2007-08-22 22:41:25 +02:00
|
|
|
set_toolbar_state(BANDID_FORMATBAR, is_bar_visible(BANDID_FORMATBAR));
|
2008-01-14 00:36:23 +01:00
|
|
|
set_toolbar_state(BANDID_RULER, is_bar_visible(BANDID_RULER));
|
2007-08-22 22:41:25 +02:00
|
|
|
set_statusbar_state(is_bar_visible(BANDID_STATUSBAR));
|
|
|
|
|
|
|
|
update_window();
|
|
|
|
}
|
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
static void preview_exit(HWND hMainWnd)
|
2007-08-23 15:08:41 +02:00
|
|
|
{
|
2009-12-23 17:10:23 +01:00
|
|
|
HMENU hMenu = LoadMenuW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDM_MAINMENU));
|
2007-11-11 01:06:46 +01:00
|
|
|
HWND hEditorWnd = GetDlgItem(hMainWnd, IDC_EDITOR);
|
2007-08-23 15:08:41 +02:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
set_bar_states();
|
|
|
|
ShowWindow(hEditorWnd, TRUE);
|
2007-08-23 15:08:41 +02:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
close_preview(hMainWnd);
|
2007-08-23 15:08:41 +02:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
SetMenu(hMainWnd, hMenu);
|
|
|
|
registry_read_filelist(hMainWnd);
|
2007-08-23 15:08:41 +02:00
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
update_window();
|
2007-08-23 15:08:41 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
static void set_fileformat(WPARAM format)
|
|
|
|
{
|
|
|
|
fileFormat = format;
|
2007-08-22 22:41:25 +02:00
|
|
|
|
|
|
|
set_bar_states();
|
2007-08-22 22:51:46 +02:00
|
|
|
set_default_font();
|
2007-11-11 01:06:46 +01:00
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-07-18 21:59:24 +02:00
|
|
|
}
|
|
|
|
|
2008-07-17 16:58:07 +02:00
|
|
|
static void ShowOpenError(DWORD Code)
|
|
|
|
{
|
|
|
|
LPWSTR Message;
|
|
|
|
|
|
|
|
switch(Code)
|
|
|
|
{
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
Message = MAKEINTRESOURCEW(STRING_OPEN_ACCESS_DENIED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Message = MAKEINTRESOURCEW(STRING_OPEN_FAILED);
|
|
|
|
}
|
|
|
|
MessageBoxW(hMainWnd, Message, wszAppTitle, MB_ICONEXCLAMATION | MB_OK);
|
|
|
|
}
|
|
|
|
|
2007-05-30 14:42:36 +02:00
|
|
|
static void DoOpenFile(LPCWSTR szOpenFileName)
|
2007-02-10 22:55:29 +01:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
EDITSTREAM es;
|
2007-07-18 21:59:24 +02:00
|
|
|
char fileStart[5];
|
|
|
|
DWORD readOut;
|
|
|
|
WPARAM format = SF_TEXT;
|
2007-02-10 22:55:29 +01:00
|
|
|
|
2007-05-30 14:42:36 +02:00
|
|
|
hFile = CreateFileW(szOpenFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
2007-02-10 22:55:29 +01:00
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
2008-07-17 16:58:07 +02:00
|
|
|
{
|
|
|
|
ShowOpenError(GetLastError());
|
2007-02-10 22:55:29 +01:00
|
|
|
return;
|
2008-07-17 16:58:07 +02:00
|
|
|
}
|
2007-02-10 22:55:29 +01:00
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
ReadFile(hFile, fileStart, 5, &readOut, NULL);
|
|
|
|
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
|
|
|
|
|
|
|
|
if(readOut >= 2 && (BYTE)fileStart[0] == 0xff && (BYTE)fileStart[1] == 0xfe)
|
|
|
|
{
|
|
|
|
format = SF_TEXT | SF_UNICODE;
|
|
|
|
SetFilePointer(hFile, 2, NULL, FILE_BEGIN);
|
|
|
|
} else if(readOut >= 5)
|
|
|
|
{
|
|
|
|
static const char header[] = "{\\rtf";
|
2007-10-16 15:07:31 +02:00
|
|
|
static const BYTE STG_magic[] = { 0xd0,0xcf,0x11,0xe0 };
|
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
if(!memcmp(header, fileStart, 5))
|
|
|
|
format = SF_RTF;
|
2007-10-16 15:07:31 +02:00
|
|
|
else if (!memcmp(STG_magic, fileStart, sizeof(STG_magic)))
|
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hMainWnd, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED),
|
|
|
|
wszAppTitle, MB_OK | MB_ICONEXCLAMATION);
|
2007-10-16 15:07:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-07-18 21:59:24 +02:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:19:37 +02:00
|
|
|
es.dwCookie = (DWORD_PTR)hFile;
|
2007-02-10 22:55:29 +01:00
|
|
|
es.pfnCallback = stream_in;
|
|
|
|
|
2007-07-18 22:31:14 +02:00
|
|
|
clear_formatting();
|
2007-08-22 22:51:46 +02:00
|
|
|
set_fileformat(format);
|
2007-07-18 21:59:24 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_STREAMIN, format, (LPARAM)&es);
|
2007-02-10 22:55:29 +01:00
|
|
|
|
2007-06-02 00:19:37 +02:00
|
|
|
CloseHandle(hFile);
|
2007-02-10 22:55:29 +01:00
|
|
|
|
|
|
|
SetFocus(hEditorWnd);
|
2007-02-25 14:40:27 +01:00
|
|
|
|
2007-05-30 14:42:36 +02:00
|
|
|
set_caption(szOpenFileName);
|
2007-05-30 14:56:20 +02:00
|
|
|
|
|
|
|
lstrcpyW(wszFileName, szOpenFileName);
|
2007-07-08 13:51:19 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_SETMODIFY, FALSE, 0);
|
2007-12-12 09:36:41 +01:00
|
|
|
registry_set_filelist(szOpenFileName, hMainWnd);
|
2007-08-24 15:46:09 +02:00
|
|
|
update_font_list();
|
2007-02-10 22:55:29 +01:00
|
|
|
}
|
|
|
|
|
2008-07-11 20:38:50 +02:00
|
|
|
static void ShowWriteError(DWORD Code)
|
|
|
|
{
|
|
|
|
LPWSTR Message;
|
|
|
|
|
|
|
|
switch(Code)
|
|
|
|
{
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
Message = MAKEINTRESOURCEW(STRING_WRITE_ACCESS_DENIED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Message = MAKEINTRESOURCEW(STRING_WRITE_FAILED);
|
|
|
|
}
|
|
|
|
MessageBoxW(hMainWnd, Message, wszAppTitle, MB_ICONEXCLAMATION | MB_OK);
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:50:57 +02:00
|
|
|
static BOOL DoSaveFile(LPCWSTR wszSaveFileName, WPARAM format)
|
2007-06-02 00:07:02 +02:00
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
EDITSTREAM stream;
|
|
|
|
LRESULT ret;
|
|
|
|
|
|
|
|
hFile = CreateFileW(wszSaveFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if(hFile == INVALID_HANDLE_VALUE)
|
2008-07-11 20:38:50 +02:00
|
|
|
{
|
|
|
|
ShowWriteError(GetLastError());
|
2012-04-11 14:50:57 +02:00
|
|
|
return FALSE;
|
2008-07-11 20:38:50 +02:00
|
|
|
}
|
2007-06-02 00:07:02 +02:00
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
if(format == (SF_TEXT | SF_UNICODE))
|
|
|
|
{
|
|
|
|
static const BYTE unicode[] = {0xff,0xfe};
|
|
|
|
DWORD writeOut;
|
|
|
|
WriteFile(hFile, &unicode, sizeof(unicode), &writeOut, 0);
|
|
|
|
|
|
|
|
if(writeOut != sizeof(unicode))
|
2008-10-12 13:09:45 +02:00
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
2012-04-11 14:50:57 +02:00
|
|
|
return FALSE;
|
2008-10-12 13:09:45 +02:00
|
|
|
}
|
2007-07-18 21:59:24 +02:00
|
|
|
}
|
|
|
|
|
2007-06-02 00:07:02 +02:00
|
|
|
stream.dwCookie = (DWORD_PTR)hFile;
|
|
|
|
stream.pfnCallback = stream_out;
|
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
ret = SendMessageW(hEditorWnd, EM_STREAMOUT, format, (LPARAM)&stream);
|
2007-06-02 00:07:02 +02:00
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
|
|
|
SetFocus(hEditorWnd);
|
|
|
|
|
|
|
|
if(!ret)
|
2007-07-18 20:47:40 +02:00
|
|
|
{
|
|
|
|
GETTEXTLENGTHEX gt;
|
|
|
|
gt.flags = GTL_DEFAULT;
|
|
|
|
gt.codepage = 1200;
|
|
|
|
|
|
|
|
if(SendMessageW(hEditorWnd, EM_GETTEXTLENGTHEX, (WPARAM)>, 0))
|
2012-04-11 14:50:57 +02:00
|
|
|
return FALSE;
|
2007-07-18 20:47:40 +02:00
|
|
|
}
|
2007-06-02 00:07:02 +02:00
|
|
|
|
|
|
|
lstrcpyW(wszFileName, wszSaveFileName);
|
|
|
|
set_caption(wszFileName);
|
2007-07-08 13:51:19 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_SETMODIFY, FALSE, 0);
|
2007-07-18 21:59:24 +02:00
|
|
|
set_fileformat(format);
|
2012-04-11 14:50:57 +02:00
|
|
|
|
|
|
|
return TRUE;
|
2007-06-02 00:07:02 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 14:50:57 +02:00
|
|
|
static BOOL DialogSaveFile(void)
|
2007-05-31 15:38:51 +02:00
|
|
|
{
|
|
|
|
OPENFILENAMEW sfn;
|
|
|
|
|
|
|
|
WCHAR wszFile[MAX_PATH] = {'\0'};
|
|
|
|
static const WCHAR wszDefExt[] = {'r','t','f','\0'};
|
|
|
|
|
|
|
|
ZeroMemory(&sfn, sizeof(sfn));
|
|
|
|
|
|
|
|
sfn.lStructSize = sizeof(sfn);
|
2009-05-06 08:41:15 +02:00
|
|
|
sfn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_ENABLESIZING;
|
2007-05-31 15:38:51 +02:00
|
|
|
sfn.hwndOwner = hMainWnd;
|
|
|
|
sfn.lpstrFilter = wszFilter;
|
|
|
|
sfn.lpstrFile = wszFile;
|
|
|
|
sfn.nMaxFile = MAX_PATH;
|
|
|
|
sfn.lpstrDefExt = wszDefExt;
|
2007-07-18 21:59:24 +02:00
|
|
|
sfn.nFilterIndex = fileformat_number(fileFormat)+1;
|
2007-05-31 15:38:51 +02:00
|
|
|
|
2007-07-18 21:59:24 +02:00
|
|
|
while(GetSaveFileNameW(&sfn))
|
|
|
|
{
|
|
|
|
if(fileformat_flags(sfn.nFilterIndex-1) != SF_RTF)
|
|
|
|
{
|
2008-10-21 09:07:09 +02:00
|
|
|
if(MessageBoxWithResStringW(hMainWnd, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING),
|
2007-07-18 21:59:24 +02:00
|
|
|
wszAppTitle, MB_YESNO | MB_ICONEXCLAMATION) != IDYES)
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-11 14:50:57 +02:00
|
|
|
return DoSaveFile(sfn.lpstrFile, fileformat_flags(sfn.nFilterIndex-1));
|
2007-07-18 21:59:24 +02:00
|
|
|
}
|
2012-04-11 14:50:57 +02:00
|
|
|
return FALSE;
|
2007-05-31 15:38:51 +02:00
|
|
|
}
|
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
static BOOL prompt_save_changes(void)
|
|
|
|
{
|
|
|
|
if(!wszFileName[0])
|
|
|
|
{
|
|
|
|
GETTEXTLENGTHEX gt;
|
|
|
|
gt.flags = GTL_NUMCHARS;
|
|
|
|
gt.codepage = 1200;
|
|
|
|
if(!SendMessageW(hEditorWnd, EM_GETTEXTLENGTHEX, (WPARAM)>, 0))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!SendMessageW(hEditorWnd, EM_GETMODIFY, 0, 0))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
LPWSTR displayFileName;
|
|
|
|
WCHAR *text;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if(!wszFileName[0])
|
|
|
|
displayFileName = wszDefaultFileName;
|
|
|
|
else
|
2007-08-22 22:52:19 +02:00
|
|
|
displayFileName = file_basename(wszFileName);
|
2007-07-08 13:51:19 +02:00
|
|
|
|
|
|
|
text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
(lstrlenW(displayFileName)+lstrlenW(wszSaveChanges))*sizeof(WCHAR));
|
|
|
|
|
|
|
|
if(!text)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wsprintfW(text, wszSaveChanges, displayFileName);
|
|
|
|
|
|
|
|
ret = MessageBoxW(hMainWnd, text, wszAppTitle, MB_YESNOCANCEL | MB_ICONEXCLAMATION);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, text);
|
|
|
|
|
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case IDNO:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case IDYES:
|
|
|
|
if(wszFileName[0])
|
2012-04-11 14:50:57 +02:00
|
|
|
return DoSaveFile(wszFileName, fileFormat);
|
|
|
|
return DialogSaveFile();
|
2007-07-08 13:51:19 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DialogOpenFile(void)
|
|
|
|
{
|
|
|
|
OPENFILENAMEW ofn;
|
|
|
|
|
|
|
|
WCHAR wszFile[MAX_PATH] = {'\0'};
|
|
|
|
static const WCHAR wszDefExt[] = {'r','t','f','\0'};
|
|
|
|
|
|
|
|
ZeroMemory(&ofn, sizeof(ofn));
|
|
|
|
|
|
|
|
ofn.lStructSize = sizeof(ofn);
|
2009-05-06 08:41:15 +02:00
|
|
|
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ENABLESIZING;
|
2007-07-08 13:51:19 +02:00
|
|
|
ofn.hwndOwner = hMainWnd;
|
|
|
|
ofn.lpstrFilter = wszFilter;
|
|
|
|
ofn.lpstrFile = wszFile;
|
|
|
|
ofn.nMaxFile = MAX_PATH;
|
|
|
|
ofn.lpstrDefExt = wszDefExt;
|
2007-07-18 21:59:24 +02:00
|
|
|
ofn.nFilterIndex = fileformat_number(fileFormat)+1;
|
2007-07-08 13:51:19 +02:00
|
|
|
|
|
|
|
if(GetOpenFileNameW(&ofn))
|
|
|
|
{
|
2007-07-20 00:04:09 +02:00
|
|
|
if(prompt_save_changes())
|
|
|
|
DoOpenFile(ofn.lpstrFile);
|
2007-07-08 13:51:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-23 15:05:40 +02:00
|
|
|
static void dialog_about(void)
|
|
|
|
{
|
2009-12-23 17:10:23 +01:00
|
|
|
HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_WORDPAD), IMAGE_ICON, 48, 48, LR_SHARED);
|
2007-08-23 15:05:40 +02:00
|
|
|
ShellAboutW(hMainWnd, wszAppTitle, 0, icon);
|
|
|
|
}
|
|
|
|
|
2007-08-23 15:08:41 +02:00
|
|
|
static INT_PTR CALLBACK formatopts_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
LPPROPSHEETPAGEW ps = (LPPROPSHEETPAGEW)lParam;
|
|
|
|
int wrap = -1;
|
|
|
|
char id[4];
|
|
|
|
HWND hIdWnd = GetDlgItem(hWnd, IDC_PAGEFMT_ID);
|
|
|
|
|
|
|
|
sprintf(id, "%d\n", (int)ps->lParam);
|
|
|
|
SetWindowTextA(hIdWnd, id);
|
2008-10-14 00:48:41 +02:00
|
|
|
if(wordWrap[ps->lParam] == ID_WORDWRAP_NONE)
|
|
|
|
wrap = IDC_PAGEFMT_WN;
|
|
|
|
else if(wordWrap[ps->lParam] == ID_WORDWRAP_WINDOW)
|
2007-08-23 15:08:41 +02:00
|
|
|
wrap = IDC_PAGEFMT_WW;
|
|
|
|
else if(wordWrap[ps->lParam] == ID_WORDWRAP_MARGIN)
|
|
|
|
wrap = IDC_PAGEFMT_WM;
|
|
|
|
|
|
|
|
if(wrap != -1)
|
2008-10-14 00:48:41 +02:00
|
|
|
CheckRadioButton(hWnd, IDC_PAGEFMT_WN,
|
2007-08-23 15:08:41 +02:00
|
|
|
IDC_PAGEFMT_WM, wrap);
|
|
|
|
|
|
|
|
if(barState[ps->lParam] & (1 << BANDID_TOOLBAR))
|
|
|
|
CheckDlgButton(hWnd, IDC_PAGEFMT_TB, TRUE);
|
|
|
|
if(barState[ps->lParam] & (1 << BANDID_FORMATBAR))
|
|
|
|
CheckDlgButton(hWnd, IDC_PAGEFMT_FB, TRUE);
|
2008-01-14 00:36:23 +01:00
|
|
|
if(barState[ps->lParam] & (1 << BANDID_RULER))
|
|
|
|
CheckDlgButton(hWnd, IDC_PAGEFMT_RU, TRUE);
|
|
|
|
if(barState[ps->lParam] & (1 << BANDID_STATUSBAR))
|
2007-08-23 15:08:41 +02:00
|
|
|
CheckDlgButton(hWnd, IDC_PAGEFMT_SB, TRUE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
2008-10-14 00:48:41 +02:00
|
|
|
case IDC_PAGEFMT_WN:
|
2007-08-23 15:08:41 +02:00
|
|
|
case IDC_PAGEFMT_WW:
|
|
|
|
case IDC_PAGEFMT_WM:
|
2008-10-14 00:48:41 +02:00
|
|
|
CheckRadioButton(hWnd, IDC_PAGEFMT_WN, IDC_PAGEFMT_WM,
|
2007-08-23 15:08:41 +02:00
|
|
|
LOWORD(wParam));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_PAGEFMT_TB:
|
|
|
|
case IDC_PAGEFMT_FB:
|
2008-01-14 00:36:23 +01:00
|
|
|
case IDC_PAGEFMT_RU:
|
2007-08-23 15:08:41 +02:00
|
|
|
case IDC_PAGEFMT_SB:
|
|
|
|
CheckDlgButton(hWnd, LOWORD(wParam),
|
|
|
|
!IsDlgButtonChecked(hWnd, LOWORD(wParam)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
LPNMHDR header = (LPNMHDR)lParam;
|
|
|
|
if(header->code == PSN_APPLY)
|
|
|
|
{
|
|
|
|
HWND hIdWnd = GetDlgItem(hWnd, IDC_PAGEFMT_ID);
|
|
|
|
char sid[4];
|
|
|
|
int id;
|
|
|
|
|
|
|
|
GetWindowTextA(hIdWnd, sid, 4);
|
|
|
|
id = atoi(sid);
|
2008-10-14 00:48:41 +02:00
|
|
|
if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_WN))
|
|
|
|
wordWrap[id] = ID_WORDWRAP_NONE;
|
|
|
|
else if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_WW))
|
2007-08-23 15:08:41 +02:00
|
|
|
wordWrap[id] = ID_WORDWRAP_WINDOW;
|
|
|
|
else if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_WM))
|
|
|
|
wordWrap[id] = ID_WORDWRAP_MARGIN;
|
|
|
|
|
|
|
|
if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_TB))
|
|
|
|
barState[id] |= (1 << BANDID_TOOLBAR);
|
|
|
|
else
|
|
|
|
barState[id] &= ~(1 << BANDID_TOOLBAR);
|
|
|
|
|
|
|
|
if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_FB))
|
|
|
|
barState[id] |= (1 << BANDID_FORMATBAR);
|
|
|
|
else
|
|
|
|
barState[id] &= ~(1 << BANDID_FORMATBAR);
|
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_RU))
|
|
|
|
barState[id] |= (1 << BANDID_RULER);
|
|
|
|
else
|
|
|
|
barState[id] &= ~(1 << BANDID_RULER);
|
|
|
|
|
2007-08-23 15:08:41 +02:00
|
|
|
if(IsDlgButtonChecked(hWnd, IDC_PAGEFMT_SB))
|
|
|
|
barState[id] |= (1 << BANDID_STATUSBAR);
|
|
|
|
else
|
|
|
|
barState[id] &= ~(1 << BANDID_STATUSBAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dialog_viewproperties(void)
|
|
|
|
{
|
|
|
|
PROPSHEETPAGEW psp[2];
|
|
|
|
PROPSHEETHEADERW psh;
|
2008-10-09 20:34:27 +02:00
|
|
|
size_t i;
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2007-08-23 15:08:41 +02:00
|
|
|
LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)&psp;
|
|
|
|
|
|
|
|
psp[0].dwSize = sizeof(PROPSHEETPAGEW);
|
|
|
|
psp[0].dwFlags = PSP_USETITLE;
|
2007-09-18 00:39:11 +02:00
|
|
|
U(psp[0]).pszTemplate = MAKEINTRESOURCEW(IDD_FORMATOPTS);
|
2007-08-23 15:08:41 +02:00
|
|
|
psp[0].pfnDlgProc = formatopts_proc;
|
|
|
|
psp[0].hInstance = hInstance;
|
|
|
|
psp[0].lParam = reg_formatindex(SF_TEXT);
|
|
|
|
psp[0].pfnCallback = NULL;
|
|
|
|
psp[0].pszTitle = MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT);
|
2018-07-24 22:13:45 +02:00
|
|
|
for(i = 1; i < ARRAY_SIZE(psp); i++)
|
2007-08-23 15:08:41 +02:00
|
|
|
{
|
|
|
|
psp[i].dwSize = psp[0].dwSize;
|
|
|
|
psp[i].dwFlags = psp[0].dwFlags;
|
2007-09-18 00:39:11 +02:00
|
|
|
U(psp[i]).pszTemplate = U(psp[0]).pszTemplate;
|
2007-08-23 15:08:41 +02:00
|
|
|
psp[i].pfnDlgProc = psp[0].pfnDlgProc;
|
|
|
|
psp[i].hInstance = psp[0].hInstance;
|
|
|
|
psp[i].lParam = reg_formatindex(SF_RTF);
|
|
|
|
psp[i].pfnCallback = psp[0].pfnCallback;
|
|
|
|
psp[i].pszTitle = MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
psh.dwSize = sizeof(psh);
|
|
|
|
psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
|
|
|
|
psh.hwndParent = hMainWnd;
|
|
|
|
psh.hInstance = hInstance;
|
|
|
|
psh.pszCaption = MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE);
|
2018-07-24 22:13:45 +02:00
|
|
|
psh.nPages = ARRAY_SIZE(psp);
|
2007-09-18 00:39:11 +02:00
|
|
|
U3(psh).ppsp = ppsp;
|
|
|
|
U(psh).pszIcon = MAKEINTRESOURCEW(IDI_WORDPAD);
|
2007-08-23 15:08:41 +02:00
|
|
|
|
|
|
|
if(fileFormat & SF_RTF)
|
2007-09-18 00:39:11 +02:00
|
|
|
U2(psh).nStartPage = 1;
|
2007-08-23 15:08:41 +02:00
|
|
|
else
|
2007-09-18 00:39:11 +02:00
|
|
|
U2(psh).nStartPage = 0;
|
2007-08-23 15:08:41 +02:00
|
|
|
PropertySheetW(&psh);
|
|
|
|
set_bar_states();
|
2007-11-11 01:06:46 +01:00
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-08-23 15:08:41 +02:00
|
|
|
}
|
|
|
|
|
2007-02-10 22:55:29 +01:00
|
|
|
static void HandleCommandLine(LPWSTR cmdline)
|
|
|
|
{
|
|
|
|
WCHAR delimiter;
|
2013-11-02 14:34:15 +01:00
|
|
|
BOOL opt_print = FALSE;
|
2007-02-10 22:55:29 +01:00
|
|
|
|
|
|
|
/* skip white space */
|
|
|
|
while (*cmdline == ' ') cmdline++;
|
|
|
|
|
|
|
|
/* skip executable name */
|
|
|
|
delimiter = (*cmdline == '"' ? '"' : ' ');
|
|
|
|
|
|
|
|
if (*cmdline == delimiter) cmdline++;
|
|
|
|
while (*cmdline && *cmdline != delimiter) cmdline++;
|
|
|
|
if (*cmdline == delimiter) cmdline++;
|
|
|
|
|
2008-04-26 13:33:24 +02:00
|
|
|
while (*cmdline)
|
2007-02-10 22:55:29 +01:00
|
|
|
{
|
2017-05-17 14:35:51 +02:00
|
|
|
while (*cmdline == ' ' || *cmdline == '\t') cmdline++;
|
2007-02-10 22:55:29 +01:00
|
|
|
|
2008-04-26 13:33:24 +02:00
|
|
|
if (*cmdline == '-' || *cmdline == '/')
|
2007-02-10 22:55:29 +01:00
|
|
|
{
|
2008-04-26 13:33:24 +02:00
|
|
|
if (!cmdline[2] || isspace(cmdline[2]))
|
|
|
|
{
|
|
|
|
switch (cmdline[1])
|
|
|
|
{
|
|
|
|
case 'P':
|
|
|
|
case 'p':
|
2013-11-02 14:34:15 +01:00
|
|
|
opt_print = TRUE;
|
2008-04-26 13:33:24 +02:00
|
|
|
cmdline += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* a filename starting by / */
|
2007-02-10 22:55:29 +01:00
|
|
|
}
|
2008-04-26 13:33:24 +02:00
|
|
|
break;
|
2007-02-10 22:55:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*cmdline)
|
|
|
|
{
|
|
|
|
/* file name is passed on the command line */
|
|
|
|
if (cmdline[0] == '"')
|
|
|
|
{
|
|
|
|
cmdline++;
|
|
|
|
cmdline[lstrlenW(cmdline) - 1] = 0;
|
|
|
|
}
|
|
|
|
DoOpenFile(cmdline);
|
|
|
|
InvalidateRect(hMainWnd, NULL, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt_print)
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hMainWnd, MAKEINTRESOURCEW(STRING_PRINTING_NOT_IMPLEMENTED), wszAppTitle, MB_OK);
|
2007-02-10 22:55:29 +01:00
|
|
|
}
|
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
static LRESULT handle_findmsg(LPFINDREPLACEW pFr)
|
|
|
|
{
|
|
|
|
if(pFr->Flags & FR_DIALOGTERM)
|
|
|
|
{
|
|
|
|
hFindWnd = 0;
|
|
|
|
pFr->Flags = FR_FINDNEXT;
|
|
|
|
return 0;
|
2007-08-26 15:01:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(pFr->Flags & FR_FINDNEXT || pFr->Flags & FR_REPLACE || pFr->Flags & FR_REPLACEALL)
|
2007-07-18 15:41:33 +02:00
|
|
|
{
|
2010-07-20 00:17:57 +02:00
|
|
|
FINDREPLACE_custom *custom_data = (FINDREPLACE_custom*)pFr->lCustData;
|
|
|
|
DWORD flags;
|
|
|
|
FINDTEXTEXW ft;
|
|
|
|
CHARRANGE sel;
|
|
|
|
LRESULT ret = -1;
|
2007-07-18 15:41:33 +02:00
|
|
|
HMENU hMenu = GetMenu(hMainWnd);
|
|
|
|
MENUITEMINFOW mi;
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
mi.fMask = MIIM_DATA;
|
|
|
|
mi.dwItemData = 1;
|
|
|
|
SetMenuItemInfoW(hMenu, ID_FIND_NEXT, FALSE, &mi);
|
|
|
|
|
2010-07-20 00:18:08 +02:00
|
|
|
/* Make sure find field is saved. */
|
|
|
|
if (pFr->lpstrFindWhat != custom_data->findBuffer)
|
|
|
|
{
|
|
|
|
lstrcpynW(custom_data->findBuffer, pFr->lpstrFindWhat,
|
2018-07-24 22:13:45 +02:00
|
|
|
ARRAY_SIZE(custom_data->findBuffer));
|
2010-07-20 00:18:08 +02:00
|
|
|
pFr->lpstrFindWhat = custom_data->findBuffer;
|
|
|
|
}
|
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_GETSEL, (WPARAM)&sel.cpMin, (LPARAM)&sel.cpMax);
|
|
|
|
if(custom_data->endPos == -1) {
|
|
|
|
custom_data->endPos = sel.cpMin;
|
|
|
|
custom_data->wrapped = FALSE;
|
2007-07-18 15:41:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
flags = FR_DOWN | (pFr->Flags & (FR_MATCHCASE | FR_WHOLEWORD));
|
2007-07-18 15:41:33 +02:00
|
|
|
ft.lpstrText = pFr->lpstrFindWhat;
|
|
|
|
|
2011-08-24 15:28:14 +02:00
|
|
|
/* Only replace the existing selection if it is an exact match. */
|
2010-07-20 00:17:57 +02:00
|
|
|
if (sel.cpMin != sel.cpMax &&
|
|
|
|
(pFr->Flags & FR_REPLACE || pFr->Flags & FR_REPLACEALL))
|
2007-07-18 15:41:33 +02:00
|
|
|
{
|
2010-07-20 00:17:57 +02:00
|
|
|
ft.chrg = sel;
|
|
|
|
SendMessageW(hEditorWnd, EM_FINDTEXTEXW, flags, (LPARAM)&ft);
|
|
|
|
if (ft.chrgText.cpMin == sel.cpMin && ft.chrgText.cpMax == sel.cpMax) {
|
|
|
|
SendMessageW(hEditorWnd, EM_REPLACESEL, TRUE, (LPARAM)pFr->lpstrReplaceWith);
|
|
|
|
SendMessageW(hEditorWnd, EM_GETSEL, (WPARAM)&sel.cpMin, (LPARAM)&sel.cpMax);
|
|
|
|
}
|
|
|
|
}
|
2007-07-18 15:41:33 +02:00
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
/* Search from the start of the selection, but exclude the first character
|
|
|
|
* from search if there is a selection. */
|
|
|
|
ft.chrg.cpMin = sel.cpMin;
|
|
|
|
if (sel.cpMin != sel.cpMax)
|
|
|
|
ft.chrg.cpMin++;
|
|
|
|
|
|
|
|
/* Search to the end, then wrap around and search from the start. */
|
|
|
|
if (!custom_data->wrapped) {
|
|
|
|
ft.chrg.cpMax = -1;
|
|
|
|
ret = SendMessageW(hEditorWnd, EM_FINDTEXTEXW, flags, (LPARAM)&ft);
|
|
|
|
if (ret == -1) {
|
|
|
|
custom_data->wrapped = TRUE;
|
|
|
|
ft.chrg.cpMin = 0;
|
2007-07-18 15:41:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
if (ret == -1) {
|
|
|
|
ft.chrg.cpMax = custom_data->endPos + lstrlenW(pFr->lpstrFindWhat) - 1;
|
|
|
|
if (ft.chrg.cpMax > ft.chrg.cpMin)
|
|
|
|
ret = SendMessageW(hEditorWnd, EM_FINDTEXTEXW, flags, (LPARAM)&ft);
|
|
|
|
}
|
2007-08-26 15:01:44 +02:00
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
if (ret == -1) {
|
|
|
|
custom_data->endPos = -1;
|
2010-07-20 00:18:17 +02:00
|
|
|
EnableWindow(hMainWnd, FALSE);
|
|
|
|
MessageBoxWithResStringW(hFindWnd, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED),
|
|
|
|
wszAppTitle, MB_OK | MB_ICONASTERISK | MB_TASKMODAL);
|
|
|
|
EnableWindow(hMainWnd, TRUE);
|
2010-07-20 00:17:57 +02:00
|
|
|
} else {
|
|
|
|
SendMessageW(hEditorWnd, EM_SETSEL, ft.chrgText.cpMin, ft.chrgText.cpMax);
|
|
|
|
SendMessageW(hEditorWnd, EM_SCROLLCARET, 0, 0);
|
2007-08-26 15:01:44 +02:00
|
|
|
|
2010-07-20 00:17:57 +02:00
|
|
|
if (pFr->Flags & FR_REPLACEALL)
|
|
|
|
return handle_findmsg(pFr);
|
2007-07-18 15:41:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-26 15:01:44 +02:00
|
|
|
static void dialog_find(LPFINDREPLACEW fr, BOOL replace)
|
2007-07-18 15:41:33 +02:00
|
|
|
{
|
2010-07-20 00:18:08 +02:00
|
|
|
static WCHAR selBuffer[128];
|
|
|
|
static WCHAR replaceBuffer[128];
|
2010-07-20 00:17:57 +02:00
|
|
|
static FINDREPLACE_custom custom_data;
|
2010-07-20 00:18:08 +02:00
|
|
|
static const WCHAR endl = '\r';
|
|
|
|
FINDTEXTW ft;
|
2007-07-18 15:41:33 +02:00
|
|
|
|
2009-11-22 19:19:26 +01:00
|
|
|
/* Allow only one search/replace dialog to open */
|
|
|
|
if(hFindWnd != NULL)
|
|
|
|
{
|
|
|
|
SetActiveWindow(hFindWnd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
ZeroMemory(fr, sizeof(FINDREPLACEW));
|
|
|
|
fr->lStructSize = sizeof(FINDREPLACEW);
|
|
|
|
fr->hwndOwner = hMainWnd;
|
|
|
|
fr->Flags = FR_HIDEUPDOWN;
|
2010-07-20 00:18:08 +02:00
|
|
|
/* Find field is filled with the selected text if it is non-empty
|
|
|
|
* and stays within the same paragraph, otherwise the previous
|
|
|
|
* find field is used. */
|
|
|
|
SendMessageW(hEditorWnd, EM_GETSEL, (WPARAM)&ft.chrg.cpMin,
|
|
|
|
(LPARAM)&ft.chrg.cpMax);
|
|
|
|
ft.lpstrText = &endl;
|
|
|
|
if (ft.chrg.cpMin != ft.chrg.cpMax &&
|
|
|
|
SendMessageW(hEditorWnd, EM_FINDTEXTW, FR_DOWN, (LPARAM)&ft) == -1)
|
|
|
|
{
|
|
|
|
/* Use a temporary buffer for the selected text so that the saved
|
|
|
|
* find field is only overwritten when a find/replace is clicked. */
|
|
|
|
GETTEXTEX gt = {sizeof(selBuffer), GT_SELECTION, 1200, NULL, NULL};
|
|
|
|
SendMessageW(hEditorWnd, EM_GETTEXTEX, (WPARAM)>, (LPARAM)selBuffer);
|
|
|
|
fr->lpstrFindWhat = selBuffer;
|
|
|
|
} else {
|
|
|
|
fr->lpstrFindWhat = custom_data.findBuffer;
|
|
|
|
}
|
2010-06-11 06:44:16 +02:00
|
|
|
fr->lpstrReplaceWith = replaceBuffer;
|
2010-07-20 00:17:57 +02:00
|
|
|
custom_data.endPos = -1;
|
|
|
|
custom_data.wrapped = FALSE;
|
|
|
|
fr->lCustData = (LPARAM)&custom_data;
|
2010-07-20 00:18:08 +02:00
|
|
|
fr->wFindWhatLen = sizeof(custom_data.findBuffer);
|
2010-06-11 06:44:16 +02:00
|
|
|
fr->wReplaceWithLen = sizeof(replaceBuffer);
|
2007-07-18 15:41:33 +02:00
|
|
|
|
2007-08-26 15:01:44 +02:00
|
|
|
if(replace)
|
|
|
|
hFindWnd = ReplaceTextW(fr);
|
|
|
|
else
|
|
|
|
hFindWnd = FindTextW(fr);
|
2007-07-18 15:41:33 +02:00
|
|
|
}
|
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
static int units_to_twips(UNIT unit, float number)
|
2007-08-23 01:15:17 +02:00
|
|
|
{
|
2010-05-08 03:23:06 +02:00
|
|
|
int twips = 0;
|
|
|
|
|
|
|
|
switch(unit)
|
|
|
|
{
|
|
|
|
case UNIT_CM:
|
|
|
|
twips = (int)(number * 1000.0 / (float)CENTMM_PER_INCH * (float)TWIPS_PER_INCH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNIT_INCH:
|
|
|
|
twips = (int)(number * (float)TWIPS_PER_INCH);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNIT_PT:
|
|
|
|
twips = (int)(number * (0.0138 * (float)TWIPS_PER_INCH));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
return twips;
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:27:50 +02:00
|
|
|
static void append_current_units(LPWSTR buffer)
|
|
|
|
{
|
2008-05-27 22:40:13 +02:00
|
|
|
static const WCHAR space[] = {' ', 0};
|
2007-08-23 01:27:50 +02:00
|
|
|
lstrcatW(buffer, space);
|
|
|
|
lstrcatW(buffer, units_cmW);
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
static void number_with_units(LPWSTR buffer, int number)
|
|
|
|
{
|
2008-10-09 20:34:16 +02:00
|
|
|
static const WCHAR fmt[] = {'%','.','2','f',' ','%','s','\0'};
|
2008-10-12 13:13:08 +02:00
|
|
|
float converted = (float)number / (float)TWIPS_PER_INCH *(float)CENTMM_PER_INCH / 1000.0;
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2019-04-11 10:04:28 +02:00
|
|
|
swprintf(buffer, MAX_STRING_LEN, fmt, converted, units_cmW);
|
2007-08-23 01:15:17 +02:00
|
|
|
}
|
|
|
|
|
2008-06-18 03:19:15 +02:00
|
|
|
static BOOL get_comboexlist_selection(HWND hComboEx, LPWSTR wszBuffer, UINT bufferLength)
|
|
|
|
{
|
2008-10-09 20:34:16 +02:00
|
|
|
COMBOBOXEXITEMW cbItem;
|
2008-06-18 03:19:15 +02:00
|
|
|
COMBOBOXINFO cbInfo;
|
|
|
|
HWND hCombo, hList;
|
|
|
|
int idx, result;
|
2008-10-09 20:34:16 +02:00
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
hCombo = (HWND)SendMessageW(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
|
2008-06-18 03:19:15 +02:00
|
|
|
if (!hCombo)
|
|
|
|
return FALSE;
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
2012-01-20 12:07:24 +01:00
|
|
|
result = SendMessageW(hCombo, CB_GETCOMBOBOXINFO, 0, (LPARAM)&cbInfo);
|
2008-06-18 03:19:15 +02:00
|
|
|
if (!result)
|
|
|
|
return FALSE;
|
|
|
|
hList = cbInfo.hwndList;
|
2012-01-20 12:07:24 +01:00
|
|
|
idx = SendMessageW(hList, LB_GETCURSEL, 0, 0);
|
2008-06-18 03:19:15 +02:00
|
|
|
if (idx < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ZeroMemory(&cbItem, sizeof(cbItem));
|
|
|
|
cbItem.mask = CBEIF_TEXT;
|
|
|
|
cbItem.iItem = idx;
|
2008-10-09 20:34:16 +02:00
|
|
|
cbItem.pszText = wszBuffer;
|
2008-06-18 03:19:15 +02:00
|
|
|
cbItem.cchTextMax = bufferLength-1;
|
2009-01-08 20:17:55 +01:00
|
|
|
result = SendMessageW(hComboEx, CBEM_GETITEMW, 0, (LPARAM)&cbItem);
|
2008-06-18 03:19:15 +02:00
|
|
|
|
|
|
|
return result != 0;
|
|
|
|
}
|
|
|
|
|
2008-03-03 21:05:34 +01:00
|
|
|
static INT_PTR CALLBACK datetime_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
2007-07-18 15:50:21 +02:00
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
SYSTEMTIME st;
|
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_DATETIME);
|
|
|
|
GetLocalTime(&st);
|
|
|
|
|
|
|
|
GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, 0, (LPWSTR)&buffer,
|
|
|
|
MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
|
|
|
GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, 0, (LPWSTR)&buffer,
|
|
|
|
MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
|
|
|
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, 0, (LPWSTR)&buffer, MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
|
|
|
|
|
|
|
SendMessageW(hListWnd, LB_SETSEL, TRUE, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
2008-11-08 02:33:33 +01:00
|
|
|
case IDC_DATETIME:
|
|
|
|
if (HIWORD(wParam) != LBN_DBLCLK)
|
|
|
|
break;
|
|
|
|
/* Fall through */
|
|
|
|
|
2007-07-18 15:50:21 +02:00
|
|
|
case IDOK:
|
|
|
|
{
|
|
|
|
LRESULT index;
|
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_DATETIME);
|
|
|
|
|
|
|
|
index = SendMessageW(hListWnd, LB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
if(index != LB_ERR)
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
SendMessageW(hListWnd, LB_GETTEXT, index, (LPARAM)&buffer);
|
|
|
|
SendMessageW(hEditorWnd, EM_REPLACESEL, TRUE, (LPARAM)&buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hWnd, wParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-03 21:05:34 +01:00
|
|
|
static INT_PTR CALLBACK newfile_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
2007-07-18 22:27:15 +02:00
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2007-07-18 22:27:15 +02:00
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_NEWFILE);
|
|
|
|
|
2009-01-17 22:56:19 +01:00
|
|
|
LoadStringW(hInstance, STRING_NEWFILE_RICHTEXT, buffer, MAX_STRING_LEN);
|
2007-07-18 22:27:15 +02:00
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
2009-01-17 22:56:19 +01:00
|
|
|
LoadStringW(hInstance, STRING_NEWFILE_TXT, buffer, MAX_STRING_LEN);
|
2007-07-18 22:27:15 +02:00
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
2009-01-17 22:56:19 +01:00
|
|
|
LoadStringW(hInstance, STRING_NEWFILE_TXT_UNICODE, buffer, MAX_STRING_LEN);
|
2007-07-18 22:27:15 +02:00
|
|
|
SendMessageW(hListWnd, LB_ADDSTRING, 0, (LPARAM)&buffer);
|
|
|
|
|
|
|
|
SendMessageW(hListWnd, LB_SETSEL, TRUE, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
{
|
|
|
|
LRESULT index;
|
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_NEWFILE);
|
|
|
|
index = SendMessageW(hListWnd, LB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
if(index != LB_ERR)
|
|
|
|
EndDialog(hWnd, MAKELONG(fileformat_flags(index),0));
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hWnd, MAKELONG(ID_NEWFILE_ABORT,0));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
static INT_PTR CALLBACK paraformat_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2008-06-18 03:20:14 +02:00
|
|
|
static const WORD ALIGNMENT_VALUES[] = {PFA_LEFT, PFA_RIGHT, PFA_CENTER};
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2007-08-23 01:15:17 +02:00
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_PARA_ALIGN);
|
|
|
|
HWND hLeftWnd = GetDlgItem(hWnd, IDC_PARA_LEFT);
|
|
|
|
HWND hRightWnd = GetDlgItem(hWnd, IDC_PARA_RIGHT);
|
|
|
|
HWND hFirstWnd = GetDlgItem(hWnd, IDC_PARA_FIRST);
|
|
|
|
PARAFORMAT2 pf;
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
LoadStringW(hInstance, STRING_ALIGN_LEFT, buffer,
|
|
|
|
MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
|
|
LoadStringW(hInstance, STRING_ALIGN_RIGHT, buffer,
|
|
|
|
MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
|
|
LoadStringW(hInstance, STRING_ALIGN_CENTER, buffer,
|
|
|
|
MAX_STRING_LEN);
|
|
|
|
SendMessageW(hListWnd, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_ALIGNMENT | PFM_OFFSET | PFM_RIGHTINDENT |
|
2008-06-18 03:20:10 +02:00
|
|
|
PFM_STARTINDENT;
|
2007-08-23 01:15:17 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
|
|
|
|
if(pf.wAlignment == PFA_RIGHT)
|
|
|
|
index ++;
|
|
|
|
else if(pf.wAlignment == PFA_CENTER)
|
|
|
|
index += 2;
|
|
|
|
|
|
|
|
SendMessageW(hListWnd, CB_SETCURSEL, index, 0);
|
|
|
|
|
2008-06-18 03:20:10 +02:00
|
|
|
number_with_units(buffer, pf.dxStartIndent + pf.dxOffset);
|
2007-08-23 01:15:17 +02:00
|
|
|
SetWindowTextW(hLeftWnd, buffer);
|
|
|
|
number_with_units(buffer, pf.dxRightIndent);
|
|
|
|
SetWindowTextW(hRightWnd, buffer);
|
2008-06-18 03:20:10 +02:00
|
|
|
number_with_units(buffer, -pf.dxOffset);
|
2007-08-23 01:15:17 +02:00
|
|
|
SetWindowTextW(hFirstWnd, buffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDOK:
|
|
|
|
{
|
2008-06-18 03:20:14 +02:00
|
|
|
HWND hListWnd = GetDlgItem(hWnd, IDC_PARA_ALIGN);
|
2007-08-23 01:15:17 +02:00
|
|
|
HWND hLeftWnd = GetDlgItem(hWnd, IDC_PARA_LEFT);
|
|
|
|
HWND hRightWnd = GetDlgItem(hWnd, IDC_PARA_RIGHT);
|
|
|
|
HWND hFirstWnd = GetDlgItem(hWnd, IDC_PARA_FIRST);
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
2008-06-18 03:20:14 +02:00
|
|
|
int index;
|
2007-08-23 01:15:17 +02:00
|
|
|
float num;
|
|
|
|
int ret = 0;
|
2016-10-11 14:01:12 +02:00
|
|
|
PARAFORMAT2 pf;
|
2010-05-08 03:23:06 +02:00
|
|
|
UNIT unit;
|
2016-10-11 14:01:12 +02:00
|
|
|
BOOL in_list = FALSE;
|
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_NUMBERING;
|
|
|
|
SendMessageW(hEditorWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
if ((pf.dwMask & PFM_NUMBERING) && pf.wNumbering)
|
|
|
|
in_list = TRUE;
|
2007-08-23 01:15:17 +02:00
|
|
|
|
2008-06-18 03:20:14 +02:00
|
|
|
index = SendMessageW(hListWnd, CB_GETCURSEL, 0, 0);
|
|
|
|
pf.wAlignment = ALIGNMENT_VALUES[index];
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
GetWindowTextW(hLeftWnd, buffer, MAX_STRING_LEN);
|
2010-05-08 03:23:06 +02:00
|
|
|
if(number_from_string(buffer, &num, &unit))
|
2007-08-23 01:15:17 +02:00
|
|
|
ret++;
|
2010-05-08 03:23:06 +02:00
|
|
|
pf.dxOffset = units_to_twips(unit, num);
|
2007-08-23 01:15:17 +02:00
|
|
|
GetWindowTextW(hRightWnd, buffer, MAX_STRING_LEN);
|
2010-05-08 03:23:06 +02:00
|
|
|
if(number_from_string(buffer, &num, &unit))
|
2007-08-23 01:15:17 +02:00
|
|
|
ret++;
|
2010-05-08 03:23:06 +02:00
|
|
|
pf.dxRightIndent = units_to_twips(unit, num);
|
2007-08-23 01:15:17 +02:00
|
|
|
GetWindowTextW(hFirstWnd, buffer, MAX_STRING_LEN);
|
2010-05-08 03:23:06 +02:00
|
|
|
if(number_from_string(buffer, &num, &unit))
|
2007-08-23 01:15:17 +02:00
|
|
|
ret++;
|
2010-05-08 03:23:06 +02:00
|
|
|
pf.dxStartIndent = units_to_twips(unit, num);
|
2007-08-23 01:15:17 +02:00
|
|
|
|
|
|
|
if(ret != 3)
|
|
|
|
{
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hMainWnd, MAKEINTRESOURCEW(STRING_INVALID_NUMBER),
|
2007-08-23 01:15:17 +02:00
|
|
|
wszAppTitle, MB_OK | MB_ICONASTERISK);
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
{
|
2008-06-18 03:20:10 +02:00
|
|
|
if (pf.dxOffset + pf.dxStartIndent < 0
|
|
|
|
&& pf.dxStartIndent < 0)
|
|
|
|
{
|
|
|
|
/* The first line is before the left edge, so
|
|
|
|
* make sure it is at the left edge. */
|
|
|
|
pf.dxOffset = -pf.dxStartIndent;
|
|
|
|
} else if (pf.dxOffset < 0) {
|
|
|
|
/* The second and following lines are before
|
|
|
|
* the left edge, so set it to be at the left
|
|
|
|
* edge, and adjust the first line since it
|
|
|
|
* is relative to it. */
|
|
|
|
pf.dxStartIndent = max(pf.dxStartIndent + pf.dxOffset, 0);
|
|
|
|
pf.dxOffset = 0;
|
|
|
|
}
|
|
|
|
/* Internally the dxStartIndent is the absolute
|
|
|
|
* offset for the first line and dxOffset is
|
|
|
|
* to it value as opposed how it is displayed with
|
|
|
|
* the first line being the relative value.
|
|
|
|
* These two lines make the adjustments. */
|
2007-08-23 01:15:17 +02:00
|
|
|
pf.dxStartIndent = pf.dxStartIndent + pf.dxOffset;
|
2008-06-18 03:20:10 +02:00
|
|
|
pf.dxOffset = pf.dxOffset - pf.dxStartIndent;
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
pf.cbSize = sizeof(pf);
|
2008-06-18 03:20:14 +02:00
|
|
|
pf.dwMask = PFM_ALIGNMENT | PFM_OFFSET | PFM_RIGHTINDENT |
|
|
|
|
PFM_STARTINDENT;
|
2016-10-11 14:01:12 +02:00
|
|
|
if (in_list)
|
|
|
|
{
|
|
|
|
pf.wNumberingTab = max(pf.dxOffset, 0);
|
|
|
|
pf.dwMask |= PFM_NUMBERINGTAB;
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hWnd, wParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-23 01:27:50 +02:00
|
|
|
static INT_PTR CALLBACK tabstops_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS);
|
|
|
|
PARAFORMAT pf;
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_TABSTOPS;
|
|
|
|
SendMessageW(hEditorWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
SendMessageW(hTabWnd, CB_LIMITTEXT, MAX_STRING_LEN-1, 0);
|
|
|
|
|
|
|
|
for(i = 0; i < pf.cTabCount; i++)
|
|
|
|
{
|
|
|
|
number_with_units(buffer, pf.rgxTabs[i]);
|
|
|
|
SendMessageW(hTabWnd, CB_ADDSTRING, 0, (LPARAM)&buffer);
|
|
|
|
}
|
|
|
|
SetFocus(hTabWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_TABSTOPS:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = (HWND)lParam;
|
|
|
|
HWND hAddWnd = GetDlgItem(hWnd, ID_TAB_ADD);
|
|
|
|
HWND hDelWnd = GetDlgItem(hWnd, ID_TAB_DEL);
|
|
|
|
HWND hEmptyWnd = GetDlgItem(hWnd, ID_TAB_EMPTY);
|
|
|
|
|
|
|
|
if(GetWindowTextLengthW(hTabWnd))
|
|
|
|
EnableWindow(hAddWnd, TRUE);
|
|
|
|
else
|
|
|
|
EnableWindow(hAddWnd, FALSE);
|
|
|
|
|
|
|
|
if(SendMessageW(hTabWnd, CB_GETCOUNT, 0, 0))
|
|
|
|
{
|
|
|
|
EnableWindow(hEmptyWnd, TRUE);
|
|
|
|
|
|
|
|
if(SendMessageW(hTabWnd, CB_GETCURSEL, 0, 0) == CB_ERR)
|
|
|
|
EnableWindow(hDelWnd, FALSE);
|
|
|
|
else
|
|
|
|
EnableWindow(hDelWnd, TRUE);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
EnableWindow(hEmptyWnd, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TAB_ADD:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS);
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
2010-05-08 03:23:06 +02:00
|
|
|
UNIT unit;
|
2007-08-23 01:27:50 +02:00
|
|
|
|
|
|
|
GetWindowTextW(hTabWnd, buffer, MAX_STRING_LEN);
|
|
|
|
append_current_units(buffer);
|
|
|
|
|
|
|
|
if(SendMessageW(hTabWnd, CB_FINDSTRINGEXACT, -1, (LPARAM)&buffer) == CB_ERR)
|
|
|
|
{
|
|
|
|
float number = 0;
|
2012-01-20 12:07:24 +01:00
|
|
|
int item_count = SendMessageW(hTabWnd, CB_GETCOUNT, 0, 0);
|
2007-08-23 01:27:50 +02:00
|
|
|
|
2010-05-08 03:23:06 +02:00
|
|
|
if(!number_from_string(buffer, &number, &unit))
|
2007-08-23 01:27:50 +02:00
|
|
|
{
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hWnd, MAKEINTRESOURCEW(STRING_INVALID_NUMBER),
|
2007-08-23 01:27:50 +02:00
|
|
|
wszAppTitle, MB_OK | MB_ICONINFORMATION);
|
2009-02-25 21:15:22 +01:00
|
|
|
} else if (item_count >= MAX_TAB_STOPS) {
|
|
|
|
MessageBoxWithResStringW(hWnd, MAKEINTRESOURCEW(STRING_MAX_TAB_STOPS),
|
|
|
|
wszAppTitle, MB_OK | MB_ICONINFORMATION);
|
|
|
|
} else {
|
2009-02-25 21:15:25 +01:00
|
|
|
int i;
|
|
|
|
float next_number = -1;
|
|
|
|
int next_number_in_twips = -1;
|
2010-05-08 03:23:06 +02:00
|
|
|
int insert_number = units_to_twips(unit, number);
|
2009-02-25 21:15:25 +01:00
|
|
|
|
|
|
|
/* linear search for position to insert the string */
|
|
|
|
for(i = 0; i < item_count; i++)
|
|
|
|
{
|
|
|
|
SendMessageW(hTabWnd, CB_GETLBTEXT, i, (LPARAM)&buffer);
|
2010-05-08 03:23:06 +02:00
|
|
|
number_from_string(buffer, &next_number, &unit);
|
|
|
|
next_number_in_twips = units_to_twips(unit, next_number);
|
2009-02-25 21:15:25 +01:00
|
|
|
if (insert_number <= next_number_in_twips)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (insert_number != next_number_in_twips)
|
|
|
|
{
|
|
|
|
number_with_units(buffer, insert_number);
|
|
|
|
SendMessageW(hTabWnd, CB_INSERTSTRING, i, (LPARAM)&buffer);
|
|
|
|
SetWindowTextW(hTabWnd, 0);
|
|
|
|
}
|
2007-08-23 01:27:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SetFocus(hTabWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TAB_DEL:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS);
|
|
|
|
LRESULT ret;
|
|
|
|
ret = SendMessageW(hTabWnd, CB_GETCURSEL, 0, 0);
|
|
|
|
if(ret != CB_ERR)
|
|
|
|
SendMessageW(hTabWnd, CB_DELETESTRING, ret, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TAB_EMPTY:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS);
|
|
|
|
SendMessageW(hTabWnd, CB_RESETCONTENT, 0, 0);
|
|
|
|
SetFocus(hTabWnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDOK:
|
|
|
|
{
|
|
|
|
HWND hTabWnd = GetDlgItem(hWnd, IDC_TABSTOPS);
|
|
|
|
int i;
|
|
|
|
WCHAR buffer[MAX_STRING_LEN];
|
|
|
|
PARAFORMAT pf;
|
|
|
|
float number;
|
2010-05-08 03:23:06 +02:00
|
|
|
UNIT unit;
|
2007-08-23 01:27:50 +02:00
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_TABSTOPS;
|
|
|
|
|
|
|
|
for(i = 0; SendMessageW(hTabWnd, CB_GETLBTEXT, i,
|
|
|
|
(LPARAM)&buffer) != CB_ERR &&
|
|
|
|
i < MAX_TAB_STOPS; i++)
|
|
|
|
{
|
2010-05-08 03:23:06 +02:00
|
|
|
number_from_string(buffer, &number, &unit);
|
|
|
|
pf.rgxTabs[i] = units_to_twips(unit, number);
|
2007-08-23 01:27:50 +02:00
|
|
|
}
|
|
|
|
pf.cTabCount = i;
|
|
|
|
SendMessageW(hEditorWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hWnd, wParam);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-07 16:05:26 +02:00
|
|
|
static LRESULT OnCreate( HWND hWnd )
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
2008-01-14 00:36:23 +01:00
|
|
|
HWND hToolBarWnd, hFormatBarWnd, hReBarWnd, hFontListWnd, hSizeListWnd, hRulerWnd;
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2006-02-14 14:48:29 +01:00
|
|
|
HANDLE hDLL;
|
|
|
|
TBADDBITMAP ab;
|
|
|
|
int nStdBitmaps = 0;
|
|
|
|
REBARINFO rbi;
|
2007-06-13 22:24:16 +02:00
|
|
|
REBARBANDINFOW rbb;
|
2017-05-02 12:03:19 +02:00
|
|
|
RECT rect;
|
|
|
|
HFONT font;
|
|
|
|
HDC hdc;
|
|
|
|
SIZE name_sz, size_sz;
|
|
|
|
int height;
|
2007-06-13 22:24:16 +02:00
|
|
|
static const WCHAR wszRichEditDll[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
|
|
|
|
static const WCHAR wszRichEditText[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
|
2017-05-02 12:03:19 +02:00
|
|
|
static const WCHAR font_text[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0}; /* a long font name */
|
|
|
|
static const WCHAR size_text[] = {' ','0','0',0}; /* enough for two digits */
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
CreateStatusWindowW(CCS_NODIVIDER|WS_CHILD|WS_VISIBLE, wszRichEditText, hWnd, IDC_STATUSBAR);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
hReBarWnd = CreateWindowExW(WS_EX_TOOLWINDOW, REBARCLASSNAMEW, NULL,
|
2006-02-14 14:48:29 +01:00
|
|
|
CCS_NODIVIDER|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_TOP,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)IDC_REBAR, hInstance, NULL);
|
|
|
|
|
|
|
|
rbi.cbSize = sizeof(rbi);
|
|
|
|
rbi.fMask = 0;
|
|
|
|
rbi.himl = NULL;
|
2007-06-13 22:24:16 +02:00
|
|
|
if(!SendMessageW(hReBarWnd, RB_SETBARINFO, 0, (LPARAM)&rbi))
|
2006-02-14 14:48:29 +01:00
|
|
|
return -1;
|
|
|
|
|
2016-10-11 14:01:10 +02:00
|
|
|
hToolBarWnd = CreateToolbarEx(hReBarWnd, CCS_NOPARENTALIGN|CCS_NOMOVEY|WS_VISIBLE|WS_CHILD|TBSTYLE_TOOLTIPS,
|
2006-02-14 14:48:29 +01:00
|
|
|
IDC_TOOLBAR,
|
2007-07-18 15:50:43 +02:00
|
|
|
1, hInstance, IDB_TOOLBAR,
|
2006-02-14 14:48:29 +01:00
|
|
|
NULL, 0,
|
|
|
|
24, 24, 16, 16, sizeof(TBBUTTON));
|
|
|
|
|
|
|
|
ab.hInst = HINST_COMMCTRL;
|
|
|
|
ab.nID = IDB_STD_SMALL_COLOR;
|
2007-06-06 13:28:26 +02:00
|
|
|
nStdBitmaps = SendMessageW(hToolBarWnd, TB_ADDBITMAP, 0, (LPARAM)&ab);
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_FILENEW, ID_FILE_NEW);
|
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_FILEOPEN, ID_FILE_OPEN);
|
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_FILESAVE, ID_FILE_SAVE);
|
|
|
|
AddSeparator(hToolBarWnd);
|
2007-08-23 15:00:44 +02:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_PRINT, ID_PRINT_QUICK);
|
2007-02-24 21:00:08 +01:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_PRINTPRE, ID_PREVIEW);
|
|
|
|
AddSeparator(hToolBarWnd);
|
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_FIND, ID_FIND);
|
|
|
|
AddSeparator(hToolBarWnd);
|
2006-02-14 14:48:29 +01:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_CUT, ID_EDIT_CUT);
|
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_COPY, ID_EDIT_COPY);
|
2007-02-25 14:38:50 +01:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_PASTE, ID_EDIT_PASTE);
|
2006-02-14 14:48:29 +01:00
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_UNDO, ID_EDIT_UNDO);
|
|
|
|
AddButton(hToolBarWnd, nStdBitmaps+STD_REDOW, ID_EDIT_REDO);
|
2007-07-18 15:50:43 +02:00
|
|
|
AddSeparator(hToolBarWnd);
|
|
|
|
AddButton(hToolBarWnd, 0, ID_DATETIME);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hToolBarWnd, TB_AUTOSIZE, 0, 0);
|
2017-05-02 12:03:19 +02:00
|
|
|
height = HIWORD(SendMessageW(hToolBarWnd, TB_GETBUTTONSIZE, 0, 0));
|
|
|
|
|
|
|
|
hFontListWnd = CreateWindowExW(0, WC_COMBOBOXEXW, NULL,
|
|
|
|
WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN | CBS_SORT,
|
|
|
|
0, 0, 200, 150, hReBarWnd, (HMENU)IDC_FONTLIST, hInstance, NULL);
|
|
|
|
GetWindowRect(hFontListWnd, &rect);
|
|
|
|
height = max(height, rect.bottom - rect.top);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2009-08-15 04:23:21 +02:00
|
|
|
rbb.cbSize = REBARBANDINFOW_V6_SIZE;
|
2007-08-22 22:41:25 +02:00
|
|
|
rbb.fMask = RBBIM_SIZE | RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_STYLE | RBBIM_ID;
|
2007-06-06 13:28:26 +02:00
|
|
|
rbb.fStyle = RBBS_CHILDEDGE | RBBS_BREAK | RBBS_NOGRIPPER;
|
|
|
|
rbb.cx = 0;
|
2006-02-14 14:48:29 +01:00
|
|
|
rbb.hwndChild = hToolBarWnd;
|
|
|
|
rbb.cxMinChild = 0;
|
2017-05-02 12:03:19 +02:00
|
|
|
rbb.cyChild = rbb.cyMinChild = height;
|
2007-08-22 22:41:25 +02:00
|
|
|
rbb.wID = BANDID_TOOLBAR;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hReBarWnd, RB_INSERTBANDW, -1, (LPARAM)&rbb);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2017-05-02 12:03:19 +02:00
|
|
|
font = (HFONT)SendMessageW(hFontListWnd, WM_GETFONT, 0, 0);
|
|
|
|
hdc = GetDC(hFontListWnd);
|
|
|
|
font = SelectObject(hdc, font);
|
2018-07-24 22:13:45 +02:00
|
|
|
GetTextExtentPointW(hdc, font_text, ARRAY_SIZE(font_text) - 1, &name_sz);
|
|
|
|
GetTextExtentPointW(hdc, size_text, ARRAY_SIZE(size_text) - 1, &size_sz);
|
2017-05-02 12:03:19 +02:00
|
|
|
font = SelectObject(hdc, font);
|
|
|
|
ReleaseDC(hFontListWnd, hdc);
|
2007-08-24 15:46:09 +02:00
|
|
|
rbb.hwndChild = hFontListWnd;
|
2017-05-02 12:03:19 +02:00
|
|
|
rbb.cx = MulDiv(name_sz.cx, 3, 2) + height; /* height is space for the dropdown arrow */
|
2007-08-24 15:46:09 +02:00
|
|
|
rbb.wID = BANDID_FONTLIST;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hReBarWnd, RB_INSERTBANDW, -1, (LPARAM)&rbb);
|
2007-08-24 15:46:09 +02:00
|
|
|
|
2007-08-24 19:45:54 +02:00
|
|
|
hSizeListWnd = CreateWindowExW(0, WC_COMBOBOXEXW, NULL,
|
|
|
|
WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN,
|
|
|
|
0, 0, 50, 150, hReBarWnd, (HMENU)IDC_SIZELIST, hInstance, NULL);
|
|
|
|
|
|
|
|
rbb.hwndChild = hSizeListWnd;
|
2017-05-02 12:03:19 +02:00
|
|
|
rbb.cx = MulDiv(size_sz.cx, 3, 2) + height; /* height is space for the dropdown arrow */
|
2007-08-24 19:45:54 +02:00
|
|
|
rbb.fStyle ^= RBBS_BREAK;
|
|
|
|
rbb.wID = BANDID_SIZELIST;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hReBarWnd, RB_INSERTBANDW, -1, (LPARAM)&rbb);
|
2007-08-24 19:45:54 +02:00
|
|
|
|
2007-06-06 13:28:26 +02:00
|
|
|
hFormatBarWnd = CreateToolbarEx(hReBarWnd,
|
2016-10-11 14:01:10 +02:00
|
|
|
CCS_NOPARENTALIGN | CCS_NOMOVEY | WS_VISIBLE | TBSTYLE_TOOLTIPS,
|
2010-02-17 20:19:36 +01:00
|
|
|
IDC_FORMATBAR, 8, hInstance, IDB_FORMATBAR, NULL, 0, 16, 16, 16, 16, sizeof(TBBUTTON));
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
SendMessageW(hFormatBarWnd, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS);
|
|
|
|
|
2007-06-06 13:28:26 +02:00
|
|
|
AddButton(hFormatBarWnd, 0, ID_FORMAT_BOLD);
|
|
|
|
AddButton(hFormatBarWnd, 1, ID_FORMAT_ITALIC);
|
|
|
|
AddButton(hFormatBarWnd, 2, ID_FORMAT_UNDERLINE);
|
2010-02-17 20:19:36 +01:00
|
|
|
AddButton(hFormatBarWnd, 3, ID_FORMAT_COLOR);
|
2007-06-06 13:28:26 +02:00
|
|
|
AddSeparator(hFormatBarWnd);
|
2010-02-17 20:19:36 +01:00
|
|
|
AddButton(hFormatBarWnd, 4, ID_ALIGN_LEFT);
|
|
|
|
AddButton(hFormatBarWnd, 5, ID_ALIGN_CENTER);
|
|
|
|
AddButton(hFormatBarWnd, 6, ID_ALIGN_RIGHT);
|
2007-07-20 21:18:02 +02:00
|
|
|
AddSeparator(hFormatBarWnd);
|
2016-10-11 14:01:11 +02:00
|
|
|
AddButtonStyle(hFormatBarWnd, 7, ID_BULLETONOFF, BTNS_DROPDOWN);
|
2007-06-06 13:28:26 +02:00
|
|
|
|
|
|
|
SendMessageW(hFormatBarWnd, TB_AUTOSIZE, 0, 0);
|
|
|
|
|
|
|
|
rbb.hwndChild = hFormatBarWnd;
|
2007-08-22 22:41:25 +02:00
|
|
|
rbb.wID = BANDID_FORMATBAR;
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hReBarWnd, RB_INSERTBANDW, -1, (LPARAM)&rbb);
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
hRulerWnd = CreateWindowExW(0, WC_STATICW, NULL, WS_VISIBLE | WS_CHILD,
|
|
|
|
0, 0, 200, 10, hReBarWnd, (HMENU)IDC_RULER, hInstance, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
rbb.hwndChild = hRulerWnd;
|
|
|
|
rbb.wID = BANDID_RULER;
|
|
|
|
rbb.fStyle |= RBBS_BREAK;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hReBarWnd, RB_INSERTBANDW, -1, (LPARAM)&rbb);
|
2008-01-14 00:36:23 +01:00
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
hDLL = LoadLibraryW(wszRichEditDll);
|
2007-07-18 15:44:24 +02:00
|
|
|
if(!hDLL)
|
|
|
|
{
|
2008-10-21 09:07:09 +02:00
|
|
|
MessageBoxWithResStringW(hWnd, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED), wszAppTitle,
|
2007-07-18 15:44:24 +02:00
|
|
|
MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
PostQuitMessage(1);
|
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2009-08-10 16:53:30 +02:00
|
|
|
hEditorWnd = CreateWindowExW(WS_EX_CLIENTEDGE, RICHEDIT_CLASS20W, NULL,
|
2008-06-18 03:18:13 +02:00
|
|
|
WS_CHILD|WS_VISIBLE|ES_SELECTIONBAR|ES_MULTILINE|ES_AUTOVSCROLL
|
2008-10-14 00:48:41 +02:00
|
|
|
|ES_WANTRETURN|WS_VSCROLL|ES_NOHIDESEL|WS_HSCROLL,
|
2006-02-14 14:48:29 +01:00
|
|
|
0, 0, 1000, 100, hWnd, (HMENU)IDC_EDITOR, hInstance, NULL);
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
if (!hEditorWnd)
|
|
|
|
{
|
2006-10-10 23:01:16 +02:00
|
|
|
fprintf(stderr, "Error code %u\n", GetLastError());
|
2006-02-14 14:48:29 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
assert(hEditorWnd);
|
|
|
|
|
2010-07-22 14:30:19 +02:00
|
|
|
setup_richedit_olecallback(hEditorWnd);
|
2006-02-14 14:48:29 +01:00
|
|
|
SetFocus(hEditorWnd);
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_SETEVENTMASK, 0, ENM_SELCHANGE);
|
2007-02-25 14:40:27 +01:00
|
|
|
|
2007-08-22 22:51:46 +02:00
|
|
|
set_default_font();
|
2007-02-26 18:32:11 +01:00
|
|
|
|
2007-08-24 15:46:09 +02:00
|
|
|
populate_font_list(hFontListWnd);
|
2007-08-24 19:45:54 +02:00
|
|
|
populate_size_list(hSizeListWnd);
|
2007-02-25 14:40:27 +01:00
|
|
|
DoLoadStrings();
|
2007-07-08 13:51:19 +02:00
|
|
|
SendMessageW(hEditorWnd, EM_SETMODIFY, FALSE, 0);
|
2007-02-25 14:40:27 +01:00
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
ID_FINDMSGSTRING = RegisterWindowMessageW(FINDMSGSTRINGW);
|
|
|
|
|
2007-07-18 15:41:57 +02:00
|
|
|
registry_read_filelist(hWnd);
|
2007-12-12 09:36:41 +01:00
|
|
|
registry_read_formatopts_all(barState, wordWrap);
|
2007-08-22 22:41:25 +02:00
|
|
|
registry_read_options();
|
2007-08-22 22:45:11 +02:00
|
|
|
DragAcceptFiles(hWnd, TRUE);
|
2007-07-18 15:41:57 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 16:05:26 +02:00
|
|
|
static LRESULT OnUser( HWND hWnd )
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
|
|
|
HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
|
|
|
|
HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
|
|
|
|
HWND hwndToolBar = GetDlgItem(hwndReBar, IDC_TOOLBAR);
|
2007-06-06 13:28:26 +02:00
|
|
|
HWND hwndFormatBar = GetDlgItem(hwndReBar, IDC_FORMATBAR);
|
2006-02-14 14:48:29 +01:00
|
|
|
int from, to;
|
|
|
|
CHARFORMAT2W fmt;
|
2007-02-27 15:09:24 +01:00
|
|
|
PARAFORMAT2 pf;
|
2007-07-18 15:41:33 +02:00
|
|
|
GETTEXTLENGTHEX gt;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
|
2007-02-27 15:09:24 +01:00
|
|
|
ZeroMemory(&pf, sizeof(pf));
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
gt.flags = GTL_NUMCHARS;
|
|
|
|
gt.codepage = 1200;
|
|
|
|
|
|
|
|
SendMessageW(hwndToolBar, TB_ENABLEBUTTON, ID_FIND,
|
|
|
|
SendMessageW(hwndEditor, EM_GETTEXTLENGTHEX, (WPARAM)>, 0) ? 1 : 0);
|
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETCHARFORMAT, TRUE, (LPARAM)&fmt);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
|
|
|
|
SendMessageW(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_UNDO,
|
|
|
|
SendMessageW(hwndEditor, EM_CANUNDO, 0, 0));
|
|
|
|
SendMessageW(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_REDO,
|
|
|
|
SendMessageW(hwndEditor, EM_CANREDO, 0, 0));
|
|
|
|
SendMessageW(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_CUT, from == to ? 0 : 1);
|
|
|
|
SendMessageW(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_COPY, from == to ? 0 : 1);
|
2007-02-27 15:09:24 +01:00
|
|
|
|
2007-06-06 13:28:26 +02:00
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_FORMAT_BOLD, (fmt.dwMask & CFM_BOLD) &&
|
|
|
|
(fmt.dwEffects & CFE_BOLD));
|
|
|
|
SendMessageW(hwndFormatBar, TB_INDETERMINATE, ID_FORMAT_BOLD, !(fmt.dwMask & CFM_BOLD));
|
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_FORMAT_ITALIC, (fmt.dwMask & CFM_ITALIC) &&
|
|
|
|
(fmt.dwEffects & CFE_ITALIC));
|
|
|
|
SendMessageW(hwndFormatBar, TB_INDETERMINATE, ID_FORMAT_ITALIC, !(fmt.dwMask & CFM_ITALIC));
|
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_FORMAT_UNDERLINE, (fmt.dwMask & CFM_UNDERLINE) &&
|
|
|
|
(fmt.dwEffects & CFE_UNDERLINE));
|
|
|
|
SendMessageW(hwndFormatBar, TB_INDETERMINATE, ID_FORMAT_UNDERLINE, !(fmt.dwMask & CFM_UNDERLINE));
|
|
|
|
|
|
|
|
SendMessageW(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_ALIGN_LEFT, (pf.wAlignment == PFA_LEFT));
|
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_ALIGN_CENTER, (pf.wAlignment == PFA_CENTER));
|
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_ALIGN_RIGHT, (pf.wAlignment == PFA_RIGHT));
|
2007-02-27 15:09:24 +01:00
|
|
|
|
2017-01-30 14:16:03 +01:00
|
|
|
SendMessageW(hwndFormatBar, TB_CHECKBUTTON, ID_BULLETONOFF, pf.wNumbering != 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 16:05:26 +02:00
|
|
|
static LRESULT OnNotify( HWND hWnd, LPARAM lParam)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
|
|
|
HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
|
2007-08-24 15:46:09 +02:00
|
|
|
HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
|
2006-02-14 14:48:29 +01:00
|
|
|
NMHDR *pHdr = (NMHDR *)lParam;
|
2007-08-24 15:46:09 +02:00
|
|
|
HWND hwndFontList = GetDlgItem(hwndReBar, IDC_FONTLIST);
|
2007-08-24 19:45:54 +02:00
|
|
|
HWND hwndSizeList = GetDlgItem(hwndReBar, IDC_SIZELIST);
|
2016-10-11 14:01:11 +02:00
|
|
|
HWND hwndFormatBar = GetDlgItem(hwndReBar, IDC_FORMATBAR);
|
2007-08-24 15:46:09 +02:00
|
|
|
|
2007-08-24 19:45:54 +02:00
|
|
|
if (pHdr->hwndFrom == hwndFontList || pHdr->hwndFrom == hwndSizeList)
|
2007-08-24 15:46:09 +02:00
|
|
|
{
|
|
|
|
if (pHdr->code == CBEN_ENDEDITW)
|
|
|
|
{
|
2012-01-20 12:07:24 +01:00
|
|
|
NMCBEENDEDITW *endEdit = (NMCBEENDEDITW *)lParam;
|
2007-08-24 19:45:54 +02:00
|
|
|
if(pHdr->hwndFrom == hwndFontList)
|
|
|
|
{
|
2012-01-20 12:07:24 +01:00
|
|
|
on_fontlist_modified(endEdit->szText);
|
2007-08-24 19:45:54 +02:00
|
|
|
} else if (pHdr->hwndFrom == hwndSizeList)
|
|
|
|
{
|
2013-12-06 17:28:31 +01:00
|
|
|
on_sizelist_modified(hwndSizeList,endEdit->szText);
|
2007-08-24 19:45:54 +02:00
|
|
|
}
|
2007-08-24 15:46:09 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
if (pHdr->hwndFrom == hwndFormatBar)
|
|
|
|
{
|
|
|
|
if (pHdr->code == TBN_DROPDOWN)
|
|
|
|
{
|
|
|
|
NMTOOLBARW *tb_notify = (NMTOOLBARW *)lParam;
|
|
|
|
HMENU menu = GetMenu( hWnd );
|
|
|
|
MENUITEMINFOW info;
|
|
|
|
TPMPARAMS params;
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
if (!menu) return 0;
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
info.fMask = MIIM_SUBMENU;
|
|
|
|
GetMenuItemInfoW( menu, ID_LISTMENU, FALSE, &info );
|
|
|
|
if (!info.hSubMenu) return 0;
|
|
|
|
|
|
|
|
SendMessageW( tb_notify->hdr.hwndFrom, TB_GETRECT, (WPARAM)tb_notify->iItem, (LPARAM)&rc );
|
|
|
|
MapWindowPoints( tb_notify->hdr.hwndFrom, HWND_DESKTOP, (LPPOINT)&rc, 2 );
|
|
|
|
|
|
|
|
params.cbSize = sizeof(params);
|
|
|
|
params.rcExclude = rc;
|
|
|
|
TrackPopupMenuEx( info.hSubMenu,
|
|
|
|
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
|
|
|
|
rc.left, rc.bottom, hWnd, ¶ms );
|
|
|
|
}
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
2016-10-11 14:01:11 +02:00
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
if (pHdr->hwndFrom == hwndEditor)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
2016-10-11 14:01:11 +02:00
|
|
|
if (pHdr->code == EN_SELCHANGE)
|
|
|
|
{
|
|
|
|
SELCHANGE *pSC = (SELCHANGE *)lParam;
|
|
|
|
char buf[128];
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
update_font_list();
|
2007-08-24 15:46:09 +02:00
|
|
|
|
2016-10-11 14:01:11 +02:00
|
|
|
sprintf( buf,"selection = %d..%d, line count=%ld",
|
|
|
|
pSC->chrg.cpMin, pSC->chrg.cpMax,
|
|
|
|
SendMessageW(hwndEditor, EM_GETLINECOUNT, 0, 0));
|
|
|
|
SetWindowTextA(GetDlgItem(hWnd, IDC_STATUSBAR), buf);
|
|
|
|
SendMessageW(hWnd, WM_USER, 0, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-17 20:19:36 +01:00
|
|
|
/* Copied from dlls/comdlg32/fontdlg.c */
|
|
|
|
static const COLORREF textcolors[]=
|
|
|
|
{
|
|
|
|
0x00000000L,0x00000080L,0x00008000L,0x00008080L,
|
|
|
|
0x00800000L,0x00800080L,0x00808000L,0x00808080L,
|
|
|
|
0x00c0c0c0L,0x000000ffL,0x0000ff00L,0x0000ffffL,
|
|
|
|
0x00ff0000L,0x00ff00ffL,0x00ffff00L,0x00FFFFFFL
|
|
|
|
};
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
|
2007-07-18 15:41:33 +02:00
|
|
|
static FINDREPLACEW findreplace;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
if ((HWND)lParam == hwndEditor)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
2007-07-18 15:41:33 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_FILE_EXIT:
|
2007-06-13 22:24:16 +02:00
|
|
|
PostMessageW(hWnd, WM_CLOSE, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FILE_NEW:
|
2007-07-08 13:51:19 +02:00
|
|
|
{
|
2009-12-23 17:10:23 +01:00
|
|
|
HINSTANCE hInstance = GetModuleHandleW(0);
|
2012-01-20 12:07:24 +01:00
|
|
|
int ret = DialogBoxW(hInstance, MAKEINTRESOURCEW(IDD_NEWFILE), hWnd, newfile_proc);
|
2007-07-18 22:27:15 +02:00
|
|
|
|
|
|
|
if(ret != ID_NEWFILE_ABORT)
|
|
|
|
{
|
|
|
|
if(prompt_save_changes())
|
|
|
|
{
|
|
|
|
SETTEXTEX st;
|
|
|
|
|
|
|
|
set_caption(NULL);
|
|
|
|
wszFileName[0] = '\0';
|
|
|
|
|
2007-08-23 15:02:23 +02:00
|
|
|
clear_formatting();
|
|
|
|
|
2007-07-18 22:27:15 +02:00
|
|
|
st.flags = ST_DEFAULT;
|
|
|
|
st.codepage = 1200;
|
|
|
|
SendMessageW(hEditorWnd, EM_SETTEXTEX, (WPARAM)&st, 0);
|
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_SETMODIFY, FALSE, 0);
|
|
|
|
set_fileformat(ret);
|
2007-08-24 15:46:09 +02:00
|
|
|
update_font_list();
|
2007-07-18 22:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-08 13:51:19 +02:00
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FILE_OPEN:
|
2007-02-25 14:40:27 +01:00
|
|
|
DialogOpenFile();
|
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_FILE_SAVE:
|
2007-06-02 00:07:02 +02:00
|
|
|
if(wszFileName[0])
|
2007-05-31 15:38:51 +02:00
|
|
|
{
|
2007-07-18 21:59:24 +02:00
|
|
|
DoSaveFile(wszFileName, fileFormat);
|
2007-05-31 15:38:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
|
|
|
|
case ID_FILE_SAVEAS:
|
|
|
|
DialogSaveFile();
|
2007-06-02 00:07:02 +02:00
|
|
|
break;
|
|
|
|
|
2007-07-18 15:41:57 +02:00
|
|
|
case ID_FILE_RECENT1:
|
|
|
|
case ID_FILE_RECENT2:
|
|
|
|
case ID_FILE_RECENT3:
|
|
|
|
case ID_FILE_RECENT4:
|
|
|
|
{
|
|
|
|
HMENU hMenu = GetMenu(hWnd);
|
|
|
|
MENUITEMINFOW mi;
|
|
|
|
|
|
|
|
mi.cbSize = sizeof(MENUITEMINFOW);
|
|
|
|
mi.fMask = MIIM_DATA;
|
|
|
|
if(GetMenuItemInfoW(hMenu, LOWORD(wParam), FALSE, &mi))
|
|
|
|
DoOpenFile((LPWSTR)mi.dwItemData);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
case ID_FIND:
|
2007-08-26 15:01:44 +02:00
|
|
|
dialog_find(&findreplace, FALSE);
|
2007-07-18 15:41:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_FIND_NEXT:
|
|
|
|
handle_findmsg(&findreplace);
|
|
|
|
break;
|
|
|
|
|
2007-08-26 15:01:44 +02:00
|
|
|
case ID_REPLACE:
|
|
|
|
dialog_find(&findreplace, TRUE);
|
|
|
|
break;
|
|
|
|
|
2007-08-25 16:54:02 +02:00
|
|
|
case ID_FONTSETTINGS:
|
|
|
|
dialog_choose_font();
|
|
|
|
break;
|
|
|
|
|
2007-02-24 21:00:08 +01:00
|
|
|
case ID_PRINT:
|
2007-11-11 01:06:46 +01:00
|
|
|
dialog_print(hWnd, wszFileName);
|
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-08-23 01:36:29 +02:00
|
|
|
break;
|
|
|
|
|
2007-08-23 15:00:44 +02:00
|
|
|
case ID_PRINT_QUICK:
|
2010-02-10 08:38:40 +01:00
|
|
|
print_quick(hMainWnd, wszFileName);
|
2007-11-11 01:06:46 +01:00
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-08-23 15:00:44 +02:00
|
|
|
break;
|
|
|
|
|
2007-02-24 21:00:08 +01:00
|
|
|
case ID_PREVIEW:
|
2007-06-13 22:24:16 +02:00
|
|
|
{
|
2007-08-23 15:09:49 +02:00
|
|
|
int index = reg_formatindex(fileFormat);
|
|
|
|
DWORD tmp = barState[index];
|
2010-02-25 07:50:01 +01:00
|
|
|
barState[index] = 1 << BANDID_STATUSBAR;
|
2007-08-23 15:09:49 +02:00
|
|
|
set_bar_states();
|
|
|
|
barState[index] = tmp;
|
|
|
|
ShowWindow(hEditorWnd, FALSE);
|
|
|
|
|
2007-11-11 01:06:46 +01:00
|
|
|
init_preview(hWnd, wszFileName);
|
|
|
|
|
2007-08-23 15:09:49 +02:00
|
|
|
SetMenu(hWnd, NULL);
|
|
|
|
InvalidateRect(0, 0, TRUE);
|
2007-06-13 22:24:16 +02:00
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
2007-08-23 01:38:08 +02:00
|
|
|
case ID_PRINTSETUP:
|
2007-11-11 01:06:46 +01:00
|
|
|
dialog_printsetup(hWnd);
|
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-08-23 01:38:08 +02:00
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_FORMAT_BOLD:
|
|
|
|
case ID_FORMAT_ITALIC:
|
|
|
|
case ID_FORMAT_UNDERLINE:
|
|
|
|
{
|
|
|
|
CHARFORMAT2W fmt;
|
2007-09-08 20:23:26 +02:00
|
|
|
int effects = CFE_BOLD;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
2007-09-08 20:23:26 +02:00
|
|
|
|
|
|
|
fmt.dwMask = CFM_BOLD;
|
|
|
|
|
|
|
|
if (LOWORD(wParam) == ID_FORMAT_ITALIC)
|
|
|
|
{
|
|
|
|
effects = CFE_ITALIC;
|
|
|
|
fmt.dwMask = CFM_ITALIC;
|
|
|
|
} else if (LOWORD(wParam) == ID_FORMAT_UNDERLINE)
|
|
|
|
{
|
|
|
|
effects = CFE_UNDERLINE;
|
|
|
|
fmt.dwMask = CFM_UNDERLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.dwEffects ^= effects;
|
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-17 20:19:36 +01:00
|
|
|
case ID_FORMAT_COLOR:
|
|
|
|
{
|
|
|
|
HWND hReBarWnd = GetDlgItem(hWnd, IDC_REBAR);
|
|
|
|
HWND hFormatBarWnd = GetDlgItem(hReBarWnd, IDC_FORMATBAR);
|
|
|
|
HMENU hPop;
|
|
|
|
RECT itemrc;
|
|
|
|
POINT pt;
|
|
|
|
int mid;
|
2012-01-20 12:07:24 +01:00
|
|
|
int itemidx = SendMessageW(hFormatBarWnd, TB_COMMANDTOINDEX, ID_FORMAT_COLOR, 0);
|
2010-02-17 20:19:36 +01:00
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hFormatBarWnd, TB_GETITEMRECT, itemidx, (LPARAM)&itemrc);
|
2010-02-17 20:19:36 +01:00
|
|
|
pt.x = itemrc.left;
|
|
|
|
pt.y = itemrc.bottom;
|
|
|
|
ClientToScreen(hFormatBarWnd, &pt);
|
|
|
|
hPop = GetSubMenu(hColorPopupMenu, 0);
|
|
|
|
mid = TrackPopupMenu(hPop, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON |
|
|
|
|
TPM_RETURNCMD | TPM_NONOTIFY,
|
|
|
|
pt.x, pt.y, 0, hWnd, 0);
|
|
|
|
if (mid >= ID_COLOR_FIRST && mid <= ID_COLOR_AUTOMATIC)
|
|
|
|
{
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
ZeroMemory(&fmt, sizeof(fmt));
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
SendMessageW(hwndEditor, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
|
|
|
|
fmt.dwMask = CFM_COLOR;
|
|
|
|
|
|
|
|
if (mid < ID_COLOR_AUTOMATIC) {
|
|
|
|
fmt.crTextColor = textcolors[mid - ID_COLOR_FIRST];
|
|
|
|
fmt.dwEffects &= ~CFE_AUTOCOLOR;
|
|
|
|
} else {
|
|
|
|
fmt.dwEffects |= CFE_AUTOCOLOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageW(hwndEditor, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_EDIT_CUT:
|
2007-06-13 22:24:16 +02:00
|
|
|
PostMessageW(hwndEditor, WM_CUT, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_EDIT_COPY:
|
2007-06-13 22:24:16 +02:00
|
|
|
PostMessageW(hwndEditor, WM_COPY, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
2007-02-25 14:38:50 +01:00
|
|
|
case ID_EDIT_PASTE:
|
2007-06-13 22:24:16 +02:00
|
|
|
PostMessageW(hwndEditor, WM_PASTE, 0, 0);
|
2007-02-25 14:38:50 +01:00
|
|
|
break;
|
|
|
|
|
2007-02-25 14:39:58 +01:00
|
|
|
case ID_EDIT_CLEAR:
|
2007-06-13 22:24:16 +02:00
|
|
|
PostMessageW(hwndEditor, WM_CLEAR, 0, 0);
|
2007-02-25 14:39:58 +01:00
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_EDIT_SELECTALL:
|
|
|
|
{
|
|
|
|
CHARRANGE range = {0, -1};
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_EXSETSEL, 0, (LPARAM)&range);
|
2006-02-14 14:48:29 +01:00
|
|
|
/* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_GETTEXT:
|
|
|
|
{
|
|
|
|
int nLen = GetWindowTextLengthW(hwndEditor);
|
|
|
|
LPWSTR data = HeapAlloc( GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR) );
|
|
|
|
TEXTRANGEW tr;
|
|
|
|
|
|
|
|
GetWindowTextW(hwndEditor, data, nLen+1);
|
2008-10-09 20:34:01 +02:00
|
|
|
MessageBoxW(NULL, data, wszAppTitle, MB_OK);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, data);
|
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR));
|
|
|
|
tr.chrg.cpMin = 0;
|
|
|
|
tr.chrg.cpMax = nLen;
|
|
|
|
tr.lpstrText = data;
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hwndEditor, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
|
2008-10-09 20:34:01 +02:00
|
|
|
MessageBoxW(NULL, data, wszAppTitle, MB_OK);
|
2006-02-14 14:48:29 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
|
|
|
|
/* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_CHARFORMAT:
|
|
|
|
case ID_EDIT_DEFCHARFORMAT:
|
|
|
|
{
|
|
|
|
CHARFORMAT2W cf;
|
2010-04-24 14:09:26 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
ZeroMemory(&cf, sizeof(cf));
|
|
|
|
cf.cbSize = sizeof(cf);
|
|
|
|
cf.dwMask = 0;
|
2010-04-24 14:09:26 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETCHARFORMAT,
|
|
|
|
LOWORD(wParam) == ID_EDIT_CHARFORMAT, (LPARAM)&cf);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_PARAFORMAT:
|
|
|
|
{
|
|
|
|
PARAFORMAT2 pf;
|
|
|
|
ZeroMemory(&pf, sizeof(pf));
|
|
|
|
pf.cbSize = sizeof(pf);
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_SELECTIONINFO:
|
|
|
|
{
|
|
|
|
CHARRANGE range = {0, -1};
|
|
|
|
char buf[128];
|
|
|
|
WCHAR *data = NULL;
|
|
|
|
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hwndEditor, EM_EXGETSEL, 0, (LPARAM)&range);
|
2006-02-14 14:48:29 +01:00
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * (range.cpMax-range.cpMin+1));
|
2012-01-20 12:07:24 +01:00
|
|
|
SendMessageW(hwndEditor, EM_GETSELTEXT, 0, (LPARAM)data);
|
2006-10-10 23:01:16 +02:00
|
|
|
sprintf(buf, "Start = %d, End = %d", range.cpMin, range.cpMax);
|
2006-02-14 14:48:29 +01:00
|
|
|
MessageBoxA(hWnd, buf, "Editor", MB_OK);
|
2008-10-09 20:34:01 +02:00
|
|
|
MessageBoxW(hWnd, data, wszAppTitle, MB_OK);
|
2006-02-14 14:48:29 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, data);
|
|
|
|
/* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_READONLY:
|
|
|
|
{
|
2012-01-20 12:07:24 +01:00
|
|
|
LONG nStyle = GetWindowLongW(hwndEditor, GWL_STYLE);
|
2006-02-14 14:48:29 +01:00
|
|
|
if (nStyle & ES_READONLY)
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETREADONLY, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
else
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETREADONLY, 1, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_EDIT_MODIFIED:
|
2007-06-13 22:24:16 +02:00
|
|
|
if (SendMessageW(hwndEditor, EM_GETMODIFY, 0, 0))
|
|
|
|
SendMessageW(hwndEditor, EM_SETMODIFY, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
else
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETMODIFY, 1, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case ID_EDIT_UNDO:
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_UNDO, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case ID_EDIT_REDO:
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_REDO, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
|
2016-10-10 14:13:05 +02:00
|
|
|
case ID_BULLETONOFF:
|
2007-07-20 18:38:08 +02:00
|
|
|
case ID_BULLET:
|
2016-10-10 14:13:05 +02:00
|
|
|
case ID_NUMBERING:
|
|
|
|
case ID_LCLETTER:
|
|
|
|
case ID_UCLETTER:
|
|
|
|
case ID_LCROMAN:
|
|
|
|
case ID_UCROMAN:
|
2007-07-20 18:38:08 +02:00
|
|
|
{
|
2016-10-07 11:49:37 +02:00
|
|
|
PARAFORMAT2 pf;
|
2016-10-10 14:13:05 +02:00
|
|
|
WORD new_number = LOWORD(wParam) - ID_BULLET + PFN_BULLET;
|
2007-07-20 18:38:08 +02:00
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_NUMBERING;
|
|
|
|
SendMessageW(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
|
2016-10-10 14:13:05 +02:00
|
|
|
pf.dwMask = PFM_NUMBERING | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE | PFM_NUMBERINGTAB | PFM_OFFSET | PFM_OFFSETINDENT;
|
2007-07-20 18:38:08 +02:00
|
|
|
|
2016-10-10 14:13:05 +02:00
|
|
|
if(pf.wNumbering && ((pf.wNumbering == new_number) || (LOWORD(wParam) == ID_BULLETONOFF)))
|
2007-07-20 18:38:08 +02:00
|
|
|
{
|
|
|
|
pf.wNumbering = 0;
|
2016-10-07 11:49:37 +02:00
|
|
|
pf.wNumberingStart = 0;
|
2016-10-10 14:13:05 +02:00
|
|
|
pf.wNumberingStyle = 0;
|
2016-10-07 11:49:37 +02:00
|
|
|
pf.wNumberingTab = 0;
|
2007-07-20 18:38:08 +02:00
|
|
|
pf.dxOffset = 0;
|
2016-10-07 11:49:37 +02:00
|
|
|
pf.dxStartIndent = -360;
|
2007-07-20 18:38:08 +02:00
|
|
|
} else
|
|
|
|
{
|
2016-10-10 14:13:05 +02:00
|
|
|
pf.dxStartIndent = pf.wNumbering ? 0 : 360;
|
|
|
|
|
|
|
|
if (LOWORD(wParam) == ID_BULLETONOFF)
|
|
|
|
pf.wNumbering = last_bullet;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pf.wNumbering = new_number;
|
|
|
|
last_bullet = pf.wNumbering;
|
|
|
|
}
|
2016-10-07 11:49:37 +02:00
|
|
|
pf.wNumberingStart = 1;
|
2016-10-10 14:13:05 +02:00
|
|
|
pf.wNumberingStyle = PFNS_PERIOD;
|
2016-10-07 11:49:37 +02:00
|
|
|
pf.wNumberingTab = 360;
|
|
|
|
pf.dxOffset = 360;
|
2007-07-20 18:38:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageW(hwndEditor, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case ID_ALIGN_LEFT:
|
|
|
|
case ID_ALIGN_CENTER:
|
|
|
|
case ID_ALIGN_RIGHT:
|
|
|
|
{
|
|
|
|
PARAFORMAT2 pf;
|
|
|
|
|
|
|
|
pf.cbSize = sizeof(pf);
|
|
|
|
pf.dwMask = PFM_ALIGNMENT;
|
|
|
|
switch(LOWORD(wParam)) {
|
|
|
|
case ID_ALIGN_LEFT: pf.wAlignment = PFA_LEFT; break;
|
|
|
|
case ID_ALIGN_CENTER: pf.wAlignment = PFA_CENTER; break;
|
|
|
|
case ID_ALIGN_RIGHT: pf.wAlignment = PFA_RIGHT; break;
|
|
|
|
}
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ID_BACK_1:
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETBKGNDCOLOR, 1, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_BACK_2:
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_SETBKGNDCOLOR, 0, RGB(255,255,192));
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
|
2007-06-06 11:10:47 +02:00
|
|
|
case ID_TOGGLE_TOOLBAR:
|
2007-08-22 22:41:25 +02:00
|
|
|
set_toolbar_state(BANDID_TOOLBAR, !is_bar_visible(BANDID_TOOLBAR));
|
2007-06-06 13:28:26 +02:00
|
|
|
update_window();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TOGGLE_FORMATBAR:
|
2007-08-24 15:46:09 +02:00
|
|
|
set_toolbar_state(BANDID_FONTLIST, !is_bar_visible(BANDID_FORMATBAR));
|
2007-08-24 19:45:54 +02:00
|
|
|
set_toolbar_state(BANDID_SIZELIST, !is_bar_visible(BANDID_FORMATBAR));
|
2007-08-22 22:41:25 +02:00
|
|
|
set_toolbar_state(BANDID_FORMATBAR, !is_bar_visible(BANDID_FORMATBAR));
|
2007-06-06 13:28:26 +02:00
|
|
|
update_window();
|
2007-06-06 11:10:47 +02:00
|
|
|
break;
|
|
|
|
|
2007-06-06 11:21:08 +02:00
|
|
|
case ID_TOGGLE_STATUSBAR:
|
2007-08-22 22:41:25 +02:00
|
|
|
set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR));
|
2007-06-06 11:21:08 +02:00
|
|
|
update_window();
|
|
|
|
break;
|
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
case ID_TOGGLE_RULER:
|
|
|
|
set_toolbar_state(BANDID_RULER, !is_bar_visible(BANDID_RULER));
|
|
|
|
update_window();
|
|
|
|
break;
|
|
|
|
|
2007-07-18 15:50:21 +02:00
|
|
|
case ID_DATETIME:
|
2009-12-23 17:10:23 +01:00
|
|
|
DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_DATETIME), hWnd, datetime_proc);
|
2007-07-18 15:50:21 +02:00
|
|
|
break;
|
|
|
|
|
2007-08-23 01:15:17 +02:00
|
|
|
case ID_PARAFORMAT:
|
2009-12-23 17:10:23 +01:00
|
|
|
DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_PARAFORMAT), hWnd, paraformat_proc);
|
2007-08-23 01:15:17 +02:00
|
|
|
break;
|
|
|
|
|
2007-08-23 01:27:50 +02:00
|
|
|
case ID_TABSTOPS:
|
2010-06-25 00:36:04 +02:00
|
|
|
DialogBoxW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_TABSTOPS), hWnd, tabstops_proc);
|
2007-08-23 01:27:50 +02:00
|
|
|
break;
|
|
|
|
|
2007-08-23 15:05:40 +02:00
|
|
|
case ID_ABOUT:
|
|
|
|
dialog_about();
|
|
|
|
break;
|
|
|
|
|
2007-08-23 15:08:41 +02:00
|
|
|
case ID_VIEWPROPERTIES:
|
|
|
|
dialog_viewproperties();
|
|
|
|
break;
|
|
|
|
|
2008-06-18 03:19:15 +02:00
|
|
|
case IDC_FONTLIST:
|
|
|
|
if (HIWORD(wParam) == CBN_SELENDOK)
|
|
|
|
{
|
|
|
|
WCHAR buffer[LF_FACESIZE];
|
|
|
|
HWND hwndFontList = (HWND)lParam;
|
|
|
|
get_comboexlist_selection(hwndFontList, buffer, LF_FACESIZE);
|
2008-09-07 16:05:26 +02:00
|
|
|
on_fontlist_modified(buffer);
|
2008-06-18 03:19:15 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_SIZELIST:
|
|
|
|
if (HIWORD(wParam) == CBN_SELENDOK)
|
|
|
|
{
|
|
|
|
WCHAR buffer[MAX_STRING_LEN+1];
|
|
|
|
HWND hwndSizeList = (HWND)lParam;
|
|
|
|
get_comboexlist_selection(hwndSizeList, buffer, MAX_STRING_LEN+1);
|
|
|
|
on_sizelist_modified(hwndSizeList, buffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
default:
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, WM_COMMAND, wParam, lParam);
|
2006-02-14 14:48:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-07 16:05:26 +02:00
|
|
|
static LRESULT OnInitPopupMenu( HWND hWnd, WPARAM wParam )
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
|
|
|
HMENU hMenu = (HMENU)wParam;
|
|
|
|
HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
|
2007-06-06 11:21:08 +02:00
|
|
|
HWND hwndStatus = GetDlgItem(hWnd, IDC_STATUSBAR);
|
2006-02-14 14:48:29 +01:00
|
|
|
PARAFORMAT pf;
|
|
|
|
int nAlignment = -1;
|
2007-07-04 14:14:02 +02:00
|
|
|
int selFrom, selTo;
|
2007-07-18 15:41:33 +02:00
|
|
|
GETTEXTLENGTHEX gt;
|
|
|
|
LRESULT textLength;
|
|
|
|
MENUITEMINFOW mi;
|
2007-07-04 14:14:02 +02:00
|
|
|
|
|
|
|
SendMessageW(hEditorWnd, EM_GETSEL, (WPARAM)&selFrom, (LPARAM)&selTo);
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_EDIT_COPY, (selFrom == selTo) ? MF_GRAYED : MF_ENABLED);
|
|
|
|
EnableMenuItem(hMenu, ID_EDIT_CUT, (selFrom == selTo) ? MF_GRAYED : MF_ENABLED);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
pf.cbSize = sizeof(PARAFORMAT);
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
|
2006-02-14 14:48:29 +01:00
|
|
|
CheckMenuItem(hMenu, ID_EDIT_READONLY,
|
2015-03-06 10:20:12 +01:00
|
|
|
(GetWindowLongW(hwndEditor, GWL_STYLE) & ES_READONLY) ? MF_CHECKED : MF_UNCHECKED);
|
2006-02-14 14:48:29 +01:00
|
|
|
CheckMenuItem(hMenu, ID_EDIT_MODIFIED,
|
2015-03-06 10:20:12 +01:00
|
|
|
SendMessageW(hwndEditor, EM_GETMODIFY, 0, 0) ? MF_CHECKED : MF_UNCHECKED);
|
2006-02-14 14:48:29 +01:00
|
|
|
if (pf.dwMask & PFM_ALIGNMENT)
|
|
|
|
nAlignment = pf.wAlignment;
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_ALIGN_LEFT, (nAlignment == PFA_LEFT) ? MF_CHECKED : MF_UNCHECKED);
|
|
|
|
CheckMenuItem(hMenu, ID_ALIGN_CENTER, (nAlignment == PFA_CENTER) ? MF_CHECKED : MF_UNCHECKED);
|
|
|
|
CheckMenuItem(hMenu, ID_ALIGN_RIGHT, (nAlignment == PFA_RIGHT) ? MF_CHECKED : MF_UNCHECKED);
|
2016-10-10 14:13:05 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_BULLET, ((pf.wNumbering == PFN_BULLET) ? MF_CHECKED : MF_UNCHECKED));
|
2016-10-10 14:13:05 +02:00
|
|
|
CheckMenuItem(hMenu, ID_NUMBERING, ((pf.wNumbering == PFN_ARABIC) ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
CheckMenuItem(hMenu, ID_LCLETTER, ((pf.wNumbering == PFN_LCLETTER) ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
CheckMenuItem(hMenu, ID_UCLETTER, ((pf.wNumbering == PFN_UCLETTER) ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
CheckMenuItem(hMenu, ID_LCROMAN, ((pf.wNumbering == PFN_LCROMAN) ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
CheckMenuItem(hMenu, ID_UCROMAN, ((pf.wNumbering == PFN_UCROMAN) ? MF_CHECKED : MF_UNCHECKED));
|
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_EDIT_UNDO, SendMessageW(hwndEditor, EM_CANUNDO, 0, 0) ?
|
2007-06-06 13:28:26 +02:00
|
|
|
MF_ENABLED : MF_GRAYED);
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_EDIT_REDO, SendMessageW(hwndEditor, EM_CANREDO, 0, 0) ?
|
2007-06-06 13:28:26 +02:00
|
|
|
MF_ENABLED : MF_GRAYED);
|
2007-06-06 11:10:47 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_TOGGLE_TOOLBAR, is_bar_visible(BANDID_TOOLBAR) ?
|
2007-08-22 22:41:25 +02:00
|
|
|
MF_CHECKED : MF_UNCHECKED);
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_TOGGLE_FORMATBAR, is_bar_visible(BANDID_FORMATBAR) ?
|
2007-08-22 22:41:25 +02:00
|
|
|
MF_CHECKED : MF_UNCHECKED);
|
2007-06-06 13:28:26 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_TOGGLE_STATUSBAR, IsWindowVisible(hwndStatus) ?
|
2007-06-06 11:21:08 +02:00
|
|
|
MF_CHECKED : MF_UNCHECKED);
|
2007-07-18 15:41:33 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
CheckMenuItem(hMenu, ID_TOGGLE_RULER, is_bar_visible(BANDID_RULER) ? MF_CHECKED : MF_UNCHECKED);
|
2008-01-14 00:36:23 +01:00
|
|
|
|
2007-07-18 15:41:33 +02:00
|
|
|
gt.flags = GTL_NUMCHARS;
|
|
|
|
gt.codepage = 1200;
|
|
|
|
textLength = SendMessageW(hEditorWnd, EM_GETTEXTLENGTHEX, (WPARAM)>, 0);
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_FIND, textLength ? MF_ENABLED : MF_GRAYED);
|
2007-07-18 15:41:33 +02:00
|
|
|
|
|
|
|
mi.cbSize = sizeof(mi);
|
|
|
|
mi.fMask = MIIM_DATA;
|
|
|
|
|
|
|
|
GetMenuItemInfoW(hMenu, ID_FIND_NEXT, FALSE, &mi);
|
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_FIND_NEXT, (textLength && mi.dwItemData) ? MF_ENABLED : MF_GRAYED);
|
2007-08-26 15:01:44 +02:00
|
|
|
|
2015-03-06 10:20:12 +01:00
|
|
|
EnableMenuItem(hMenu, ID_REPLACE, textLength ? MF_ENABLED : MF_GRAYED);
|
2007-08-26 15:01:44 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam )
|
|
|
|
{
|
2007-06-06 11:10:47 +02:00
|
|
|
int nStatusSize = 0;
|
2006-02-14 14:48:29 +01:00
|
|
|
RECT rc;
|
2010-01-29 09:02:41 +01:00
|
|
|
HWND hwndEditor = preview_isactive() ? GetDlgItem(hWnd, IDC_PREVIEW) : GetDlgItem(hWnd, IDC_EDITOR);
|
2006-02-14 14:48:29 +01:00
|
|
|
HWND hwndStatusBar = GetDlgItem(hWnd, IDC_STATUSBAR);
|
|
|
|
HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
|
2010-06-15 06:07:40 +02:00
|
|
|
HWND hRulerWnd = GetDlgItem(hwndReBar, IDC_RULER);
|
2007-06-06 13:28:26 +02:00
|
|
|
int rebarHeight = 0;
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
if (hwndStatusBar)
|
|
|
|
{
|
2007-06-13 22:24:16 +02:00
|
|
|
SendMessageW(hwndStatusBar, WM_SIZE, 0, 0);
|
2007-06-06 11:21:08 +02:00
|
|
|
if (IsWindowVisible(hwndStatusBar))
|
|
|
|
{
|
|
|
|
GetClientRect(hwndStatusBar, &rc);
|
|
|
|
nStatusSize = rc.bottom - rc.top;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
nStatusSize = 0;
|
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
2007-06-06 13:28:26 +02:00
|
|
|
if (hwndReBar)
|
|
|
|
{
|
2008-02-27 18:21:40 +01:00
|
|
|
rebarHeight = SendMessageW(hwndReBar, RB_GETBARHEIGHT, 0, 0);
|
2007-09-08 21:36:50 +02:00
|
|
|
|
|
|
|
MoveWindow(hwndReBar, 0, 0, LOWORD(lParam), rebarHeight, TRUE);
|
2007-06-06 13:28:26 +02:00
|
|
|
}
|
2006-02-14 14:48:29 +01:00
|
|
|
if (hwndEditor)
|
|
|
|
{
|
|
|
|
GetClientRect(hWnd, &rc);
|
2007-06-06 11:10:47 +02:00
|
|
|
MoveWindow(hwndEditor, 0, rebarHeight, rc.right, rc.bottom-nStatusSize-rebarHeight, TRUE);
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
redraw_ruler(hRulerWnd);
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
return DefWindowProcW(hWnd, WM_SIZE, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2006-06-05 12:10:40 +02:00
|
|
|
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
2007-07-18 15:41:33 +02:00
|
|
|
if(msg == ID_FINDMSGSTRING)
|
|
|
|
return handle_findmsg((LPFINDREPLACEW)lParam);
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
switch(msg)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
2008-09-07 16:05:26 +02:00
|
|
|
return OnCreate( hWnd );
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
case WM_USER:
|
2008-09-07 16:05:26 +02:00
|
|
|
return OnUser( hWnd );
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
case WM_NOTIFY:
|
2008-09-07 16:05:26 +02:00
|
|
|
return OnNotify( hWnd, lParam );
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
case WM_COMMAND:
|
2007-11-11 01:06:46 +01:00
|
|
|
if(preview_isactive())
|
|
|
|
{
|
2008-07-22 12:04:08 +02:00
|
|
|
return preview_command( hWnd, wParam );
|
2007-11-11 01:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OnCommand( hWnd, wParam, lParam );
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
case WM_CLOSE:
|
2007-11-11 01:06:46 +01:00
|
|
|
if(preview_isactive())
|
2007-08-23 15:09:49 +02:00
|
|
|
{
|
2007-11-11 01:06:46 +01:00
|
|
|
preview_exit(hWnd);
|
2007-08-23 15:09:49 +02:00
|
|
|
} else if(prompt_save_changes())
|
2007-07-18 23:40:58 +02:00
|
|
|
{
|
2007-12-12 09:36:41 +01:00
|
|
|
registry_set_options(hMainWnd);
|
2010-07-20 00:22:22 +02:00
|
|
|
registry_set_formatopts_all(barState, wordWrap);
|
2007-07-08 13:51:19 +02:00
|
|
|
PostQuitMessage(0);
|
2007-07-18 23:40:58 +02:00
|
|
|
}
|
2007-07-08 13:51:19 +02:00
|
|
|
break;
|
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
if (LOWORD(wParam))
|
|
|
|
SetFocus(GetDlgItem(hWnd, IDC_EDITOR));
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_INITMENUPOPUP:
|
2008-09-07 16:05:26 +02:00
|
|
|
return OnInitPopupMenu( hWnd, wParam );
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
return OnSize( hWnd, wParam, lParam );
|
|
|
|
|
2007-08-23 15:05:23 +02:00
|
|
|
case WM_CONTEXTMENU:
|
2010-07-22 14:30:19 +02:00
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
2007-08-23 15:05:23 +02:00
|
|
|
|
2007-08-22 22:45:11 +02:00
|
|
|
case WM_DROPFILES:
|
|
|
|
{
|
|
|
|
WCHAR file[MAX_PATH];
|
|
|
|
DragQueryFileW((HDROP)wParam, 0, file, MAX_PATH);
|
|
|
|
DragFinish((HDROP)wParam);
|
|
|
|
|
|
|
|
if(prompt_save_changes())
|
|
|
|
DoOpenFile(file);
|
|
|
|
}
|
|
|
|
break;
|
2007-08-23 15:09:49 +02:00
|
|
|
case WM_PAINT:
|
2010-01-29 09:02:41 +01:00
|
|
|
if(!preview_isactive())
|
2007-08-23 15:09:49 +02:00
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
2007-08-22 22:45:11 +02:00
|
|
|
|
2006-02-14 14:48:29 +01:00
|
|
|
default:
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-03 18:51:17 +02:00
|
|
|
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdParagraph, int nCmdShow)
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
2007-08-24 15:46:09 +02:00
|
|
|
INITCOMMONCONTROLSEX classes = {8, ICC_BAR_CLASSES|ICC_COOL_CLASSES|ICC_USEREX_CLASSES};
|
2006-02-14 14:48:29 +01:00
|
|
|
HACCEL hAccel;
|
2010-04-19 20:13:34 +02:00
|
|
|
WNDCLASSEXW wc;
|
2006-02-14 14:48:29 +01:00
|
|
|
MSG msg;
|
2007-07-18 23:40:58 +02:00
|
|
|
RECT rc;
|
2008-01-14 00:36:23 +01:00
|
|
|
UINT_PTR hPrevRulerProc;
|
|
|
|
HWND hRulerWnd;
|
|
|
|
POINTL EditPoint;
|
2008-07-03 18:51:17 +02:00
|
|
|
DWORD bMaximized;
|
2017-03-21 22:59:13 +01:00
|
|
|
MONITORINFO info;
|
|
|
|
HMONITOR monitor;
|
|
|
|
int x, y;
|
2007-06-13 22:24:16 +02:00
|
|
|
static const WCHAR wszAccelTable[] = {'M','A','I','N','A','C','C','E','L',
|
|
|
|
'T','A','B','L','E','\0'};
|
2006-02-14 14:48:29 +01:00
|
|
|
|
|
|
|
InitCommonControlsEx(&classes);
|
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
hAccel = LoadAcceleratorsW(hInstance, wszAccelTable);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2010-06-11 06:43:44 +02:00
|
|
|
wc.cbSize = sizeof(wc);
|
2010-07-20 00:20:48 +02:00
|
|
|
wc.style = 0;
|
2006-02-14 14:48:29 +01:00
|
|
|
wc.lpfnWndProc = WndProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 4;
|
|
|
|
wc.hInstance = hInstance;
|
2007-05-29 22:19:36 +02:00
|
|
|
wc.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_WORDPAD));
|
2010-04-19 20:13:34 +02:00
|
|
|
wc.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_WORDPAD), IMAGE_ICON,
|
|
|
|
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
|
2012-01-20 12:07:24 +01:00
|
|
|
wc.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_IBEAM);
|
2006-02-14 14:48:29 +01:00
|
|
|
wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
|
2007-11-04 12:34:03 +01:00
|
|
|
wc.lpszMenuName = MAKEINTRESOURCEW(IDM_MAINMENU);
|
2006-02-14 14:48:29 +01:00
|
|
|
wc.lpszClassName = wszMainWndClass;
|
2010-04-19 20:13:34 +02:00
|
|
|
RegisterClassExW(&wc);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2010-07-20 00:20:48 +02:00
|
|
|
wc.style = 0;
|
2010-01-29 09:02:41 +01:00
|
|
|
wc.lpfnWndProc = preview_proc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
wc.hIcon = NULL;
|
2010-04-19 20:13:34 +02:00
|
|
|
wc.hIconSm = NULL;
|
2012-01-20 12:07:24 +01:00
|
|
|
wc.hCursor = LoadCursorW(NULL, (LPWSTR)IDC_IBEAM);
|
2010-07-20 00:20:48 +02:00
|
|
|
wc.hbrBackground = NULL;
|
2010-01-29 09:02:41 +01:00
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = wszPreviewWndClass;
|
2010-04-19 20:13:34 +02:00
|
|
|
RegisterClassExW(&wc);
|
2010-01-29 09:02:41 +01:00
|
|
|
|
2007-12-12 09:36:41 +01:00
|
|
|
registry_read_winrect(&rc);
|
2017-03-21 22:59:13 +01:00
|
|
|
monitor = MonitorFromRect(&rc, MONITOR_DEFAULTTOPRIMARY);
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
GetMonitorInfoW(monitor, &info);
|
|
|
|
|
|
|
|
x = rc.left;
|
|
|
|
y = rc.top;
|
|
|
|
IntersectRect(&info.rcWork, &info.rcWork, &rc);
|
|
|
|
if (IsRectEmpty(&info.rcWork))
|
|
|
|
x = y = CW_USEDEFAULT;
|
|
|
|
|
2007-09-11 16:11:48 +02:00
|
|
|
hMainWnd = CreateWindowExW(0, wszMainWndClass, wszAppTitle, WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW,
|
2017-03-21 22:59:13 +01:00
|
|
|
x, y, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);
|
2008-07-03 18:51:17 +02:00
|
|
|
registry_read_maximized(&bMaximized);
|
|
|
|
if ((nCmdShow == SW_SHOWNORMAL || nCmdShow == SW_SHOWDEFAULT)
|
|
|
|
&& bMaximized)
|
|
|
|
nCmdShow = SW_SHOWMAXIMIZED;
|
|
|
|
ShowWindow(hMainWnd, nCmdShow);
|
2006-02-14 14:48:29 +01:00
|
|
|
|
2007-07-08 13:51:19 +02:00
|
|
|
set_caption(NULL);
|
2007-08-22 22:41:25 +02:00
|
|
|
set_bar_states();
|
2007-08-25 20:41:30 +02:00
|
|
|
set_fileformat(SF_RTF);
|
2010-02-17 20:19:36 +01:00
|
|
|
hColorPopupMenu = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDM_COLOR_POPUP));
|
2007-08-23 15:08:41 +02:00
|
|
|
get_default_printer_opts();
|
2007-11-11 01:06:46 +01:00
|
|
|
target_device(hMainWnd, wordWrap[reg_formatindex(fileFormat)]);
|
2007-07-08 13:51:19 +02:00
|
|
|
|
2008-01-14 00:36:23 +01:00
|
|
|
hRulerWnd = GetDlgItem(GetDlgItem(hMainWnd, IDC_REBAR), IDC_RULER);
|
|
|
|
SendMessageW(GetDlgItem(hMainWnd, IDC_EDITOR), EM_POSFROMCHAR, (WPARAM)&EditPoint, 0);
|
|
|
|
hPrevRulerProc = SetWindowLongPtrW(hRulerWnd, GWLP_WNDPROC, (UINT_PTR)ruler_proc);
|
|
|
|
SendMessageW(hRulerWnd, WM_USER, (WPARAM)&EditPoint, hPrevRulerProc);
|
|
|
|
|
2007-02-10 22:55:29 +01:00
|
|
|
HandleCommandLine(GetCommandLineW());
|
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
while(GetMessageW(&msg,0,0,0))
|
2006-02-14 14:48:29 +01:00
|
|
|
{
|
2012-01-20 12:07:24 +01:00
|
|
|
if (IsDialogMessageW(hFindWnd, &msg))
|
2007-07-18 15:41:33 +02:00
|
|
|
continue;
|
|
|
|
|
2007-06-13 22:24:16 +02:00
|
|
|
if (TranslateAcceleratorW(hMainWnd, hAccel, &msg))
|
2006-02-14 14:48:29 +01:00
|
|
|
continue;
|
|
|
|
TranslateMessage(&msg);
|
2007-06-13 22:24:16 +02:00
|
|
|
DispatchMessageW(&msg);
|
|
|
|
if (!PeekMessageW(&msg, 0, 0, 0, PM_NOREMOVE))
|
|
|
|
SendMessageW(hMainWnd, WM_USER, 0, 0);
|
2006-02-14 14:48:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|