Skip to content

Commit

Permalink
Settings for toolbar and status text
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jul 26, 2022
1 parent 7038c04 commit f2b4cd6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 52 deletions.
104 changes: 58 additions & 46 deletions src/ItemWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ void ItemWindow::move(int x, int y) {
RECT ItemWindow::windowBody() {
RECT clientRect;
GetClientRect(hwnd, &clientRect);
return useCustomFrame() ?
RECT {0, CAPTION_HEIGHT + TOOLBAR_HEIGHT, clientRect.right, clientRect.bottom} : clientRect;
if (!useCustomFrame())
return clientRect;
int top = (statusText || toolbar) ? (CAPTION_HEIGHT + TOOLBAR_HEIGHT) : CAPTION_HEIGHT;
return RECT {0, top, clientRect.right, clientRect.bottom};
}

LRESULT ItemWindow::handleMessage(UINT message, WPARAM wParam, LPARAM lParam) {
Expand Down Expand Up @@ -509,49 +511,53 @@ void ItemWindow::onCreate() {
if (captionFont)
SendMessage(renameBox, WM_SETFONT, (WPARAM)captionFont, FALSE);

statusText = CreateWindow(L"STATIC", nullptr,
WS_VISIBLE | WS_CHILD | SS_WORDELLIPSIS | SS_LEFT | SS_CENTERIMAGE | SS_NOPREFIX
| SS_NOTIFY, // allows tooltips to work
STATUS_TEXT_MARGIN, CAPTION_HEIGHT, 0, TOOLBAR_HEIGHT,
hwnd, nullptr, instance, nullptr);
if (statusFont)
SendMessage(statusText, WM_SETFONT, (WPARAM)statusFont, FALSE);
if (useDefaultStatusText()) {
statusTextThread.Attach(new StatusTextThread(item, hwnd));
statusTextThread->start();
if (settings::getStatusTextEnabled()) {
statusText = CreateWindow(L"STATIC", nullptr,
WS_VISIBLE | WS_CHILD | SS_WORDELLIPSIS | SS_LEFT | SS_CENTERIMAGE | SS_NOPREFIX
| SS_NOTIFY, // allows tooltips to work
STATUS_TEXT_MARGIN, CAPTION_HEIGHT, 0, TOOLBAR_HEIGHT,
hwnd, nullptr, instance, nullptr);
if (statusFont)
SendMessage(statusText, WM_SETFONT, (WPARAM)statusFont, FALSE);
if (useDefaultStatusText()) {
statusTextThread.Attach(new StatusTextThread(item, hwnd));
statusTextThread->start();
}

statusTooltip = CreateWindow(TOOLTIPS_CLASS, nullptr,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, nullptr, instance, nullptr);
if (statusFont)
SendMessage(statusTooltip, WM_SETFONT, (WPARAM)statusFont, FALSE);
SendMessage(statusTooltip, TTM_SETMAXTIPWIDTH, 0, 0x7fff); // allow tabs
toolInfo = {sizeof(toolInfo)};
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT;
toolInfo.hwnd = hwnd;
toolInfo.uId = (UINT_PTR)statusText;
toolInfo.lpszText = L"";
SendMessage(statusTooltip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
}

statusTooltip = CreateWindow(TOOLTIPS_CLASS, nullptr,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, nullptr, instance, nullptr);
if (statusFont)
SendMessage(statusTooltip, WM_SETFONT, (WPARAM)statusFont, FALSE);
SendMessage(statusTooltip, TTM_SETMAXTIPWIDTH, 0, 0x7fff); // allow tabs
toolInfo = {sizeof(toolInfo)};
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT;
toolInfo.hwnd = hwnd;
toolInfo.uId = (UINT_PTR)statusText;
toolInfo.lpszText = L"";
SendMessage(statusTooltip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);

toolbar = CreateWindowEx(
TBSTYLE_EX_MIXEDBUTTONS, TOOLBARCLASSNAME, nullptr,
TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER
| WS_VISIBLE | WS_CHILD,
0, CAPTION_HEIGHT, 0, TOOLBAR_HEIGHT,
hwnd, nullptr, instance, nullptr);
SendMessage(toolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(toolbar, TB_SETBUTTONWIDTH, 0, MAKELPARAM(TOOLBAR_HEIGHT, TOOLBAR_HEIGHT));
SendMessage(toolbar, TB_SETBITMAPSIZE, 0, 0);
if (symbolFont)
SendMessage(toolbar, WM_SETFONT, (WPARAM)symbolFont, FALSE);
addToolbarButtons(toolbar);
SendMessage(toolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(TOOLBAR_HEIGHT, TOOLBAR_HEIGHT));
SIZE ideal;
SendMessage(toolbar, TB_GETIDEALSIZE, FALSE, (LPARAM)&ideal);
SetWindowPos(toolbar, nullptr, 0, 0, ideal.cx, TOOLBAR_HEIGHT,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
if (settings::getToolbarEnabled()) {
toolbar = CreateWindowEx(
TBSTYLE_EX_MIXEDBUTTONS, TOOLBARCLASSNAME, nullptr,
TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER
| WS_VISIBLE | WS_CHILD,
0, CAPTION_HEIGHT, 0, TOOLBAR_HEIGHT,
hwnd, nullptr, instance, nullptr);
SendMessage(toolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(toolbar, TB_SETBUTTONWIDTH, 0, MAKELPARAM(TOOLBAR_HEIGHT, TOOLBAR_HEIGHT));
SendMessage(toolbar, TB_SETBITMAPSIZE, 0, 0);
if (symbolFont)
SendMessage(toolbar, WM_SETFONT, (WPARAM)symbolFont, FALSE);
addToolbarButtons(toolbar);
SendMessage(toolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(TOOLBAR_HEIGHT, TOOLBAR_HEIGHT));
SIZE ideal;
SendMessage(toolbar, TB_GETIDEALSIZE, FALSE, (LPARAM)&ideal);
SetWindowPos(toolbar, nullptr, 0, 0, ideal.cx, TOOLBAR_HEIGHT,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
}
}

bool ItemWindow::hasStatusText() {
Expand Down Expand Up @@ -733,15 +739,21 @@ void ItemWindow::onActivate(WORD state, HWND) {

void ItemWindow::onSize(int width, int) {
windowRectChanged();
if (useCustomFrame()) {

int toolbarLeft = width;
if (toolbar) {
RECT toolbarRect;
GetClientRect(toolbar, &toolbarRect);
SetWindowPos(toolbar, nullptr, width - rectWidth(toolbarRect), CAPTION_HEIGHT, 0, 0,
toolbarLeft = width - rectWidth(toolbarRect);
SetWindowPos(toolbar, nullptr, toolbarLeft, CAPTION_HEIGHT, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
if (statusText) {
SetWindowPos(statusText, nullptr,
0, 0, width - rectWidth(toolbarRect) - STATUS_TEXT_MARGIN, TOOLBAR_HEIGHT,
0, 0, toolbarLeft - STATUS_TEXT_MARGIN * 2, TOOLBAR_HEIGHT,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
}

if (parent && preserveSize()) {
RECT rect;
GetWindowRect(hwnd, &rect);
Expand Down
24 changes: 24 additions & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const wchar_t VAL_ITEM_WINDOW_W[] = L"ItemWindowWidth";
const wchar_t VAL_ITEM_WINDOW_H[] = L"ItemWindowHeight";
const wchar_t VAL_FOLDER_WINDOW_W[] = L"FolderWindowWidth";
const wchar_t VAL_FOLDER_WINDOW_H[] = L"FolderWindowHeight";
const wchar_t VAL_STATUS_TEXT_ENABLED[] = L"StatusTextEnabled";
const wchar_t VAL_TOOLBAR_ENABLED[] = L"ToolbarEnabled";
const wchar_t VAL_PREVIEWS_ENABLED[] = L"PreviewsEnabled";
const wchar_t VAL_TEXT_EDITOR_ENABLED[] = L"TextEditorEnabled";
const wchar_t VAL_TRAY_FOLDER[] = L"TrayFolder";
Expand Down Expand Up @@ -84,6 +86,28 @@ void setFolderWindowSize(SIZE value) {
setSettingsValue(VAL_FOLDER_WINDOW_H, REG_DWORD, &value.cy, sizeof(value.cy));
}

bool getStatusTextEnabled() {
DWORD value = DEFAULT_STATUS_TEXT_ENABLED;
getSettingsValue(VAL_STATUS_TEXT_ENABLED, RRF_RT_DWORD, &value, sizeof(value));
return value;
}

void setStatusTextEnabled(bool value) {
DWORD dwValue = value;
setSettingsValue(VAL_STATUS_TEXT_ENABLED, REG_DWORD, &dwValue, sizeof(dwValue));
}

bool getToolbarEnabled() {
DWORD value = DEFAULT_TOOLBAR_ENABLED;
getSettingsValue(VAL_TOOLBAR_ENABLED, RRF_RT_DWORD, &value, sizeof(value));
return value;
}

void setToolbarEnabled(bool value) {
DWORD dwValue = value;
setSettingsValue(VAL_TOOLBAR_ENABLED, REG_DWORD, &dwValue, sizeof(dwValue));
}

bool getPreviewsEnabled() {
DWORD value = DEFAULT_PREVIEWS_ENABLED;
getSettingsValue(VAL_PREVIEWS_ENABLED, RRF_RT_DWORD, &value, sizeof(value));
Expand Down
7 changes: 7 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum TrayDirection : DWORD { TRAY_UP, TRAY_DOWN, TRAY_RIGHT };
const wchar_t DEFAULT_STARTING_FOLDER[] = L"shell:Desktop";
const SIZE DEFAULT_ITEM_WINDOW_SIZE = {450, 450};
const SIZE DEFAULT_FOLDER_WINDOW_SIZE = {231, 450}; // just wide enough for scrollbar tooltips
const bool DEFAULT_STATUS_TEXT_ENABLED = true;
const bool DEFAULT_TOOLBAR_ENABLED = true;
const bool DEFAULT_PREVIEWS_ENABLED = true;
const bool DEFAULT_TEXT_EDITOR_ENABLED = false;
const wchar_t DEFAULT_TRAY_FOLDER[] = L"shell:Links";
Expand All @@ -29,6 +31,11 @@ void setItemWindowSize(SIZE value);
SIZE getFolderWindowSize();
void setFolderWindowSize(SIZE value);

bool getStatusTextEnabled();
void setStatusTextEnabled(bool value);
bool getToolbarEnabled();
void setToolbarEnabled(bool value);

bool getPreviewsEnabled();
void setPreviewsEnabled(bool value);

Expand Down
8 changes: 8 additions & 0 deletions src/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ INT_PTR generalProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
SIZE itemWindowSize = settings::getItemWindowSize();
SetDlgItemInt(hwnd, IDC_ITEM_WINDOW_WIDTH, itemWindowSize.cx, TRUE);
SetDlgItemInt(hwnd, IDC_ITEM_WINDOW_HEIGHT, itemWindowSize.cy, TRUE);
CheckDlgButton(hwnd, IDC_STATUS_TEXT_ENABLED,
settings::getStatusTextEnabled() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_TOOLBAR_ENABLED,
settings::getToolbarEnabled() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_PREVIEWS_ENABLED,
settings::getPreviewsEnabled() ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd, IDC_TEXT_EDITOR_ENABLED,
Expand Down Expand Up @@ -83,6 +87,8 @@ INT_PTR generalProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (success)
settings::setItemWindowSize(size);
}
settings::setStatusTextEnabled(!!IsDlgButtonChecked(hwnd, IDC_STATUS_TEXT_ENABLED));
settings::setToolbarEnabled(!!IsDlgButtonChecked(hwnd, IDC_TOOLBAR_ENABLED));
settings::setPreviewsEnabled(!!IsDlgButtonChecked(hwnd, IDC_PREVIEWS_ENABLED));
settings::setTextEditorEnabled(!!IsDlgButtonChecked(hwnd, IDC_TEXT_EDITOR_ENABLED));
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, PSNRET_NOERROR);
Expand Down Expand Up @@ -110,6 +116,8 @@ INT_PTR generalProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
} else if (HIWORD(wParam) == EN_CHANGE
|| LOWORD(wParam) == IDC_START_FOLDER_PATH && HIWORD(wParam) == CBN_EDITCHANGE
|| LOWORD(wParam) == IDC_START_FOLDER_PATH && HIWORD(wParam) == CBN_SELCHANGE
|| LOWORD(wParam) == IDC_STATUS_TEXT_ENABLED && HIWORD(wParam) == BN_CLICKED
|| LOWORD(wParam) == IDC_TOOLBAR_ENABLED && HIWORD(wParam) == BN_CLICKED
|| LOWORD(wParam) == IDC_PREVIEWS_ENABLED && HIWORD(wParam) == BN_CLICKED
|| LOWORD(wParam) == IDC_TEXT_EDITOR_ENABLED && HIWORD(wParam) == BN_CLICKED) {
PropSheet_Changed(GetParent(hwnd), hwnd);
Expand Down
8 changes: 5 additions & 3 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
#define IDC_FOLDER_WINDOW_HEIGHT 1004
#define IDC_ITEM_WINDOW_WIDTH 1005
#define IDC_ITEM_WINDOW_HEIGHT 1006
#define IDC_PREVIEWS_ENABLED 1007
#define IDC_TEXT_EDITOR_ENABLED 1008
#define IDC_EXPLORER_SETTINGS 1009
#define IDC_STATUS_TEXT_ENABLED 1007
#define IDC_TOOLBAR_ENABLED 1008
#define IDC_PREVIEWS_ENABLED 1009
#define IDC_TEXT_EDITOR_ENABLED 1010
#define IDC_EXPLORER_SETTINGS 1011

#define IDD_SETTINGS_TRAY 105
#define IDC_OPEN_TRAY_ON_STARTUP 1001
Expand Down
9 changes: 6 additions & 3 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ IDD_SETTINGS_GENERAL DIALOGEX
EDITTEXT IDC_ITEM_WINDOW_WIDTH, 91, 77, 21, 14, ES_NUMBER
CTEXT "x", -1, 113, 80, 12, 8
EDITTEXT IDC_ITEM_WINDOW_HEIGHT, 126, 77, 21, 14, ES_NUMBER
GROUPBOX "Previews", -1, 7, 105, 213, 49
AUTOCHECKBOX "Use Preview &Handlers", IDC_PREVIEWS_ENABLED, 21, 119, 98, 14
AUTOCHECKBOX "Enable &text editor", IDC_TEXT_EDITOR_ENABLED, 21, 133, 98, 14
GROUPBOX "Toolbar", -1, 7, 105, 103, 49
AUTOCHECKBOX "Show i&nfo text", IDC_STATUS_TEXT_ENABLED, 14, 119, 89, 14
AUTOCHECKBOX "Show &toolbar", IDC_TOOLBAR_ENABLED, 14, 133, 89, 14
GROUPBOX "Previews", -1, 117, 105, 103, 49
AUTOCHECKBOX "Use Preview &Handlers", IDC_PREVIEWS_ENABLED, 124, 119, 89, 14
AUTOCHECKBOX "Enable text &editor", IDC_TEXT_EDITOR_ENABLED, 124, 133, 89, 14
GROUPBOX "File Explorer options", -1, 7, 161, 213, 35
LTEXT "Some File Explorer options also affect chromabrowse folder windows.", -1, 14, 175, 136, 16
PUSHBUTTON "&Options...", IDC_EXPLORER_SETTINGS, 157, 175, 56, 14
Expand Down

0 comments on commit f2b4cd6

Please sign in to comment.