NIM: Reposition New Credentials Dialog if necessary
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 24 Aug 2007 14:51:46 +0000 (14:51 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 24 Aug 2007 14:51:46 +0000 (14:51 +0000)
The new credentials dialog in Network Identity Manager does not check
whether it is positioned outside of the display screen.  It tries to
position itself in the center of the primary display if the Network
Identity Manager window is hidden and it tries to center itself over
the main window if the main window is visible.  If the main window is
too close to the edge of the screen, this may result in the new
credentials window being partially outside the display area.  This is
especially a problem when the new credentials dialog switches to the
advanced view.

The patch checks whether the window rectangle is visible before
repositioning the new credentials dialog and adjusts the window
rectangle so that it is.

ticket: new
component: windows

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19867 dc483132-0cff-0310-8789-dd5450dbe970

src/windows/identity/ui/newcredwnd.c

index 1d38e4c95e0341786bd56e2c5eb9679de9be0486..afc54fa23eece2ecae99a76f90581aa2aa169e8e 100644 (file)
@@ -1564,6 +1564,21 @@ nc_handle_wm_create(HWND hwnd,
     x = (r.right + r.left)/2 - width / 2;
     y = (r.top + r.bottom)/2 - height / 2;
 
+    /* we want to check if the entire rect is visible on the screen.
+       If the main window is visible and in basic mode, we might end
+       up with a rect that is partially outside the screen. */
+    {
+        RECT r;
+
+        SetRect(&r, x, y, x + width, y + height);
+        khm_adjust_window_dimensions_for_display(&r, 0);
+
+        x = r.left;
+        y = r.top;
+        width = r.right - r.left;
+        height = r.bottom - r.top;
+    }
+
     MoveWindow(hwnd, x, y, width, height, FALSE);
 
     ncd->dlg_bb = CreateDialogParam(khm_hInstance,
@@ -2710,10 +2725,10 @@ static LRESULT nc_handle_wm_timer(HWND hwnd,
 
 #ifdef DEBUG
         {
-            long dx = (r_now.right - d->sz_ch_target.right) *
+            long dx = ((r_now.right - r_now.left) - d->sz_ch_target.right) *
                 (d->sz_ch_source.right - d->sz_ch_target.right);
 
-            long dy = (r_now.bottom - d->sz_ch_target.bottom) *
+            long dy = ((r_now.bottom - r_now.top) - d->sz_ch_target.bottom) *
                 (d->sz_ch_source.bottom - d->sz_ch_target.bottom);
 
             if (dx < 0 || dy < 0) {
@@ -2728,11 +2743,20 @@ static LRESULT nc_handle_wm_timer(HWND hwnd,
         AdjustWindowRectEx(&r_now, NC_WINDOW_STYLES, FALSE,
                            NC_WINDOW_EX_STYLES);
 
+        {
+            RECT r;
+
+            GetWindowRect(hwnd, &r);
+            OffsetRect(&r_now, r.left - r_now.left, r.top - r_now.top);
+        }
+
+        khm_adjust_window_dimensions_for_display(&r_now, 0);
+
         SetWindowPos(hwnd, NULL,
-                     0, 0,
+                     r_now.left, r_now.top,
                      r_now.right - r_now.left,
                      r_now.bottom - r_now.top,
-                     SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER |
+                     SWP_NOACTIVATE | SWP_NOOWNERZORDER |
                      SWP_NOZORDER);
 
         /* and now we wait for the next timer message */