Skip to content

Commit ac403d8

Browse files
committed
Keep edit annotations window on screen
1 parent 76a5821 commit ac403d8

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

src/EditAnnotations.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,27 @@ static void CreateMainLayout(EditAnnotationsWindow* ew) {
15841584
HidePerAnnotControls(ew);
15851585
}
15861586

1587+
static void LimitEditAnnotationsClientSizeToScreen(HWND hwnd, HWND hwndRelative, SIZE& size) {
1588+
Rect work = GetWorkAreaRect(WindowRect(hwndRelative), hwndRelative);
1589+
WINDOWINFO wi{};
1590+
wi.cbSize = sizeof(wi);
1591+
if (!GetWindowInfo(hwnd, &wi)) {
1592+
LimitWindowSizeToScreen(hwndRelative, size);
1593+
return;
1594+
}
1595+
1596+
int nonClientDx = RectDx(wi.rcWindow) - RectDx(wi.rcClient);
1597+
int nonClientDy = RectDy(wi.rcWindow) - RectDy(wi.rcClient);
1598+
int maxClientDx = work.dx - nonClientDx;
1599+
int maxClientDy = work.dy - nonClientDy;
1600+
if (size.cx > maxClientDx) {
1601+
size.cx = maxClientDx;
1602+
}
1603+
if (size.cy > maxClientDy) {
1604+
size.cy = maxClientDy;
1605+
}
1606+
}
1607+
15871608
void ShowEditAnnotationsWindow(WindowTab* tab, Annotation* annot, EditAnnotFocus focus) {
15881609
if (!tab) return;
15891610
auto engine = tab->GetEngine();
@@ -1653,14 +1674,20 @@ void ShowEditAnnotationsWindow(WindowTab* tab, Annotation* annot, EditAnnotFocus
16531674
}
16541675

16551676
if (lastPos.IsEmpty()) {
1656-
LayoutAndSizeToContent(ew->mainLayout, 520, minDy, ew->hwnd);
1677+
SIZE size = {520, minDy};
1678+
LimitEditAnnotationsClientSizeToScreen(ew->hwnd, tab->win->hwndFrame, size);
1679+
LayoutAndSizeToContent(ew->mainLayout, size.cx, size.cy, ew->hwnd);
16571680
HwndPositionToTheRightOf(ew->hwnd, tab->win->hwndFrame);
16581681
} else {
1659-
int dx = lastPos.dx;
1660-
LayoutAndSizeToContent(ew->mainLayout, dx, minDy, ew->hwnd);
1682+
SIZE size = {lastPos.dx, minDy};
1683+
LimitEditAnnotationsClientSizeToScreen(ew->hwnd, tab->win->hwndFrame, size);
1684+
LayoutAndSizeToContent(ew->mainLayout, size.cx, size.cy, ew->hwnd);
16611685
// pass nullptr for hwnd so ShiftRectToWorkArea uses the saved rect
16621686
// to find the correct monitor (not the monitor the hwnd is currently on)
1663-
Rect r = ShiftRectToWorkArea(lastPos, nullptr, true);
1687+
Rect r = WindowRect(ew->hwnd);
1688+
r.x = lastPos.x;
1689+
r.y = lastPos.y;
1690+
r = ShiftRectToWorkArea(r, nullptr, true);
16641691
SetWindowPos(ew->hwnd, nullptr, r.x, r.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
16651692
}
16661693
if (!annot) annot = ew->tab->selectedAnnotation;

0 commit comments

Comments
 (0)