Browse Source

Keyboard support for GUI

pull/51/head
Valentin Radu 4 years ago
parent
commit
a94c0347a7
  1. 102
      ExplorerPatcher/GUI.c
  2. 3
      ExplorerPatcher/GUI.h

102
ExplorerPatcher/GUI.c

@ -113,6 +113,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
DWORD dwTextFlags = DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; DWORD dwTextFlags = DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS;
RECT rcText; RECT rcText;
DWORD dwCL = 0; DWORD dwCL = 0;
BOOL bTabOrderHit = FALSE;
HDC hdcPaint = NULL; HDC hdcPaint = NULL;
BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) }; BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
@ -126,7 +127,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
wchar_t* text = malloc(MAX_LINE_LENGTH * sizeof(wchar_t)); wchar_t* text = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
wchar_t* name = malloc(MAX_LINE_LENGTH * sizeof(wchar_t)); wchar_t* name = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
wchar_t* section = malloc(MAX_LINE_LENGTH * sizeof(wchar_t)); wchar_t* section = malloc(MAX_LINE_LENGTH * sizeof(wchar_t));
size_t bufsiz = 0, numChRd = 0; size_t bufsiz = 0, numChRd = 0, tabOrder = 1;
while ((numChRd = getline(&line, &bufsiz, f)) != -1) while ((numChRd = getline(&line, &bufsiz, f)) != -1)
{ {
if (strcmp(line, "Windows Registry Editor Version 5.00\r\n") && strcmp(line, "\r\n")) if (strcmp(line, "Windows Registry Editor Version 5.00\r\n") && strcmp(line, "\r\n"))
@ -213,6 +214,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
} }
if (hDC) if (hDC)
{ {
if (!strncmp(line, ";u ", 3) && tabOrder == _this->tabOrder)
{
bTabOrderHit = TRUE;
DttOpts.crText = GUI_TEXTCOLOR_SELECTED;
}
DrawThemeTextEx( DrawThemeTextEx(
_this->hTheme, _this->hTheme,
hdcPaint, hdcPaint,
@ -224,6 +230,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
&rcText, &rcText,
&DttOpts &DttOpts
); );
if (!strncmp(line, ";u ", 3) && tabOrder == _this->tabOrder)
{
DttOpts.crText = GUI_TEXTCOLOR;
}
} }
else else
{ {
@ -237,7 +247,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
DT_CALCRECT DT_CALCRECT
); );
rcTemp.bottom = rcText.bottom; rcTemp.bottom = rcText.bottom;
if (!strncmp(line, ";u ", 3) && PtInRect(&rcTemp, pt)) if (!strncmp(line, ";u ", 3) && (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder)))
{ {
numChRd = getline(&line, &bufsiz, f); numChRd = getline(&line, &bufsiz, f);
char* p = strchr(line, '\r'); char* p = strchr(line, '\r');
@ -414,6 +424,10 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
} }
} }
dwCL += dwLineHeight * dy; dwCL += dwLineHeight * dy;
if (!strncmp(line, ";u ", 3))
{
tabOrder++;
}
} }
else if (!strncmp(line, ";l ", 3) || !strncmp(line, ";c ", 3) || !strncmp(line, ";b ", 3) || !strncmp(line, ";i ", 3) || !strncmp(line, ";d ", 3) || !strncmp(line, ";v ", 3)) else if (!strncmp(line, ";l ", 3) || !strncmp(line, ";c ", 3) || !strncmp(line, ";b ", 3) || !strncmp(line, ";i ", 3) || !strncmp(line, ";d ", 3) || !strncmp(line, ";v ", 3))
{ {
@ -609,7 +623,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
DT_CALCRECT DT_CALCRECT
); );
rcTemp.bottom = rcText.bottom; rcTemp.bottom = rcText.bottom;
if (!hDC && PtInRect(&rcTemp, pt)) if (!hDC && (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder)))
{ {
if (bJustCheck) if (bJustCheck)
{ {
@ -723,7 +737,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
); );
rcTemp.bottom = rcText.bottom; rcTemp.bottom = rcText.bottom;
//printf("%d %d %d %d %d %d %d %d\n", rcText.left, rcText.top, rcText.right, rcText.bottom, rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom); //printf("%d %d %d %d %d %d %d %d\n", rcText.left, rcText.top, rcText.right, rcText.bottom, rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom);
if (PtInRect(&rcTemp, pt)) if (PtInRect(&rcTemp, pt) || (pt.x == 0 && pt.y == 0 && tabOrder == _this->tabOrder))
{ {
numChRd = getline(&line, &bufsiz, f); numChRd = getline(&line, &bufsiz, f);
char* p = strchr(line, '\r'); char* p = strchr(line, '\r');
@ -742,6 +756,11 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
} }
if (hDC) if (hDC)
{ {
if (tabOrder == _this->tabOrder)
{
bTabOrderHit = TRUE;
DttOpts.crText = GUI_TEXTCOLOR_SELECTED;
}
DrawThemeTextEx( DrawThemeTextEx(
_this->hTheme, _this->hTheme,
hdcPaint, hdcPaint,
@ -753,8 +772,13 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
&rcText, &rcText,
&DttOpts &DttOpts
); );
if (tabOrder == _this->tabOrder)
{
DttOpts.crText = GUI_TEXTCOLOR;
}
} }
dwCL += dwLineHeight * dy; dwCL += dwLineHeight * dy;
tabOrder++;
} }
} }
} }
@ -767,6 +791,14 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
DeleteObject(hFontTitle); DeleteObject(hFontTitle);
DeleteObject(hFontUnderline); DeleteObject(hFontUnderline);
DeleteObject(hFontCaption); DeleteObject(hFontCaption);
if (_this->tabOrder == GUI_MAX_TABORDER)
{
_this->tabOrder = tabOrder;
}
else if (!bTabOrderHit)
{
_this->tabOrder = 0;
}
} }
EndBufferedPaint(hBufferedPaint, TRUE); EndBufferedPaint(hBufferedPaint, TRUE);
} }
@ -825,6 +857,39 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
PostQuitMessage(0); PostQuitMessage(0);
return 0; return 0;
} }
else if (uMsg == WM_KEYDOWN)
{
if (wParam == VK_ESCAPE)
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
return 0;
}
else if (wParam == VK_TAB)
{
if (GetKeyState(VK_SHIFT) & 0x8000)
{
_this->tabOrder--;
if (_this->tabOrder == 0)
{
_this->tabOrder = GUI_MAX_TABORDER;
}
}
else
{
_this->tabOrder++;
}
InvalidateRect(hWnd, NULL, FALSE);
return 0;
}
else if (wParam == VK_SPACE)
{
POINT pt;
pt.x = 0;
pt.y = 0;
GUI_Build(0, hWnd, pt);
return 0;
}
}
else if (uMsg == WM_NCHITTEST) else if (uMsg == WM_NCHITTEST)
{ {
POINT pt; POINT pt;
@ -883,7 +948,31 @@ static LRESULT CALLBACK GUI_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
__declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow) __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow)
{ {
/* HKEY hKey;
DWORD dwDisposition;
DWORD dwSize = sizeof(DWORD);
RegCreateKeyExW(
HKEY_CURRENT_USER,
TEXT(REGPATH),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ,
NULL,
&hKey,
&dwDisposition
);
DWORD bAllocConsole = FALSE;
RegQueryValueExW(
hKey,
TEXT("AllocConsole"),
0,
NULL,
&bAllocConsole,
&dwSize
);
if (bAllocConsole)
{
FILE* conout; FILE* conout;
AllocConsole(); AllocConsole();
freopen_s( freopen_s(
@ -892,7 +981,7 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
"w", "w",
stdout stdout
); );
*/ }
printf("Started \"GUI\" thread.\n"); printf("Started \"GUI\" thread.\n");
@ -909,6 +998,7 @@ __declspec(dllexport) int ZZGUI(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLin
_this.padding.top = GUI_PADDING_TOP; _this.padding.top = GUI_PADDING_TOP;
_this.padding.bottom = GUI_PADDING_BOTTOM; _this.padding.bottom = GUI_PADDING_BOTTOM;
_this.hTheme = OpenThemeData(NULL, TEXT(GUI_WINDOWSWITCHER_THEME_CLASS)); _this.hTheme = OpenThemeData(NULL, TEXT(GUI_WINDOWSWITCHER_THEME_CLASS));
_this.tabOrder = 0;
WNDCLASS wc = { 0 }; WNDCLASS wc = { 0 };
ZeroMemory(&wc, sizeof(WNDCLASSW)); ZeroMemory(&wc, sizeof(WNDCLASSW));

3
ExplorerPatcher/GUI.h

@ -35,6 +35,8 @@ extern HMODULE hModule;
#define GUI_LINE_HEIGHT 26 #define GUI_LINE_HEIGHT 26
#define GUI_CAPTION_LINE_HEIGHT 42 #define GUI_CAPTION_LINE_HEIGHT 42
#define GUI_TEXTCOLOR RGB(0, 0, 0) #define GUI_TEXTCOLOR RGB(0, 0, 0)
#define GUI_TEXTCOLOR_SELECTED RGB(255, 0, 0)
#define GUI_MAX_TABORDER 9999
#define GUI_PADDING 5 #define GUI_PADDING 5
#define GUI_PADDING_LEFT GUI_PADDING * 3 #define GUI_PADDING_LEFT GUI_PADDING * 3
#define GUI_PADDING_RIGHT GUI_PADDING * 3 #define GUI_PADDING_RIGHT GUI_PADDING * 3
@ -49,6 +51,7 @@ typedef struct _GUI
HTHEME hTheme; HTHEME hTheme;
POINT dpi; POINT dpi;
MARGINS extent; MARGINS extent;
UINT tabOrder;
} GUI; } GUI;
static HRESULT GUI_AboutProc( static HRESULT GUI_AboutProc(

Loading…
Cancel
Save