Skip to content

Commit

Permalink
[WLANWIZ] Sort listbox drawing operations
Browse files Browse the repository at this point in the history
Doing the graphics first, then the text.
  • Loading branch information
SigmaTel71 committed Sep 30, 2024
1 parent e85d9fc commit a2eb980
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 136 deletions.
267 changes: 135 additions & 132 deletions dll/shellext/wlanwiz/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,58 +155,12 @@ LRESULT CWlanWizard::OnDrawItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
/* Draw listbox content, if the network list is not empty */
if (this->lstWlanNetworks && this->lstWlanNetworks->dwNumberOfItems > 0 && pdis->CtlID == IDC_WLANWIZ_LISTBOX)
{
/* Prepare SSID for drawing, color is determined by selection */
UINT uSSIDLength = static_cast<UINT>(SendDlgItemMessageW(pdis->CtlID, LB_GETTEXTLEN, pdis->itemID, NULL));
UINT uItemRealID = static_cast<UINT>(SendDlgItemMessageW(pdis->CtlID, LB_GETITEMDATA, pdis->itemID, NULL));

WLAN_AVAILABLE_NETWORK wlanNetwork = this->lstWlanNetworks->Network[uItemRealID];

cswWindowText.Empty();
cswWindowText.Preallocate(uSSIDLength);

SendDlgItemMessageW(pdis->CtlID, LB_GETTEXT, pdis->itemID, reinterpret_cast<LPARAM>(cswWindowText.GetBuffer()));
cswWindowText.ReleaseBuffer();

/* Get all related text lines */
#pragma region Authentication Standard
ATL::CStringW cswNetworkSecurityAlgo = L"";
ATL::CStringW cswNetworkSecurity = L"";

if (wlanNetwork.bSecurityEnabled)
{
switch (wlanNetwork.dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
cswNetworkSecurityAlgo = L" (WEP)";
break;
case DOT11_AUTH_ALGO_WPA:
case DOT11_AUTH_ALGO_WPA_PSK:
cswNetworkSecurityAlgo = L" (WPA)";
break;
case DOT11_AUTH_ALGO_RSNA:
case DOT11_AUTH_ALGO_RSNA_PSK: /* Possible as of NT 6.0 on ad hoc */
cswNetworkSecurityAlgo = L" (WPA2)";
break;
#ifndef __REACTOS__ /* uncomment when will be implemented */
case DOT11_AUTH_ALGO_WPA3:
case DOT11_AUTH_ALGO_WPA3_SAE:
case DOT11_AUTH_ALGO_WPA3_ENT:
cswNetworkSecurityAlgo = L" (WPA3)";
break;
#endif
default:
break;
}
}

if (wlanNetwork.dot11BssType == dot11_BSS_type_infrastructure)
cswNetworkSecurity.LoadStringW(wlanNetwork.bSecurityEnabled ? IDS_WLANWIZ_ENCRYPTED_AP : IDS_WLANWIZ_UNENCRYPTED_AP);
else if (wlanNetwork.dot11BssType == dot11_BSS_type_independent)
cswNetworkSecurity.LoadStringW(wlanNetwork.bSecurityEnabled ? IDS_WLANWIZ_ENCRYPTED_IBSS : IDS_WLANWIZ_UNENCRYPTED_IBSS);

cswNetworkSecurity += cswNetworkSecurityAlgo;
#pragma endregion
/* Step 1: draw listbox item's graphics, starting with the background */
if (!(pdis->itemState & ODS_SELECTED))
{
COLORREF cr3dFace = 0;
Expand Down Expand Up @@ -255,35 +209,157 @@ LRESULT CWlanWizard::OnDrawItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
DeleteObject(hbrSelectedBg);
}

/* SSID is drawn with bold font */
COLORREF crItemText = NULL;
/* Signal quality bar */
WLAN_SIGNAL_QUALITY ulSQ = wlanNetwork.wlanSignalQuality;
int iSQResIcon = IDI_WLANICON;

if (16 <= ulSQ && ulSQ < 36)
iSQResIcon = IDI_WLANICON_20;
else if (36 <= ulSQ && ulSQ < 56)
iSQResIcon = IDI_WLANICON_40;
else if (56 <= ulSQ && ulSQ < 76)
iSQResIcon = IDI_WLANICON_60;
else if (76 <= ulSQ && ulSQ < 96)
iSQResIcon = IDI_WLANICON_80;
else if (ulSQ >= 96)
iSQResIcon = IDI_WLANICON_100;

HICON hicnRes = LoadIconW(wlanwiz_hInstance, MAKEINTRESOURCEW(iSQResIcon));

DrawIconEx(pdis->hDC,
pdis->rcItem.right - 36, pdis->rcItem.top + 24,
hicnRes,
32, 32,
NULL,
NULL,
DI_NORMAL);

DestroyIcon(hicnRes);

/* Network type */
int iBSSIcon = IDI_BSS_INFRA;

if (wlanNetwork.dot11BssType == dot11_BSS_type_independent)
iBSSIcon = IDI_BSS_ADHOC;

hicnRes = static_cast<HICON>(LoadImageW(wlanwiz_hInstance, MAKEINTRESOURCEW(iBSSIcon), IMAGE_ICON, 48, 48, LR_LOADTRANSPARENT));

DrawIconEx(pdis->hDC,
pdis->rcItem.left + 2, pdis->rcItem.top + 3,
hicnRes,
48, 48,
NULL,
NULL,
DI_NORMAL);

DestroyIcon(hicnRes);

/* Authentication standard strength */
if (wlanNetwork.bSecurityEnabled)
{
HICON hicnSecurity = LoadIconW(GetModuleHandleW(L"shell32.dll"), MAKEINTRESOURCEW(48)); /* lock icon */

DrawIconEx(pdis->hDC,
52, pdis->rcItem.top + 36,
hicnSecurity,
16, 16,
NULL,
NULL,
DI_NORMAL);

/* WEP is not secure for decades */
if (wlanNetwork.dot11DefaultAuthAlgorithm < DOT11_AUTH_ALGO_WPA)
{
DrawIconEx(pdis->hDC,
54, pdis->rcItem.top + 37,
LoadIconW(wlanwiz_hInstance, MAKEINTRESOURCE(IDI_AP_DHCP_FAILED)),
16, 16,
NULL,
NULL,
DI_NORMAL);
}

DestroyIcon(hicnSecurity);
}

/* Step 2: fill the listbox item with text */
COLORREF crItemText = SetTextColor(pdis->hDC, GetSysColor(pdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));

/* SSID */
this->lfCaption.lfWeight = FW_BOLD;
this->lfCaption.lfUnderline = FALSE;

HFONT hfCaption = CreateFontIndirectW(&this->lfCaption);
HGDIOBJ hOld = SelectObject(pdis->hDC, hfCaption);

crItemText = SetTextColor(pdis->hDC, GetSysColor(pdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
TextOutW(pdis->hDC, 52, pdis->rcItem.top + 4, cswWindowText, cswWindowText.GetLength()); /* SSID */
cswWindowText = ATL::CStringW(L"", uSSIDLength);
SendDlgItemMessageW(pdis->CtlID, LB_GETTEXT, pdis->itemID, reinterpret_cast<LPARAM>(cswWindowText.GetBuffer()));

TextOutW(pdis->hDC, 52, pdis->rcItem.top + 4, cswWindowText, cswWindowText.GetLength());
this->lfCaption.lfWeight = FW_NORMAL;

SelectObject(pdis->hDC, hOld);
DeleteObject(hfCaption);


/* Authentication standard */
ATL::CStringW cswNetworkSecurityAlgo = L"";
ATL::CStringW cswNetworkSecurity = L"";

if (wlanNetwork.bSecurityEnabled)
{
switch (wlanNetwork.dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
cswNetworkSecurityAlgo = L" (WEP)";
break;
case DOT11_AUTH_ALGO_WPA:
case DOT11_AUTH_ALGO_WPA_PSK:
cswNetworkSecurityAlgo = L" (WPA)";
break;
case DOT11_AUTH_ALGO_RSNA:
case DOT11_AUTH_ALGO_RSNA_PSK: /* Possible as of NT 6.0 on ad hoc */
cswNetworkSecurityAlgo = L" (WPA2)";
break;
#ifndef __REACTOS__ /* uncomment when will be implemented */
case DOT11_AUTH_ALGO_WPA3:
case DOT11_AUTH_ALGO_WPA3_SAE:
case DOT11_AUTH_ALGO_WPA3_ENT:
cswNetworkSecurityAlgo = L" (WPA3)";
break;
#endif
default:
break;
}
}

if (wlanNetwork.dot11BssType == dot11_BSS_type_infrastructure)
cswNetworkSecurity.LoadStringW(wlanNetwork.bSecurityEnabled ? IDS_WLANWIZ_ENCRYPTED_AP : IDS_WLANWIZ_UNENCRYPTED_AP);
else if (wlanNetwork.dot11BssType == dot11_BSS_type_independent)
cswNetworkSecurity.LoadStringW(wlanNetwork.bSecurityEnabled ? IDS_WLANWIZ_ENCRYPTED_IBSS : IDS_WLANWIZ_UNENCRYPTED_IBSS);

cswNetworkSecurity += cswNetworkSecurityAlgo;

TextOutW(pdis->hDC,
wlanNetwork.bSecurityEnabled ? 72 : 52,
pdis->rcItem.top + 38,
cswNetworkSecurity, cswNetworkSecurity.GetLength());
wlanNetwork.bSecurityEnabled ? 72 : 52,
pdis->rcItem.top + 38,
cswNetworkSecurity, cswNetworkSecurity.GetLength());

/* Draw expanded text if the network is selected */

/* Expanded text */
if (pdis->itemState & ODS_SELECTED)
{
ATL::CStringW cswExpandedText = L"";
ATL::CStringW cswConnectButtonText = L"";

if (wlanNetwork.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
cswExpandedText.LoadStringW(IDS_WLANWIZ_CONNECTED);
{
cswConnectButtonText.LoadStringW(IDS_WLANWIZ_DISCONNECT);
cswExpandedText.LoadStringW(IDS_WLANWIZ_EXPAND_CONNECTED);
}
else
{
cswConnectButtonText.LoadStringW(IDS_WLANWIZ_CONNECT);
if (wlanNetwork.bSecurityEnabled)
{
wlanNetwork.dot11DefaultAuthAlgorithm < DOT11_AUTH_ALGO_WPA
Expand All @@ -303,84 +379,11 @@ LRESULT CWlanWizard::OnDrawItem(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& b
};

DrawTextW(pdis->hDC, cswExpandedText, cswExpandedText.GetLength(), &rcExpandedText, DT_WORDBREAK | DT_LEFT);
GetDlgItem(IDC_WLANWIZ_MAINBUTTON).SetWindowTextW(cswConnectButtonText);
}

SetTextColor(pdis->hDC, crItemText);

/* Choose signal level icon depending on signal strength */
UINT uRSSI = wlanNetwork.wlanSignalQuality;
int iRSSIResIcon = IDI_WLANICON;

if (16 <= uRSSI && uRSSI < 36)
iRSSIResIcon = IDI_WLANICON_20;
else if(36 <= uRSSI && uRSSI < 56)
iRSSIResIcon = IDI_WLANICON_40;
else if(56 <= uRSSI && uRSSI < 76)
iRSSIResIcon = IDI_WLANICON_60;
else if(76 <= uRSSI && uRSSI < 96)
iRSSIResIcon = IDI_WLANICON_80;
else if (uRSSI >= 96)
iRSSIResIcon = IDI_WLANICON_100;

HICON hicnRes = LoadIconW(wlanwiz_hInstance, MAKEINTRESOURCEW(iRSSIResIcon));

DrawIconEx(pdis->hDC,
pdis->rcItem.right - 36, pdis->rcItem.top + 24,
hicnRes,
32, 32,
NULL,
NULL,
DI_NORMAL);

DestroyIcon(hicnRes);

int iBSSIcon = 0;

wlanNetwork.dot11BssType == dot11_BSS_type_independent
? iBSSIcon = IDI_BSS_ADHOC
: iBSSIcon = IDI_BSS_INFRA;

/* LoadIconW refuses to load 48px icon properly */
hicnRes = static_cast<HICON>(LoadImageW(wlanwiz_hInstance, MAKEINTRESOURCEW(iBSSIcon), IMAGE_ICON, 48, 48, LR_LOADTRANSPARENT));

DrawIconEx(pdis->hDC,
pdis->rcItem.left + 2, pdis->rcItem.top + 3,
hicnRes,
48, 48,
NULL,
NULL,
DI_NORMAL);

DestroyIcon(hicnRes);

/* Draw security indicator */
if (wlanNetwork.bSecurityEnabled)
{
HICON hicnSecurity = LoadIconW(GetModuleHandleW(L"shell32.dll"), MAKEINTRESOURCEW(48)); /* lock icon */

DrawIconEx(pdis->hDC,
52, pdis->rcItem.top + 36,
hicnSecurity,
16, 16,
NULL,
NULL,
DI_NORMAL);

/* WEP is not secure for decades */
if (wlanNetwork.dot11DefaultAuthAlgorithm < DOT11_AUTH_ALGO_WPA)
{
DrawIconEx(pdis->hDC,
54, pdis->rcItem.top + 37,
LoadIconW(wlanwiz_hInstance, MAKEINTRESOURCE(IDI_AP_DHCP_FAILED)),
16, 16,
NULL,
NULL,
DI_NORMAL);
}

DestroyIcon(hicnSecurity);
}


/* Shrink focus rectangle for listbox items */
pdis->rcItem.left += 1;
pdis->rcItem.top += 1;
Expand Down
9 changes: 5 additions & 4 deletions dll/shellext/wlanwiz/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ LRESULT CWlanWizard::OnScanNetworks(WORD wNotifyCode, WORD wID, HWND hWndCtl, BO
while (posIAQ != NULL)
{
auto csaIAQ = calIndexToSignalQuality.GetNext(posIAQ);
DOT11_SSID ssid = this->lstWlanNetworks->Network[csaIAQ[1]].dot11Ssid;

ATL::CStringW cswWlanNetworkName = "";
cswWlanNetworkName = CA2W(reinterpret_cast<LPCSTR>(this->lstWlanNetworks->Network[csaIAQ[1]].dot11Ssid.ucSSID));
int iSSIDLengthWide = MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(ssid.ucSSID), ssid.uSSIDLength, NULL, 0);
ATL::CStringW cswWlanNetworkName = ATL::CStringW(L"", iSSIDLengthWide);

MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<LPCSTR>(ssid.ucSSID), ssid.uSSIDLength, cswWlanNetworkName.GetBuffer(), iSSIDLengthWide);

if (cswWlanNetworkName.IsEmpty())
cswWlanNetworkName.LoadStringW(IDS_WLANWIZ_HIDDEN_NETWORK);
else
cswWlanNetworkName = cswWlanNetworkName.Left(DOT11_SSID_MAX_LENGTH);

LRESULT iItemIdx = m_ListboxWLAN.SendMessageW(LB_ADDSTRING,
NULL,
Expand Down

0 comments on commit a2eb980

Please sign in to comment.