Skip to content

Commit

Permalink
Merge pull request #779 from RaiKoHoff/Dev_RC2_fixes
Browse files Browse the repository at this point in the history
Switch to RichText Edit Control v.5.0 (msftedit.dll) for AboutBox text
  • Loading branch information
RaiKoHoff authored Nov 6, 2018
2 parents 2044c92 + 0119158 commit 731a633
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 40 deletions.
2 changes: 2 additions & 0 deletions language/common_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,4 +943,6 @@
#define IDS_LEX_STR_63352 63352
#define IDS_LEX_STR_63353 63353

#define RICHEDIT_CONTROL_VER "RichEdit50W" // RICHEDIT_CONTROL_VER

#endif //_COMMON_RES_H_
Binary file modified language/np3_af_za/dialogs_af_za.rc
Binary file not shown.
Binary file modified language/np3_be_by/dialogs_be_by.rc
Binary file not shown.
Binary file modified language/np3_de_de/dialogs_de_de.rc
Binary file not shown.
Binary file modified language/np3_en_gb/dialogs_en_gb.rc
Binary file not shown.
Binary file modified language/np3_en_us/dialogs_en_us.rc
Binary file not shown.
Binary file modified language/np3_es_es/dialogs_es_es.rc
Binary file not shown.
Binary file modified language/np3_fr_fr/dialogs_fr_fr.rc
Binary file not shown.
Binary file modified language/np3_ja_jp/dialogs_ja_jp.rc
Binary file not shown.
Binary file modified language/np3_nl_nl/dialogs_nl_nl.rc
Binary file not shown.
Binary file modified language/np3_ru_ru/dialogs_ru_ru.rc
Binary file not shown.
Binary file modified language/np3_zh_cn/dialogs_zh_cn.rc
Binary file not shown.
107 changes: 76 additions & 31 deletions src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@

#include "Dialogs.h"


//=============================================================================
//
// MsgBoxLng()
Expand Down Expand Up @@ -383,6 +382,8 @@ static DWORD _LoadStringEx(UINT nResId, LPCTSTR pszRsType, LPSTR strOut)
// (EditStreamCallback)
// _LoadRtfCallback() RTF edit control StreamIn's callback function
//
#if true

