调整界面布局-对齐第二列;保存了API设置的方案后,清除API设置标志
This commit is contained in:
parent
3467a987ea
commit
7a5262712b
|
@ -460,14 +460,18 @@ int dlg_base::get_width_diff_as_text_length(UINT id)
|
|||
|
||||
return get_string_width(get_item_text(id).c_str()) - RECT_W(r);
|
||||
}
|
||||
void dlg_base::offset_item(UINT id, int dx, int dy)
|
||||
void dlg_base::offset_item(HWND wnd, int dx, int dy)
|
||||
{
|
||||
RECT r = { 0 };
|
||||
|
||||
get_item_rect(id, &r, false);
|
||||
GetWindowRect(wnd, &r);
|
||||
OffsetRect(&r, dx, dy);
|
||||
screen_2_client(&r);
|
||||
MoveWindow(get_item(id), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||
MoveWindow(wnd, r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||
}
|
||||
void dlg_base::offset_item(UINT id, int dx, int dy)
|
||||
{
|
||||
offset_item(get_item(id), dx, dy);
|
||||
}
|
||||
void dlg_base::expand_item(UINT id, int dx, int dy)
|
||||
{
|
||||
|
@ -637,7 +641,7 @@ dlg_page::dlg_page(HWND parent, const wchar_t* name
|
|||
{
|
||||
size_.cx = size_.cy = 0;
|
||||
pos_.x = 12;
|
||||
pos_.y = 8;
|
||||
pos_.y = 15;
|
||||
create();
|
||||
tips_wnd_.create(hwnd());
|
||||
}
|
||||
|
@ -685,6 +689,61 @@ void dlg_page::on_font_changed(void)
|
|||
HFONT font = get_font();
|
||||
LOGFONTW lf = { 0 };
|
||||
}
|
||||
void dlg_page::align_second_control(bool ignore_single)
|
||||
{
|
||||
int pos_2nd = 0,
|
||||
xoff = 0,
|
||||
cnt = 0,
|
||||
prev_pos = 0,
|
||||
sn = -1;
|
||||
|
||||
// 1st: find the right-most position of the first control
|
||||
for (auto& v : ctrls_)
|
||||
{
|
||||
int id = (int)GetWindowLong(v, GWL_ID);
|
||||
|
||||
if (id != sn)
|
||||
{
|
||||
RECT r = { 0 };
|
||||
GetWindowRect(v, &r);
|
||||
|
||||
if (ignore_single && cnt == 1)
|
||||
{
|
||||
pos_2nd = prev_pos;
|
||||
}
|
||||
prev_pos = pos_2nd;
|
||||
sn = id;
|
||||
cnt = 1;
|
||||
if (r.right > pos_2nd)
|
||||
pos_2nd = r.right;
|
||||
}
|
||||
else
|
||||
cnt++;
|
||||
}
|
||||
|
||||
// 2nd: align the controls begin from position 2
|
||||
sn = -1;
|
||||
for (auto& v : ctrls_)
|
||||
{
|
||||
int id = (int)GetWindowLong(v, GWL_ID);
|
||||
RECT r = { 0 };
|
||||
|
||||
if (id != sn)
|
||||
{
|
||||
GetWindowRect(v, &r);
|
||||
sn = id;
|
||||
xoff = pos_2nd - r.right;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset_item(v, xoff, 0);
|
||||
GetWindowRect(v, &r);
|
||||
screen_2_client(&r);
|
||||
if (size_.cx < r.right + dlg_page::gap_x)
|
||||
size_.cx = r.right + dlg_page::gap_x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWND dlg_page::create_label(int sn, const wchar_t* title, int x, int y, SIZE size)
|
||||
{
|
||||
|
@ -721,8 +780,8 @@ HWND dlg_page::create_slider(int sn, int x, int y, double lower, double upper, d
|
|||
size->cx *= 100;
|
||||
if (size->cx < 100)
|
||||
size->cx = 100;
|
||||
if (size->cx > 300)
|
||||
size->cx = 300;
|
||||
if (size->cx > 200)
|
||||
size->cx = 200;
|
||||
if (upper > lower && size->cx / (upper - lower) < ticks_limit)
|
||||
style |= TBS_NOTICKS;
|
||||
else
|
||||
|
@ -1555,6 +1614,7 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur
|
|||
std::wstring t(local_trans::lang_trans_between_hz936(CONST_STRING_SET_AREA));
|
||||
|
||||
id_custom_area_ = sn;
|
||||
text.cx += dlg_page::gap_x;
|
||||
wnd = CreateWindowW(WC_BUTTONW, t.c_str(), WS_CHILD | WS_VISIBLE, pos_.x + text.cx, pos_.y - 1, w, text.cy + 3, hwnd(), NULL, g_my_inst, NULL);
|
||||
text.cx += w + dlg_page::gap_x;
|
||||
EnableWindow(wnd, (desc->cap & SANE_CAP_INACTIVE) == 0 && *(SANE_Bool*)cur_val == SANE_TRUE);
|
||||
|
@ -1584,6 +1644,7 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur
|
|||
std::wstring t(local_trans::lang_trans_between_hz936(CONST_STRING_SET_TONE));
|
||||
|
||||
id_custom_gamma_ = sn;
|
||||
text.cx += dlg_page::gap_x;
|
||||
wnd = CreateWindowW(WC_BUTTONW, t.c_str(), WS_CHILD | WS_VISIBLE, pos_.x + text.cx, pos_.y - 1, w, text.cy + 3, hwnd(), NULL, g_my_inst, NULL);
|
||||
text.cx += w + dlg_page::gap_x;
|
||||
EnableWindow(wnd, (desc->cap& SANE_CAP_INACTIVE) == 0 && *(SANE_Bool*)cur_val == SANE_TRUE);
|
||||
|
@ -1608,6 +1669,7 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur
|
|||
void dlg_page::add_control_done(void)
|
||||
{
|
||||
done_ = true;
|
||||
align_second_control(true);
|
||||
}
|
||||
SIZE dlg_page::desired_size(void)
|
||||
{
|
||||
|
|
|
@ -92,6 +92,7 @@ public:
|
|||
bool get_item_rect(UINT id, LPRECT r, bool client = true);
|
||||
std::wstring get_item_text(UINT id);
|
||||
int get_width_diff_as_text_length(UINT id); //
|
||||
void offset_item(HWND wnd, int dx, int dy);
|
||||
void offset_item(UINT id, int dx, int dy);
|
||||
void expand_item(UINT id, int dx, int dy);
|
||||
bool set_item_text(UINT id, const wchar_t* text);
|
||||
|
@ -182,6 +183,7 @@ class dlg_page : public dlg_base
|
|||
|
||||
BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
|
||||
void on_font_changed(void) override;
|
||||
void align_second_control(bool ignore_single = false); // align the second control of a option controls
|
||||
|
||||
HWND create_label(int sn, const wchar_t* title, int x, int y, SIZE size);
|
||||
HWND create_slider(int sn, int x, int y, double lower, double upper, double step, double pos, LPSIZE size, bool is_double);
|
||||
|
|
|
@ -19,6 +19,7 @@ dlg_save_scheme::dlg_save_scheme(HWND parent) : dlg_base(parent, IDD_SAVE_SCHEME
|
|||
|
||||
std::wstring title(local_trans::lang_trans_between_hz936(CONST_STRING_SAVE_TITLE));
|
||||
int dif = 0;
|
||||
RECT rc = { 0 };
|
||||
|
||||
SetWindowTextW(hwnd(), title.c_str());
|
||||
|
||||
|
@ -34,7 +35,9 @@ dlg_save_scheme::dlg_save_scheme(HWND parent) : dlg_base(parent, IDD_SAVE_SCHEME
|
|||
set_item_text(IDC_RADIO_NEW, title.c_str());
|
||||
dif = set_item_fit_to_text(IDC_RADIO_NEW);
|
||||
offset_item(IDC_NAME, dif, 0);
|
||||
// expand_item(IDC_NAME, dif, 0);
|
||||
GetWindowRect(get_item(IDC_NAME), &rc);
|
||||
if(dif < RECT_W(rc) / 2)
|
||||
expand_item(IDC_NAME, -dif, 0);
|
||||
|
||||
{
|
||||
RECT r = { 0 }, rc = { 0 };
|
||||
|
@ -43,8 +46,10 @@ dlg_save_scheme::dlg_save_scheme(HWND parent) : dlg_base(parent, IDD_SAVE_SCHEME
|
|||
GetWindowRect(get_item(IDC_NAME), &rc);
|
||||
if (rc.right + WIDTH_MARGINS > r.right)
|
||||
{
|
||||
dif = rc.right + WIDTH_MARGINS - r.right;
|
||||
r.right = rc.right + WIDTH_MARGINS;
|
||||
MoveWindow(hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||
offset_item(IDOK, dif / 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,8 +199,10 @@ void dlg_save_scheme::set_info(const wchar_t* name, std::vector<std::wstring>& e
|
|||
GetWindowRect(hwnd(), &r);
|
||||
if (RECT_W(r) < RECT_W(rc) + WIDTH_MARGINS)
|
||||
{
|
||||
int diff = r.left + RECT_W(rc) + WIDTH_MARGINS - r.right;
|
||||
r.right = r.left + RECT_W(rc) + WIDTH_MARGINS;
|
||||
MoveWindow(hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||
offset_item(IDOK, diff / 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -289,8 +289,8 @@ void dlg_setting::on_init_dialog(void)
|
|||
{
|
||||
if (page)
|
||||
{
|
||||
dlg_base::get_max_size(size, page->desired_size());
|
||||
page->add_control_done();
|
||||
dlg_base::get_max_size(size, page->desired_size());
|
||||
}
|
||||
page = add_tab(desc->title);
|
||||
}
|
||||
|
@ -321,8 +321,8 @@ void dlg_setting::on_init_dialog(void)
|
|||
}
|
||||
if (page)
|
||||
{
|
||||
dlg_base::get_max_size(size, page->desired_size());
|
||||
page->add_control_done();
|
||||
dlg_base::get_max_size(size, page->desired_size());
|
||||
}
|
||||
|
||||
if (size.cx || size.cy || IsWindow(tab_))
|
||||
|
@ -554,7 +554,11 @@ void dlg_setting::save_changes_to_cur_scheme(int reason)
|
|||
std::string name(local_trans::u2a(dlg.get_name().c_str(), CP_UTF8));
|
||||
if (cfg_->add_scheme(twain_schm_, name.c_str()) &&
|
||||
reason == SAVE_REASON_QUIT_UI)
|
||||
{
|
||||
cfg_->select_scheme(name.c_str());
|
||||
if (twain_set_)
|
||||
*twain_set_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
twain_schm_->release();
|
||||
|
|
Loading…
Reference in New Issue