Skip to content

Commit

Permalink
Merge pull request #689 from reupen/dark-mode-buttons-opts-pt-1
Browse files Browse the repository at this point in the history
Rework buttons options dialogue box layout
  • Loading branch information
reupen authored Apr 3, 2023
2 parents 46f0b34 + eb80a0b commit a29fa07
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 311 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
[#682](https://github.com/reupen/columns_ui/pull/682),
[#683](https://github.com/reupen/columns_ui/pull/683),
[#685](https://github.com/reupen/columns_ui/pull/685),
[#686](https://github.com/reupen/columns_ui/pull/686)]
[#686](https://github.com/reupen/columns_ui/pull/686),
[#688](https://github.com/reupen/columns_ui/pull/688) (contributed by
[@marc2k3](https://github.com/marc2k3)),
[#689](https://github.com/reupen/columns_ui/pull/689)]

- Dark menus were enabled on Windows 11 build 22624.
[[#680](https://github.com/reupen/columns_ui/pull/680), contributed by
Expand Down
102 changes: 2 additions & 100 deletions foo_ui_columns/buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ void ButtonsToolbar::import_config(stream_reader* p_reader, size_t p_size, abort
{
ConfigParam param;
param.m_selection = nullptr;
param.m_child = nullptr;
param.m_active = 0;
param.m_image = nullptr;
param.m_text_below = m_text_below;
param.m_appearance = m_appearance;
param.m_icon_size = m_icon_size;
Expand All @@ -50,9 +48,7 @@ void ButtonsToolbar::export_config(stream_writer* p_writer, abort_callback& p_ab
ConfigParam param;
param.m_selection = nullptr;
param.m_buttons = m_buttons;
param.m_child = nullptr;
param.m_active = 0;
param.m_image = nullptr;
param.m_text_below = m_text_below;
param.m_appearance = m_appearance;
param.m_icon_size = m_icon_size;
Expand Down Expand Up @@ -627,114 +623,20 @@ void ButtonsToolbar::set_config(stream_reader* p_reader, size_t p_size, abort_ca
}
}

INT_PTR CALLBACK ButtonsToolbar::ConfigChildProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_INITDIALOG:
SetWindowLongPtr(wnd, DWLP_USER, lp);
SHAutoComplete(GetDlgItem(wnd, IDC_IMAGE_PATH), SHACF_FILESYSTEM);
return TRUE;
case MSG_COMMAND_CHANGE: {
auto* ptr = reinterpret_cast<ConfigParam*>(GetWindowLongPtr(wnd, DWLP_USER));
if (ptr->m_selection) {
bool& b_custom = (ptr->m_active ? ptr->m_selection->m_use_custom_hot : ptr->m_selection->m_use_custom);
bool b_enable = ptr->m_selection && ptr->m_selection->m_type != TYPE_SEPARATOR;
EnableWindow(GetDlgItem(wnd, IDC_USE_CUSTOM_ICON), b_enable);
EnableWindow(GetDlgItem(wnd, IDC_IMAGE_PATH), b_enable && b_custom);
EnableWindow(GetDlgItem(wnd, IDC_BROWSE), b_enable && b_custom);
}
} break;
case MSG_BUTTON_CHANGE: {
auto* ptr = reinterpret_cast<ConfigParam*>(GetWindowLongPtr(wnd, DWLP_USER));
bool b_custom = ptr->m_selection
? (ptr->m_active ? ptr->m_selection->m_use_custom_hot : ptr->m_selection->m_use_custom)
: false;

Button_SetCheck(GetDlgItem(wnd, IDC_USE_CUSTOM_ICON), b_custom ? BST_CHECKED : BST_UNCHECKED);
uSendDlgItemMessageText(
wnd, IDC_IMAGE_PATH, WM_SETTEXT, 0, (ptr->m_selection && b_custom) ? ptr->m_image->m_path.get_ptr() : "");
bool b_enable = ptr->m_selection && ptr->m_selection->m_type != TYPE_SEPARATOR;
EnableWindow(GetDlgItem(wnd, IDC_USE_CUSTOM_ICON), b_enable);
EnableWindow(GetDlgItem(wnd, IDC_IMAGE_PATH), b_enable && b_custom);
EnableWindow(GetDlgItem(wnd, IDC_BROWSE), b_enable && b_custom);
} break;
case WM_COMMAND:
switch (wp) {
case IDC_USE_CUSTOM_ICON: {
auto* ptr = reinterpret_cast<ConfigParam*>(GetWindowLongPtr(wnd, DWLP_USER));
if (ptr->m_selection && ptr->m_image) {
bool& b_custom = (ptr->m_active ? ptr->m_selection->m_use_custom_hot : ptr->m_selection->m_use_custom);
b_custom = Button_GetCheck(reinterpret_cast<HWND>(lp)) == BST_CHECKED;
EnableWindow(GetDlgItem(wnd, IDC_IMAGE_PATH), b_custom);
EnableWindow(GetDlgItem(wnd, IDC_BROWSE), b_custom);
uSendDlgItemMessageText(wnd, IDC_IMAGE_PATH, WM_SETTEXT, 0,
(ptr->m_selection && b_custom) ? ptr->m_image->m_path.get_ptr() : "");
}
break;
}
case (EN_CHANGE << 16) | IDC_IMAGE_PATH: {
auto* ptr = reinterpret_cast<ConfigParam*>(GetWindowLongPtr(wnd, DWLP_USER));
if (ptr->m_image) {
ptr->m_image->m_path = uGetWindowText((HWND)lp);
}
break;
}
case IDC_BROWSE: {
auto* ptr = reinterpret_cast<ConfigParam*>(GetWindowLongPtr(wnd, DWLP_USER));
bool b_custom = ptr->m_selection
? (ptr->m_active ? ptr->m_selection->m_use_custom_hot : ptr->m_selection->m_use_custom)
: false;
if (ptr->m_image && b_custom) {
pfc::string8 temp;
if (!uGetFullPathName(ptr->m_selection->m_custom_image.m_path, temp)
|| (uGetFileAttributes(temp) & FILE_ATTRIBUTE_DIRECTORY))
temp.reset();

std::vector extensions = {"*.bmp"s, "*.gif"s, "*.ico"s, "*.png"s, "*.tiff"s, "*.webp"s};

if (svg::is_available()) {
extensions.emplace_back("*.svg"s);
std::ranges::sort(extensions);
}

const auto joined_extensions = mmh::join(extensions, ";");

const auto extension_mask = fmt::format("Image Files ({extensions})|{extensions}|All Files (*.*)|*.*",
fmt::arg("extensions", joined_extensions.c_str()));

if (uGetOpenFileName(wnd, extension_mask.c_str(), 0, "png", "Choose image", nullptr, temp, FALSE)) {
ptr->m_image->m_path = temp;
uSendDlgItemMessageText(
wnd, IDC_IMAGE_PATH, WM_SETTEXT, 0, (true) ? ptr->m_image->m_path.get_ptr() : "");
}
}
break;
}
default:
return FALSE;
}
default:
return FALSE;
}
return FALSE;
}

bool ButtonsToolbar::show_config_popup(HWND wnd_parent)
{
ConfigParam param;
param.m_selection = nullptr;
param.m_buttons = m_buttons;
param.m_child = nullptr;
param.m_active = 0;
param.m_image = nullptr;
param.m_text_below = m_text_below;
param.m_appearance = m_appearance;
param.m_icon_size = m_icon_size;
param.m_width = m_width;
param.m_height = m_height;

const auto dialog_result = DialogBoxParam(mmh::get_current_instance(), MAKEINTRESOURCE(IDD_BUTTONS_OPTIONS),
wnd_parent, ConfigParam::g_ConfigPopupProc, reinterpret_cast<LPARAM>(&param));
const auto dialog_result = uih::modal_dialog_box(IDD_BUTTONS_OPTIONS, wnd_parent,
[&param](auto&&... args) { return param.on_dialog_message(std::forward<decltype(args)>(args)...); });

if (dialog_result > 0) {
configure(
Expand Down
10 changes: 4 additions & 6 deletions foo_ui_columns/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ class ButtonsToolbar : public uie::container_uie_window_v3 {
void export_to_stream(stream_writer* p_writer, bool b_paths, abort_callback& p_abort);
void import_from_stream(stream_reader* p_reader, bool add, abort_callback& p_abort);

static INT_PTR CALLBACK g_ConfigPopupProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp);
BOOL ConfigPopupProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp);
INT_PTR on_dialog_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp);
void update_size_field_status();

void on_selection_change(size_t index);
Expand All @@ -252,9 +251,10 @@ class ButtonsToolbar : public uie::container_uie_window_v3 {
// uih::ListView m_button_list;
bool m_initialising{};
Button* m_selection{nullptr};
HWND m_wnd{nullptr}, m_child{nullptr};
HWND m_wnd{nullptr};
wil::unique_hfont m_h1_font;
wil::unique_hfont m_h2_font;
unsigned m_active{0};
Button::CustomImage* m_image{nullptr};
std::vector<Button> m_buttons;
bool m_text_below{false};
Appearance m_appearance{APPEARANCE_NORMAL};
Expand All @@ -263,8 +263,6 @@ class ButtonsToolbar : public uie::container_uie_window_v3 {
uih::IntegerAndDpi<int32_t> m_height{16};
};

static INT_PTR CALLBACK ConfigChildProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp);

bool have_config_popup() const override { return true; }
bool show_config_popup(HWND wnd_parent) override;

Expand Down
10 changes: 0 additions & 10 deletions foo_ui_columns/buttons_command_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,6 @@ INT_PTR CommandPickerDialog::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp
case WM_DESTROY:
deinitialise(wnd);
return TRUE;
case WM_ERASEBKGND:
SetWindowLongPtr(wnd, DWLP_MSGRESULT, TRUE);
return TRUE;
case WM_PAINT:
uih::handle_modern_background_paint(wnd, GetDlgItem(wnd, IDOK));
return TRUE;
case WM_CTLCOLORSTATIC:
SetBkColor((HDC)wp, GetSysColor(COLOR_WINDOW));
SetTextColor((HDC)wp, GetSysColor(COLOR_WINDOWTEXT));
return reinterpret_cast<INT_PTR>(GetSysColorBrush(COLOR_WINDOW));
case WM_COMMAND:
switch (wp) {
case IDC_GROUP | (LBN_SELCHANGE << 16):
Expand Down
Loading

0 comments on commit a29fa07

Please sign in to comment.