- int xNew = wxDefaultCoord,
- yNew = wxDefaultCoord;
-
- if ( direction & wxHORIZONTAL )
- xNew = (widthParent - width)/2;
-
- if ( direction & wxVERTICAL )
- yNew = (heightParent - height)/2;
-
- xNew += posParent.x;
- yNew += posParent.y;
-
- // Base size of the visible dimensions of the display
- // to take into account the taskbar. And the Mac menu bar at top.
- wxRect clientrect = wxGetClientDisplayRect();
-
- // NB: in wxMSW, negative position may not neccessary mean "out of screen",
- // but it may mean that the window is placed on other than the main
- // display. Therefore we only make sure centered window is on the main display
- // if the parent is at least partially present here.
- if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display
- {
- if (xNew < clientrect.GetLeft())
- xNew = clientrect.GetLeft();
- else if (xNew + width > clientrect.GetRight())
- xNew = clientrect.GetRight() - width;
- }
- if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display
- {
- if (yNew + height > clientrect.GetBottom())
- yNew = clientrect.GetBottom() - height;
-
- // Make certain that the title bar is initially visible
- // always, even if this would push the bottom of the
- // dialog off the visible area of the display
- if (yNew < clientrect.GetTop())
- yNew = clientrect.GetTop();
- }
-
- // move the window to this position (keeping the old size but using
- // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord)
- SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);