static DWORD CALLBACK _LoadRtfCallback(
DWORD_PTR dwCookie, // (in) pointer to the string
LPBYTE pbBuff, // (in) pointer to the destination buffer
Expand All @@ -391,7 +392,7 @@ static DWORD CALLBACK _LoadRtfCallback(
)
{
LPSTR* pstr = (LPSTR*)dwCookie;
LONG len = (LONG)StringCchLenA(*pstr,0);
LONG const len = (LONG)StringCchLenA(*pstr,0);

if (len < cb)
{
Expand All @@ -410,10 +411,37 @@ static DWORD CALLBACK _LoadRtfCallback(
}
// ----------------------------------------------------------------------------

#else

static DWORD CALLBACK _LoadRtfCallbackW(
DWORD_PTR dwCookie, // (in) pointer to the string
LPBYTE pbBuff, // (in) pointer to the destination buffer
LONG cb, // (in) size in bytes of the destination buffer
LONG FAR* pcb // (out) number of bytes transfered
)
{
LPWSTR* pstr = (LPWSTR*)dwCookie;
LONG const len = (LONG)StringCchLen(*pstr, 0);
LONG const size = len * sizeof(WCHAR);

static char pAboutResource[8192] = { '\0' };
static char* pAboutInfo;
cb -= (cb % sizeof(WCHAR));

if (size < cb) {
*pcb = size;
memcpy(pbBuff, (LPCWSTR)*pstr, *pcb);
*pstr += len;
//*pstr = '\0';
}
else {
*pcb = cb;
memcpy(pbBuff, (LPCWSTR)*pstr, *pcb);
*pstr += (cb / sizeof(WCHAR));
}
return 0;
}
// ----------------------------------------------------------------------------

#endif

//=============================================================================
//
Expand Down Expand Up @@ -495,6 +523,9 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam

#if true

static char pAboutResource[8192] = { '\0' };
static char* pAboutInfo = NULL;

char pAboutRes[4000];
GetLngStringA(IDS_MUI_ABOUT_RTF_1, pAboutRes, COUNTOF(pAboutRes));
StringCchCopyA(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
Expand All @@ -519,39 +550,53 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
GetLngStringA(IDS_MUI_ABOUT_RTF_6, pAboutRes, COUNTOF(pAboutRes));
StringCchCatA(pAboutResource, COUNTOF(pAboutResource), pAboutRes);


pAboutInfo = pAboutResource;

EDITSTREAM editStreamIn = { (DWORD_PTR)&pAboutInfo, 0, _LoadRtfCallback };
pAboutInfo = pAboutResource;
SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_STREAMIN, SF_RTF, (LPARAM)&editStreamIn);


//DWORD dwSize = _LoadStringEx(IDR_ABOUTINFO_RTF, L"RTF", NULL);
//if (dwSize != 0) {
// char* pchBuffer = AllocMem(dwSize + 1, HEAP_ZERO_MEMORY);
// pAboutInfo = pchBuffer;
// _LoadStringEx(IDR_ABOUTINFO_RTF, L"RTF", pAboutInfo);
// SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_STREAMIN, SF_RTF, (LPARAM)&editStreamIn);
// FreeMem(pchBuffer);
//}
//else {
// pAboutInfo = chErrMsg;
// SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_STREAMIN, SF_RTF, (LPARAM)&editStreamIn);
//}

#else
PARAFORMAT2 pf2;
ZeroMemory(&pf2, sizeof(PARAFORMAT2));
pf2.cbSize = (UINT)sizeof(PARAFORMAT2);
pf2.dwMask = (PFM_SPACEBEFORE | PFM_SPACEAFTER | PFM_LINESPACING);
pf2.dySpaceBefore = 48; // paragraph
pf2.dySpaceAfter = 48; // paragraph
pf2.dyLineSpacing = 24; // [twips]
pf2.bLineSpacingRule = 5; // 5: dyLineSpacing/20 is the spacing, in lines, from one line to the next.
SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETPARAFORMAT, 0, (LPARAM)&pf2);
SetDlgItemText(hwnd, IDC_RICHEDITABOUT, ABOUT_INFO_PLAIN);
#endif

static WCHAR pAboutResource[8192] = { L'\0' };
static PWCHAR pAboutInfo = NULL;

WCHAR pAboutRes[4000];
GetLngString(IDS_MUI_ABOUT_RTF_1, pAboutRes, COUNTOF(pAboutRes));
StringCchCopy(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_CONTRIBS, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_RTF_2, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_LIBS, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_RTF_3, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_ACKNOWLEDGES, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_RTF_4, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_MORE, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_RTF_5, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_LICENSES, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
GetLngString(IDS_MUI_ABOUT_RTF_6, pAboutRes, COUNTOF(pAboutRes));
StringCchCat(pAboutResource, COUNTOF(pAboutResource), pAboutRes);

pAboutInfo = pAboutResource;

EDITSTREAM editStreamIn = { (DWORD_PTR)&pAboutInfo, 0, _LoadRtfCallbackW };
SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_STREAMIN, (WPARAM)(UINT)(SF_TEXT | SF_UNICODE), (LPARAM)&editStreamIn);

// EM_SETTEXTEX is Richedit 3.0 only
//SETTEXTEX ste;
//ste.flags = ST_SELECTION; // replace everything
//ste.codepage = 1200; // Unicode is codepage 1200
//SendDlgItemMessage(hwnd, IDC_RICHEDITABOUT, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)pAboutInfo);

#endif

CenterDlgInParent(hwnd);
}
return true;
Expand Down
12 changes: 7 additions & 5 deletions src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static WCHAR* const _s_RecentReplace = L"Recent Replace";
static WCHAR s_tchLastSaveCopyDir[MAX_PATH + 1] = { L'\0' };
static bool s_bExternalBitmap = false;

static HMODULE s_hRichEdit = NULL;
static bool s_bRunningWatch = false;
static bool s_bFileReadOnly = false;

Expand Down Expand Up @@ -159,6 +158,7 @@ static int s_iExprError = -1;

static WIN32_FIND_DATA s_fdCurFile;

static HMODULE s_hRichEdit = INVALID_HANDLE_VALUE;

// Globals <= @@@
bool g_bWordWrapG;
Expand Down Expand Up @@ -495,6 +495,7 @@ static void _CleanUpResources(const HWND hwnd, bool bIsInitialized)

if (s_hRichEdit) {
FreeLibrary(s_hRichEdit);
s_hRichEdit = INVALID_HANDLE_VALUE;
}

if (bIsInitialized) {
Expand Down Expand Up @@ -645,12 +646,13 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
}
// ----------------------------------------------------

if (s_hRichEdit == INVALID_HANDLE_VALUE) {
//s_hRichEdit = LoadLibrary(L"RICHED20.DLL"); // Use RICHEDIT_CONTROL_VER for control in common_res.h
s_hRichEdit = LoadLibrary(L"MSFTEDIT.DLL"); // Use "RichEdit50W" for control in common_res.h
}

s_msgTaskbarCreated = RegisterWindowMessage(L"TaskbarCreated");

s_hRichEdit = LoadLibrary(L"RICHED20.DLL"); // Use "RichEdit20W" for control in .rc
//s_hRichEdit = LoadLibrary(L"MSFTEDIT.DLL"); // Use "RichEdit50W" for control in .rc

if (!Globals.hDlgIcon) {
Globals.hDlgIcon = LoadImage(hInstance, MAKEINTRESOURCE(IDR_MAINWND), IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
Expand Down Expand Up @@ -2768,7 +2770,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
EnableCmd(hmenu,IDM_EDIT_ESCAPECCHARS,!s && !ro);
EnableCmd(hmenu,IDM_EDIT_UNESCAPECCHARS,!s && !ro);

EnableCmd(hmenu,IDM_EDIT_CHAR2HEX, !ro); // Char2Hex allowed for char after curr pos
EnableCmd(hmenu,IDM_EDIT_CHAR2HEX, !ro); // Char2Hex allowed for char after current pos
EnableCmd(hmenu,IDM_EDIT_HEX2CHAR, !s && !ro);

//EnableCmd(hmenu,IDM_EDIT_INCREASENUM,!s && !ro);
Expand Down
8 changes: 4 additions & 4 deletions test/TestAhkNotepad3.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Goto LABEL_END
; =============================================================================
CHECK_NP3_STARTS:
; check that NP3 starts up
WinWait ahk_pid %v_Notepad3_PID%, , 3
WinWait ahk_pid %v_Notepad3_PID%, , 10
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
Expand Down Expand Up @@ -91,7 +91,7 @@ WinActivate, ahk_pid %v_Notepad3_PID%
; This will select File->Open in Notepad:
WinMenuSelectItem, ahk_pid %v_Notepad3_PID%, , Help, About...

WinWait, About %v_NP3Name%, , 1
WinWait, About %v_NP3Name%, , 3
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
Expand All @@ -103,7 +103,7 @@ WinActivate ; About Box
;ControlFocus, OK, About %v_NP3Name%
ControlClick, OK, About %v_NP3Name%
;Send {Enter}
WinWaitClose, About %v_NP3Name%, , 1
WinWaitClose, About %v_NP3Name%, , 2
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
Expand All @@ -116,7 +116,7 @@ Return

; =============================================================================
LABEL_END:
WinClose ahk_pid %v_Notepad3_PID%, , 1
WinClose ahk_pid %v_Notepad3_PID%, , 2
v_ErrLevel = %ErrorLevel%
if (v_ErrLevel != 0)
{
Expand Down

0 comments on commit 731a633

Please sign in to comment.