https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d8b773b19062cbb9466dd…
commit d8b773b19062cbb9466dde17c92e518c4510f7f3
Author: Giannis Adamopoulos <gadamopoulos(a)reactos.org>
AuthorDate: Sun Apr 28 06:27:53 2019 +0300
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Tue Aug 20 00:43:46 2019 +0200
[RAPPS] CAppRichEdit: Add a new class that handles filling the richtext control
---
base/applications/rapps/gui.cpp | 168 ++++++++++++++++++++--------
base/applications/rapps/include/installed.h | 4 +-
base/applications/rapps/installed.cpp | 45 +-------
base/applications/rapps/misc.cpp | 14 ---
4 files changed, 123 insertions(+), 108 deletions(-)
diff --git a/base/applications/rapps/gui.cpp b/base/applications/rapps/gui.cpp
index 3695ca73a54..cf8ef0f3126 100644
--- a/base/applications/rapps/gui.cpp
+++ b/base/applications/rapps/gui.cpp
@@ -55,60 +55,62 @@ INT GetSystemColorDepth()
return ColorDepth;
}
-class CAvailableAppView
+class CAppRichEdit:
+ public CUiWindow<CRichEdit>
{
- static inline VOID InsertTextAfterLoaded_RichEdit(UINT uStringID,
- const ATL::CStringW& szText,
- DWORD StringFlags,
- DWORD TextFlags)
+private:
+ VOID LoadAndInsertText(UINT uStringID,
+ const ATL::CStringW& szText,
+ DWORD StringFlags,
+ DWORD TextFlags)
{
ATL::CStringW szLoadedText;
if (!szText.IsEmpty() && szLoadedText.LoadStringW(uStringID))
{
- InsertRichEditText(szLoadedText, StringFlags);
- InsertRichEditText(szText, TextFlags);
+ InsertText(szLoadedText, StringFlags);
+ InsertText(szText, TextFlags);
}
}
- static inline VOID InsertLoadedTextNewl_RichEdit(UINT uStringID,
- DWORD StringFlags)
+ VOID LoadAndInsertText(UINT uStringID,
+ DWORD StringFlags)
{
ATL::CStringW szLoadedText;
if (szLoadedText.LoadStringW(uStringID))
{
- InsertRichEditText(L"\n", 0);
- InsertRichEditText(szLoadedText, StringFlags);
- InsertRichEditText(L"\n", 0);
+ InsertText(L"\n", 0);
+ InsertText(szLoadedText, StringFlags);
+ InsertText(L"\n", 0);
}
}
- static VOID InsertVersionInfo_RichEdit(CAvailableApplicationInfo* Info)
+ VOID InsertVersionInfo(CAvailableApplicationInfo* Info)
{
if (Info->IsInstalled())
{
if (Info->HasInstalledVersion())
{
if (Info->HasUpdate())
- InsertLoadedTextNewl_RichEdit(IDS_STATUS_UPDATE_AVAILABLE,
CFE_ITALIC);
+ LoadAndInsertText(IDS_STATUS_UPDATE_AVAILABLE, CFE_ITALIC);
else
- InsertLoadedTextNewl_RichEdit(IDS_STATUS_INSTALLED, CFE_ITALIC);
+ LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_VERSION,
Info->m_szInstalledVersion, CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_VERSION, Info->m_szInstalledVersion,
CFE_BOLD, 0);
}
else
{
- InsertLoadedTextNewl_RichEdit(IDS_STATUS_INSTALLED, CFE_ITALIC);
+ LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
}
}
else
{
- InsertLoadedTextNewl_RichEdit(IDS_STATUS_NOTINSTALLED, CFE_ITALIC);
+ LoadAndInsertText(IDS_STATUS_NOTINSTALLED, CFE_ITALIC);
}
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_AVAILABLEVERSION, Info->m_szVersion,
CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_AVAILABLEVERSION, Info->m_szVersion, CFE_BOLD,
0);
}
- static VOID InsertLicenseInfo_RichEdit(CAvailableApplicationInfo* Info)
+ VOID InsertLicenseInfo(CAvailableApplicationInfo* Info)
{
ATL::CStringW szLicense;
switch (Info->m_LicenseType)
@@ -123,15 +125,15 @@ class CAvailableAppView
szLicense.LoadStringW(IDS_LICENSE_TRIAL);
break;
default:
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_LICENSE, Info->m_szLicense,
CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_LICENSE, Info->m_szLicense, CFE_BOLD, 0);
return;
}
szLicense += L" (" + Info->m_szLicense + L")";
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_LICENSE, szLicense, CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_LICENSE, szLicense, CFE_BOLD, 0);
}
- static VOID InsertLanguageInfo_RichEdit(CAvailableApplicationInfo* Info)
+ VOID InsertLanguageInfo(CAvailableApplicationInfo* Info)
{
if (!Info->HasLanguageInfo())
{
@@ -180,29 +182,81 @@ class CAvailableAppView
szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_NO_TRANSLATION);
}
- InsertRichEditText(szLoadedAInfoText, CFE_BOLD);
- InsertRichEditText(szLoadedTextAvailability, NULL);
- InsertRichEditText(szLangInfo, CFE_ITALIC);
+ InsertText(szLoadedAInfoText, CFE_BOLD);
+ InsertText(szLoadedTextAvailability, NULL);
+ InsertText(szLangInfo, CFE_ITALIC);
}
public:
- static BOOL ShowAvailableAppInfo(INT Index)
+ BOOL ShowAvailableAppInfo(CAvailableApplicationInfo* Info)
{
- CAvailableApplicationInfo* Info = (CAvailableApplicationInfo*)
ListViewGetlParam(Index);
if (!Info) return FALSE;
- NewRichEditText(Info->m_szName, CFE_BOLD);
- InsertVersionInfo_RichEdit(Info);
- InsertLicenseInfo_RichEdit(Info);
- InsertLanguageInfo_RichEdit(Info);
+ SetText(Info->m_szName, CFE_BOLD);
+ InsertVersionInfo(Info);
+ InsertLicenseInfo(Info);
+ InsertLanguageInfo(Info);
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_SIZE, Info->m_szSize, CFE_BOLD, 0);
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_URLSITE, Info->m_szUrlSite, CFE_BOLD,
CFE_LINK);
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_DESCRIPTION, Info->m_szDesc,
CFE_BOLD, 0);
- InsertTextAfterLoaded_RichEdit(IDS_AINFO_URLDOWNLOAD, Info->m_szUrlDownload,
CFE_BOLD, CFE_LINK);
+ LoadAndInsertText(IDS_AINFO_SIZE, Info->m_szSize, CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_URLSITE, Info->m_szUrlSite, CFE_BOLD, CFE_LINK);
+ LoadAndInsertText(IDS_AINFO_DESCRIPTION, Info->m_szDesc, CFE_BOLD, 0);
+ LoadAndInsertText(IDS_AINFO_URLDOWNLOAD, Info->m_szUrlDownload, CFE_BOLD,
CFE_LINK);
return TRUE;
}
+
+ BOOL ShowInstalledAppInfo(PINSTALLED_INFO Info)
+ {
+ ATL::CStringW szText;
+ ATL::CStringW szInfo;
+
+ if (!Info || !Info->hSubKey)
+ return FALSE;
+
+ Info->GetApplicationString(L"DisplayName", szText);
+ SetText(szText, CFE_BOLD);
+ InsertText(L"\n", 0);
+
+#define GET_INFO(a, b, c, d) \
+ if (Info->GetApplicationString(a, szInfo)) \
+ { \
+ LoadAndInsertText(b, szInfo, c, d); \
+ }
+
+ GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
+ GET_INFO(L"Publisher", IDS_INFO_PUBLISHER, CFE_BOLD, 0);
+ GET_INFO(L"RegOwner", IDS_INFO_REGOWNER, CFE_BOLD, 0);
+ GET_INFO(L"ProductID", IDS_INFO_PRODUCTID, CFE_BOLD, 0);
+ GET_INFO(L"HelpLink", IDS_INFO_HELPLINK, CFE_BOLD, CFM_LINK);
+ GET_INFO(L"HelpTelephone", IDS_INFO_HELPPHONE, CFE_BOLD, 0);
+ GET_INFO(L"Readme", IDS_INFO_README, CFE_BOLD, 0);
+ GET_INFO(L"Contact", IDS_INFO_CONTACT, CFE_BOLD, 0);
+ GET_INFO(L"URLUpdateInfo", IDS_INFO_UPDATEINFO, CFE_BOLD, CFM_LINK);
+ GET_INFO(L"URLInfoAbout", IDS_INFO_INFOABOUT, CFE_BOLD, CFM_LINK);
+ GET_INFO(L"Comments", IDS_INFO_COMMENTS, CFE_BOLD, 0);
+ GET_INFO(L"InstallDate", IDS_INFO_INSTALLDATE, CFE_BOLD, 0);
+ GET_INFO(L"InstallLocation", IDS_INFO_INSTLOCATION, CFE_BOLD, 0);
+ GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
+ GET_INFO(L"UninstallString", IDS_INFO_UNINSTALLSTR, CFE_BOLD, 0);
+ GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
+ GET_INFO(L"ModifyPath", IDS_INFO_MODIFYPATH, CFE_BOLD, 0);
+
+ return TRUE;
+ }
+
+ VOID SetWelcomeText()
+ {
+ ATL::CStringW szText;
+
+ szText.LoadStringW(IDS_WELCOME_TITLE);
+ SetText(szText, CFE_BOLD);
+
+ szText.LoadStringW(IDS_WELCOME_TEXT);
+ InsertText(szText, 0);
+
+ szText.LoadStringW(IDS_WELCOME_URL);
+ InsertText(szText, CFM_LINK);
+ }
};
class CMainToolbar :
@@ -733,7 +787,7 @@ class CMainWindow :
CSideTreeView* m_TreeView;
CUiWindow<CStatusBar>* m_StatusBar;
- CUiWindow<CRichEdit>* m_RichEdit;
+ CAppRichEdit* m_RichEdit;
CUiWindow<CSearchBar>* m_SearchBar;
CAvailableApps m_AvailableApps;
@@ -854,7 +908,7 @@ private:
BOOL CreateRichEdit()
{
- m_RichEdit = new CUiWindow<CRichEdit>();
+ m_RichEdit = new CAppRichEdit();
m_RichEdit->m_VerticalAlignment = UiAlign_Stretch;
m_RichEdit->m_HorizontalAlignment = UiAlign_Stretch;
m_HSplitter->Second().Append(m_RichEdit);
@@ -965,6 +1019,28 @@ private:
return FALSE;
}
+ VOID ShowAppInfo(INT Index)
+ {
+ if (IsInstalledEnum(SelectedEnumType))
+ {
+ if (Index == -1)
+ Index = m_ListView->GetSelectionMark();
+
+ PINSTALLED_INFO Info = (PINSTALLED_INFO) m_ListView->GetItemData(Index);
+
+ m_RichEdit->ShowInstalledAppInfo(Info);
+ }
+ else if (IsAvailableEnum(SelectedEnumType))
+ {
+ if (Index == -1)
+ return;
+
+ CAvailableApplicationInfo* Info = (CAvailableApplicationInfo*)
m_ListView->GetItemData(Index);
+
+ m_RichEdit->ShowAvailableAppInfo(Info);
+ }
+ }
+
VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
if (wParam == SIZE_MINIMIZED)
@@ -1208,10 +1284,7 @@ private:
(pnic->uNewState & LVIS_FOCUSED) &&
!(pnic->uOldState & LVIS_FOCUSED))
{
- if (IsInstalledEnum(SelectedEnumType))
- ShowInstalledAppInfo(ItemIndex);
- if (IsAvailableEnum(SelectedEnumType))
- CAvailableAppView::ShowAvailableAppInfo(ItemIndex);
+ ShowAppInfo(ItemIndex);
}
/* Check if the item is checked */
if ((pnic->uNewState & LVIS_STATEIMAGEMASK) &&
!bUpdating)
@@ -1250,10 +1323,7 @@ private:
{
if (data->hwndFrom == m_ListView->m_hWnd && ((LPNMLISTVIEW)
lParam)->iItem != -1)
{
- if (IsInstalledEnum(SelectedEnumType))
- ShowInstalledAppInfo(-1);
- if (IsAvailableEnum(SelectedEnumType))
- CAvailableAppView::ShowAvailableAppInfo(-1);
+ ShowAppInfo(-1);
}
}
break;
@@ -1566,11 +1636,11 @@ private:
Index = ListViewAddItem(ItemIndex, 0, m_szName, (LPARAM) ItemInfo);
/* Get version info */
- GetApplicationString(ItemInfo->hSubKey, L"DisplayVersion", szText);
+ ItemInfo->GetApplicationString(L"DisplayVersion", szText);
ListView_SetItemText(hListView, Index, 1,
const_cast<LPWSTR>(szText.GetString()));
/* Get comments */
- GetApplicationString(ItemInfo->hSubKey, L"Comments", szText);
+ ItemInfo->GetApplicationString(L"Comments", szText);
ListView_SetItemText(hListView, Index, 2,
const_cast<LPWSTR>(szText.GetString()));
return TRUE;
@@ -1691,7 +1761,7 @@ private:
SelectedEnumType = EnumType;
UpdateStatusBarText();
- SetWelcomeText();
+ m_RichEdit->SetWelcomeText();
// Set automatic column width for program names if the list is not empty
if (m_ListView->GetItemCount() > 0)
diff --git a/base/applications/rapps/include/installed.h
b/base/applications/rapps/include/installed.h
index bd916d806f8..e5293c2761b 100644
--- a/base/applications/rapps/include/installed.h
+++ b/base/applications/rapps/include/installed.h
@@ -8,6 +8,8 @@ struct INSTALLED_INFO
HKEY hRootKey;
HKEY hSubKey;
ATL::CStringW szKeyName;
+
+ BOOL GetApplicationString(LPCWSTR lpKeyName, ATL::CStringW& String);
};
typedef INSTALLED_INFO *PINSTALLED_INFO;
@@ -15,8 +17,6 @@ typedef BOOL(CALLBACK *APPENUMPROC)(INT ItemIndex, ATL::CStringW
&Name, PINSTALL
BOOL EnumInstalledApplications(INT EnumType, BOOL IsUserKey, APPENUMPROC lpEnumProc);
BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, LPWSTR szString);
-BOOL GetApplicationString(HKEY hKey, LPCWSTR RegName, ATL::CStringW &String);
-BOOL ShowInstalledAppInfo(INT Index);
BOOL UninstallApplication(INT Index, BOOL bModify);
VOID RemoveAppFromRegistry(INT Index);
diff --git a/base/applications/rapps/installed.cpp
b/base/applications/rapps/installed.cpp
index c8418dca93c..83fdbe4e8a1 100644
--- a/base/applications/rapps/installed.cpp
+++ b/base/applications/rapps/installed.cpp
@@ -13,9 +13,9 @@
#include "gui.h"
#include "misc.h"
-BOOL GetApplicationString(HKEY hKey, LPCWSTR lpKeyName, ATL::CStringW& String)
+BOOL INSTALLED_INFO::GetApplicationString(LPCWSTR lpKeyName, ATL::CStringW& String)
{
- BOOL result = GetApplicationString(hKey, lpKeyName, String.GetBuffer(MAX_PATH));
+ BOOL result = ::GetApplicationString(hSubKey, lpKeyName,
String.GetBuffer(MAX_PATH));
String.ReleaseBuffer();
return result;
}
@@ -92,47 +92,6 @@ BOOL UninstallApplication(INT Index, BOOL bModify)
return StartProcess(szPath, TRUE);
}
-BOOL ShowInstalledAppInfo(INT Index)
-{
- ATL::CStringW szText;
- ATL::CStringW szInfo;
- PINSTALLED_INFO Info = (PINSTALLED_INFO) ListViewGetlParam(Index);
-
- if (!Info || !Info->hSubKey) return FALSE;
-
- GetApplicationString(Info->hSubKey, L"DisplayName", szText);
- NewRichEditText(szText, CFE_BOLD);
- InsertRichEditText(L"\n", 0);
-
-#define GET_INFO(a, b, c, d) \
- if (GetApplicationString(Info->hSubKey, a, szInfo)) \
- { \
- szText.LoadStringW(b); \
- InsertRichEditText(szText, c); \
- InsertRichEditText(szInfo, d); \
- } \
-
- GET_INFO(L"DisplayVersion", IDS_INFO_VERSION, CFE_BOLD, 0);
- GET_INFO(L"Publisher", IDS_INFO_PUBLISHER, CFE_BOLD, 0);
- GET_INFO(L"RegOwner", IDS_INFO_REGOWNER, CFE_BOLD, 0);
- GET_INFO(L"ProductID", IDS_INFO_PRODUCTID, CFE_BOLD, 0);
- GET_INFO(L"HelpLink", IDS_INFO_HELPLINK, CFE_BOLD, CFM_LINK);
- GET_INFO(L"HelpTelephone", IDS_INFO_HELPPHONE, CFE_BOLD, 0);
- GET_INFO(L"Readme", IDS_INFO_README, CFE_BOLD, 0);
- GET_INFO(L"Contact", IDS_INFO_CONTACT, CFE_BOLD, 0);
- GET_INFO(L"URLUpdateInfo", IDS_INFO_UPDATEINFO, CFE_BOLD, CFM_LINK);
- GET_INFO(L"URLInfoAbout", IDS_INFO_INFOABOUT, CFE_BOLD, CFM_LINK);
- GET_INFO(L"Comments", IDS_INFO_COMMENTS, CFE_BOLD, 0);
- GET_INFO(L"InstallDate", IDS_INFO_INSTALLDATE, CFE_BOLD, 0);
- GET_INFO(L"InstallLocation", IDS_INFO_INSTLOCATION, CFE_BOLD, 0);
- GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
- GET_INFO(L"UninstallString", IDS_INFO_UNINSTALLSTR, CFE_BOLD, 0);
- GET_INFO(L"InstallSource", IDS_INFO_INSTALLSRC, CFE_BOLD, 0);
- GET_INFO(L"ModifyPath", IDS_INFO_MODIFYPATH, CFE_BOLD, 0);
-
- return TRUE;
-}
-
VOID RemoveAppFromRegistry(INT Index)
{
PINSTALLED_INFO Info;
diff --git a/base/applications/rapps/misc.cpp b/base/applications/rapps/misc.cpp
index cc1dc6541fa..cb18503cc13 100644
--- a/base/applications/rapps/misc.cpp
+++ b/base/applications/rapps/misc.cpp
@@ -72,20 +72,6 @@ VOID CopyTextToClipboard(LPCWSTR lpszText)
CloseClipboard();
}
-VOID SetWelcomeText()
-{
- ATL::CStringW szText;
-
- szText.LoadStringW(IDS_WELCOME_TITLE);
- NewRichEditText(szText, CFE_BOLD);
-
- szText.LoadStringW(IDS_WELCOME_TEXT);
- InsertRichEditText(szText, 0);
-
- szText.LoadStringW(IDS_WELCOME_URL);
- InsertRichEditText(szText, CFM_LINK);
-}
-
VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem)
{
HMENU hMenu = NULL;