mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12:48 -05:00
Improve the align_next_to mechanism.
Various alignments I want to do in the host CA box have shown up deficiencies in this system, so I've reworked it a bit. Firstly, you can now specify more than two controls to be tied together with an align_next_to (e.g. multiple checkboxes alongside something else). Secondly, as well as forcing the controls to be the same height as each other, the layout algorithm will also move the later controls further _downward_, so that their top y positions also line up. Until now that hasn't been necessary, because they lined up already. In the GTK implementation of this via the Columns class, I've renamed 'columns_force_same_height' to 'columns_align_next_to', and similarly for some of the internal fields, since the latter change makes the previous names a misnomer. In the Windows implementation, I found it most convenient to set this up by following a linked list of align_next_to fields backwards. But it won't always be convenient to initialise them that way, so I've also written a crude normaliser that will rewrite those links into a canonical form. But I only call that on Windows; it's unnecessary in GTK, where the Columns class provides plenty of per-widget extra storage so I just keep each alignment class as a circular list.
This commit is contained in:
@ -1367,6 +1367,8 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
||||
|
||||
base_id = *id;
|
||||
|
||||
ctrlset_normalise_aligns(s);
|
||||
|
||||
/* Start a containing box, if we have a boxname. */
|
||||
if (s->boxname && *s->boxname) {
|
||||
struct winctrl *c = snew(struct winctrl);
|
||||
@ -1718,21 +1720,36 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
|
||||
* moving one or the other downwards so that they're
|
||||
* centred on a common horizontal line.
|
||||
*/
|
||||
struct winctrl *c2 = winctrl_findbyctrl(
|
||||
wc, ctrl->align_next_to);
|
||||
HWND win1 = GetDlgItem(pos.hwnd, c->align_id);
|
||||
HWND win2 = GetDlgItem(pos.hwnd, c2->align_id);
|
||||
RECT rect1, rect2;
|
||||
if (win1 && win2 &&
|
||||
GetWindowRect(win1, &rect1) &&
|
||||
GetWindowRect(win2, &rect2)) {
|
||||
LONG top = (rect1.top < rect2.top ? rect1.top : rect2.top);
|
||||
LONG bottom = (rect1.bottom > rect2.bottom ?
|
||||
rect1.bottom : rect2.bottom);
|
||||
move_windows(pos.hwnd, c->base_id, c->num_ids,
|
||||
(top + bottom - rect1.top - rect1.bottom)/2);
|
||||
move_windows(pos.hwnd, c2->base_id, c2->num_ids,
|
||||
(top + bottom - rect2.top - rect2.bottom)/2);
|
||||
LONG mid2 = 0;
|
||||
for (dlgcontrol *thisctrl = ctrl; thisctrl;
|
||||
thisctrl = thisctrl->align_next_to) {
|
||||
struct winctrl *thisc = winctrl_findbyctrl(wc, thisctrl);
|
||||
assert(thisc);
|
||||
|
||||
HWND win = GetDlgItem(pos.hwnd, thisc->align_id);
|
||||
assert(win);
|
||||
|
||||
RECT rect;
|
||||
if (!GetWindowRect(win, &rect))
|
||||
continue;
|
||||
if (mid2 < rect.top + rect.bottom)
|
||||
mid2 = rect.top + rect.bottom;
|
||||
}
|
||||
|
||||
for (dlgcontrol *thisctrl = ctrl; thisctrl;
|
||||
thisctrl = thisctrl->align_next_to) {
|
||||
struct winctrl *thisc = winctrl_findbyctrl(wc, thisctrl);
|
||||
assert(thisc);
|
||||
|
||||
HWND win = GetDlgItem(pos.hwnd, thisc->align_id);
|
||||
assert(win);
|
||||
|
||||
RECT rect;
|
||||
if (!GetWindowRect(win, &rect))
|
||||
continue;
|
||||
|
||||
LONG dy = (mid2 - (rect.top + rect.bottom)) / 2;
|
||||
move_windows(pos.hwnd, c->base_id, c->num_ids, dy);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user